Class: KiwiApi::Response
- Inherits:
-
Object
- Object
- KiwiApi::Response
- Defined in:
- lib/kiwi_api/response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #errors ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/kiwi_api/response.rb', line 5 def initialize(response) @response = response end |
Instance Method Details
#body ⇒ Object
17 18 19 20 21 22 |
# File 'lib/kiwi_api/response.rb', line 17 def body JSON.parse( JSON.parse(@response.body).deep_transform_keys { |key| key.to_s.underscore }.to_json, object_class: OpenStruct ) rescue nil end |
#errors ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kiwi_api/response.rb', line 24 def errors unless @response.success? err = body OpenStruct.new( message: @response.reason_phrase, full_messages: err.nil? ? nil : err. ) end end |
#status ⇒ Object
13 14 15 |
# File 'lib/kiwi_api/response.rb', line 13 def status @response.status end |
#success? ⇒ Boolean
9 10 11 |
# File 'lib/kiwi_api/response.rb', line 9 def success? true unless @response.status != 200 end |