Class: NoyoFulfillment::ApiResponse
- Inherits:
-
Object
- Object
- NoyoFulfillment::ApiResponse
- Defined in:
- lib/noyo_fulfillment/api_response.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
Constructor Details
#initialize(response) ⇒ ApiResponse
Returns a new instance of ApiResponse.
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
#meta ⇒ Object
Returns the value of attribute meta.
10 11 12 |
# File 'lib/noyo_fulfillment/api_response.rb', line 10 def @meta end |
#response ⇒ Object
Returns the value of attribute response.
10 11 12 |
# File 'lib/noyo_fulfillment/api_response.rb', line 10 def response @response end |