Class: Http::Response
- Inherits:
-
Object
- Object
- Http::Response
- Defined in:
- lib/http/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
(also: #code, #status_code, #status_code=)
Returns the value of attribute status.
Instance Method Summary collapse
-
#[](header) ⇒ Object
Get a header value.
-
#[]=(header, value) ⇒ Object
Set a header value.
-
#initialize ⇒ Response
constructor
A new instance of Response.
-
#parse_body ⇒ Object
Parse the response body according to its content type.
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
14 15 16 |
# File 'lib/http/response.rb', line 14 def initialize @headers = {} end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/http/response.rb', line 5 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/http/response.rb', line 4 def headers @headers end |
#status ⇒ Object Also known as: code, status_code, status_code=
Returns the value of attribute status.
3 4 5 |
# File 'lib/http/response.rb', line 3 def status @status end |
Instance Method Details
#[](header) ⇒ Object
Get a header value
32 33 34 |
# File 'lib/http/response.rb', line 32 def [](header) @headers[header.to_s.downcase] end |
#[]=(header, value) ⇒ Object
Set a header value
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/http/response.rb', line 19 def []=(header, value) key = header.to_s.downcase # Check if the header has already been set and group old_value = @headers[key] if old_value @headers[key] = [old_value].flatten << key else @headers[key] = value end end |
#parse_body ⇒ Object
Parse the response body according to its content type
37 38 39 40 41 42 43 44 |
# File 'lib/http/response.rb', line 37 def parse_body if @headers['content-type'] mime_type = MimeType[@headers['content-type'].split(/;\s*/).first] return mime_type.parse(@body) if mime_type end @body end |