Class: HonestRenter::Response
- Inherits:
-
Object
- Object
- HonestRenter::Response
- Defined in:
- lib/response.rb
Defined Under Namespace
Classes: MalformedResponse, RequestError
Constant Summary collapse
- HAPPY_STATUSES =
[200, 300].freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(raw_response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(raw_response) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/response.rb', line 10 def initialize(raw_response) @status = raw_response.status @headers = raw_response.headers begin @body = JSON.parse(raw_response.body) rescue JSON::ParserError, TypeError => e raise MalformedResponse, "Honest Renter response body not valid JSON, #{ raw_response.body } given" end if @body.key?('error') @error = RequestError.new(@body['error']['message']) end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/response.rb', line 6 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/response.rb', line 6 def error @error end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/response.rb', line 6 def headers @headers end |
Instance Method Details
#success? ⇒ Boolean
26 27 28 |
# File 'lib/response.rb', line 26 def success? HAPPY_STATUSES.include?(@status.floor) end |