Class: Webceo::Api::Response
- Inherits:
-
Object
- Object
- Webceo::Api::Response
- Defined in:
- lib/webceo/api/response.rb
Overview
Class Response provides a customize response instance to use in our client based on the response returned by the Webceo API Server
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#check_for_errors ⇒ Object
This method checks for any errors in the response returned from the api call.
-
#initialize(status, body, headers, message = nil) ⇒ Response
constructor
Creates a new Response object, which standardizes the response received for use within Webceo.
Constructor Details
#initialize(status, body, headers, message = nil) ⇒ Response
Creates a new Response object, which standardizes the response received for use within Webceo
13 14 15 16 17 18 |
# File 'lib/webceo/api/response.rb', line 13 def initialize(status, body, headers, = nil) @status = status @body = body @headers = headers @message = end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/webceo/api/response.rb', line 10 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/webceo/api/response.rb', line 10 def headers @headers end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/webceo/api/response.rb', line 10 def @message end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/webceo/api/response.rb', line 10 def status @status end |
Instance Method Details
#check_for_errors ⇒ Object
This method checks for any errors in the response returned from the api call
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/webceo/api/response.rb', line 25 def check_for_errors info = MultiJson.load(self.body).first if info['result'] && info['result'] != 0 if info['result'] == 500 raise Webceo::Api::ServerError.new(self.status.to_i, self.body) else raise Webceo::Api::ClientError.new(self.status.to_i, self.body) end end end |