Class: Analysand::Response
- Inherits:
-
Object
- Object
- Analysand::Response
- Extended by:
- Forwardable
- Includes:
- ResponseHeaders, StatusCodePredicates
- Defined in:
- lib/analysand/response.rb
Overview
The response object is a wrapper around Net::HTTPResponse that provides a few amenities:
-
A #success? method, which checks if 200 <= response code <= 299.
-
A #conflict method, which checks if response code == 409.
-
Automatic JSON deserialization of all response bodies.
-
Delegates the [] property accessor to the body.
Direct Known Subclasses
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
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
Methods included from StatusCodePredicates
#code, #conflict?, #not_found?, #success?, #unauthorized?
Methods included from ResponseHeaders
#cookies, #etag, #session_cookie
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
25 26 27 28 29 30 31 |
# File 'lib/analysand/response.rb', line 25 def initialize(response) @response = response if !@response.body.nil? && !@response.body.empty? @body = JSON.parse(@response.body) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
21 22 23 |
# File 'lib/analysand/response.rb', line 21 def body @body end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
20 21 22 |
# File 'lib/analysand/response.rb', line 20 def response @response end |