Class: Tikkie::Api::Response
- Inherits:
-
Object
- Object
- Tikkie::Api::Response
- Defined in:
- lib/tikkie/api/response.rb
Overview
Parses and wraps the response from the Tikkie API.
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
- #http_message ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #invalid? ⇒ Boolean
- #request_uri ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
12 13 14 15 |
# File 'lib/tikkie/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/tikkie/api/response.rb', line 10 def body @body end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/tikkie/api/response.rb', line 10 def response @response end |
Instance Method Details
#error? ⇒ Boolean
21 22 23 |
# File 'lib/tikkie/api/response.rb', line 21 def error? !success? end |
#errors ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tikkie/api/response.rb', line 41 def errors @errors ||= begin errors = [] if body[:errors] body[:errors].each do |error| errors << Tikkie::Api::Resources::Error.new(error) end end errors end end |
#http_code ⇒ Object
33 34 35 |
# File 'lib/tikkie/api/response.rb', line 33 def http_code response.code.to_i end |
#http_message ⇒ Object
37 38 39 |
# File 'lib/tikkie/api/response.rb', line 37 def response. end |
#invalid? ⇒ Boolean
25 26 27 |
# File 'lib/tikkie/api/response.rb', line 25 def invalid? body.nil? end |
#request_uri ⇒ Object
29 30 31 |
# File 'lib/tikkie/api/response.rb', line 29 def request_uri response.uri end |
#success? ⇒ Boolean
17 18 19 |
# File 'lib/tikkie/api/response.rb', line 17 def success? http_code == 200 || http_code == 201 || http_code == 204 end |