Class: Buzz::Response
- Inherits:
-
Object
- Object
- Buzz::Response
- Defined in:
- lib/buzz/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #next_url ⇒ Object
- #previous_url ⇒ Object
- #results ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 |
# File 'lib/buzz/response.rb', line 9 def initialize(http_response) @status = http_response.code.to_i @headers = http_response.to_hash @body = http_response.body @data = parse_body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/buzz/response.rb', line 7 def body @body end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/buzz/response.rb', line 7 def data @data end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/buzz/response.rb', line 7 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/buzz/response.rb', line 7 def status @status end |
Instance Method Details
#count ⇒ Object
24 25 26 |
# File 'lib/buzz/response.rb', line 24 def count data["count"] if data.is_a?(Hash) end |
#next_url ⇒ Object
28 29 30 |
# File 'lib/buzz/response.rb', line 28 def next_url data["next"] if data.is_a?(Hash) end |
#previous_url ⇒ Object
32 33 34 |
# File 'lib/buzz/response.rb', line 32 def previous_url data["previous"] if data.is_a?(Hash) end |
#results ⇒ Object
20 21 22 |
# File 'lib/buzz/response.rb', line 20 def results data["results"] if data.is_a?(Hash) end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/buzz/response.rb', line 16 def success? status >= 200 && status < 300 end |