Class: Webceo::Api::Response

Inherits:
Object
  • Object
show all
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

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

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, message = nil)
  @status = status
  @body = body
  @headers = headers
  @message = message
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/webceo/api/response.rb', line 10

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/webceo/api/response.rb', line 10

def headers
  @headers
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/webceo/api/response.rb', line 10

def message
  @message
end

#statusObject (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_errorsObject

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