Class: HttpClient::Response
- Inherits:
-
Object
- Object
- HttpClient::Response
- Defined in:
- lib/http_client.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.
42 43 44 45 46 47 48 49 |
# File 'lib/http_client.rb', line 42 def initialize(closeable_response) @status = closeable_response.status_line.status_code @headers = closeable_response.get_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.
40 41 42 |
# File 'lib/http_client.rb', line 40 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
40 41 42 |
# File 'lib/http_client.rb', line 40 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
40 41 42 |
# File 'lib/http_client.rb', line 40 def status @status end |
Instance Method Details
#json_body(options = {}) ⇒ Object
55 56 57 |
# File 'lib/http_client.rb', line 55 def json_body( = {}) @json_body ||= JSON.parse(body, ) end |
#success? ⇒ Boolean
51 52 53 |
# File 'lib/http_client.rb', line 51 def success? @status >= 200 && @status <= 206 end |