Class: NoyoFulfillment::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/noyo_fulfillment/api_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ApiResponse

Returns a new instance of ApiResponse.

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/noyo_fulfillment/api_response.rb', line 12

def initialize(response)
  body = response.parsed_response
  if body.is_a? String
    parsed_body = JSON.parse(body)
    if parsed_body.is_a?(Hash)
      body = parsed_body.with_indifferent_access
    elsif parsed_body.is_a?(Array)
      body = parsed_body.map(&:with_indifferent_access)
    end
  end
  raise ServerError unless body.is_a?(Hash) || body.is_a?(Array)

  if body.is_a?(Hash) && body.key?('meta')
    @meta = body['meta']
    @response = body['response']
  else
    @response = body
  end
end

Instance Attribute Details

#metaObject

Returns the value of attribute meta.



10
11
12
# File 'lib/noyo_fulfillment/api_response.rb', line 10

def meta
  @meta
end

#responseObject

Returns the value of attribute response.



10
11
12
# File 'lib/noyo_fulfillment/api_response.rb', line 10

def response
  @response
end