Class: HttpClient::Response
- Inherits:
-
Object
- Object
- HttpClient::Response
- Defined in:
- lib/http_client/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(closeable_response) ⇒ Response
constructor
A new instance of Response.
- #json_body(options = {}) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(closeable_response) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 |
# File 'lib/http_client/response.rb', line 6 def initialize(closeable_response) @status = closeable_response.status_line.status_code @headers = closeable_response.all_headers.inject({}) do |headers, header| headers[header.name] = header.value headers end @body = read_body(closeable_response) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/http_client/response.rb', line 4 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/http_client/response.rb', line 4 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/http_client/response.rb', line 4 def status @status end |
Instance Method Details
#json_body(options = {}) ⇒ Object
19 20 21 |
# File 'lib/http_client/response.rb', line 19 def json_body( = {}) @json_body ||= JSON.parse(body, ) end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/http_client/response.rb', line 15 def success? status >= 200 && status <= 206 end |