Class: Kentaa::Api::Response
- Inherits:
-
Object
- Object
- Kentaa::Api::Response
- Defined in:
- lib/kentaa/api/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #errors ⇒ Object
- #http_code ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #message ⇒ Object
- #request_uri ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
10 11 12 13 |
# File 'lib/kentaa/api/response.rb', line 10 def initialize(response) @response = response @body = response.body ? parse_body(response.body) : {} end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/kentaa/api/response.rb', line 8 def body @body end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/kentaa/api/response.rb', line 8 def response @response end |
Instance Method Details
#error? ⇒ Boolean
19 20 21 |
# File 'lib/kentaa/api/response.rb', line 19 def error? !success? end |
#errors ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kentaa/api/response.rb', line 35 def errors @errors ||= begin errors = [] if body[:errors] body[:errors].each do |error| errors << Kentaa::Api::Resources::Error.new(error) end end errors end end |
#http_code ⇒ Object
23 24 25 |
# File 'lib/kentaa/api/response.rb', line 23 def http_code response.code.to_i end |
#message ⇒ Object
31 32 33 |
# File 'lib/kentaa/api/response.rb', line 31 def body[:message] end |
#request_uri ⇒ Object
27 28 29 |
# File 'lib/kentaa/api/response.rb', line 27 def request_uri response.uri end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/kentaa/api/response.rb', line 15 def success? (http_code == 200 || http_code == 201 || http_code == 204) && ! end |