Class: Kentaa::Api::Response
- Inherits:
-
Object
- Object
- Kentaa::Api::Response
- Defined in:
- lib/kentaa/api/response.rb
Constant Summary collapse
- SUCCESS_CODES =
[200, 201, 204].freeze
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.
12 13 14 15 |
# File 'lib/kentaa/api/response.rb', line 12 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.
10 11 12 |
# File 'lib/kentaa/api/response.rb', line 10 def body @body end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/kentaa/api/response.rb', line 10 def response @response end |
Instance Method Details
#error? ⇒ Boolean
21 22 23 |
# File 'lib/kentaa/api/response.rb', line 21 def error? !success? end |
#errors ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kentaa/api/response.rb', line 37 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
25 26 27 |
# File 'lib/kentaa/api/response.rb', line 25 def http_code response.code.to_i end |
#message ⇒ Object
33 34 35 |
# File 'lib/kentaa/api/response.rb', line 33 def body[:message] end |
#request_uri ⇒ Object
29 30 31 |
# File 'lib/kentaa/api/response.rb', line 29 def request_uri response.uri end |
#success? ⇒ Boolean
17 18 19 |
# File 'lib/kentaa/api/response.rb', line 17 def success? SUCCESS_CODES.include?(http_code) && ! end |