Class: TOS::Response
- Inherits:
-
Object
- Object
- TOS::Response
- Defined in:
- lib/tos/response.rb
Overview
Lightweight wrapper around a Net::HTTPResponse so callers don’t have to know which HTTP library produced it.
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
- #content_length ⇒ Object
- #content_type ⇒ Object
- #etag ⇒ Object
- #header(name) ⇒ Object
-
#initialize(status:, headers:, body:) ⇒ Response
constructor
A new instance of Response.
- #request_id ⇒ Object
Constructor Details
#initialize(status:, headers:, body:) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/tos/response.rb', line 9 def initialize(status:, headers:, body:) @status = status @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/tos/response.rb', line 7 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/tos/response.rb', line 7 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/tos/response.rb', line 7 def status @status end |
Instance Method Details
#content_length ⇒ Object
28 29 30 |
# File 'lib/tos/response.rb', line 28 def content_length header("content-length")&.to_i end |
#content_type ⇒ Object
32 33 34 |
# File 'lib/tos/response.rb', line 32 def content_type header("content-type") end |
#etag ⇒ Object
24 25 26 |
# File 'lib/tos/response.rb', line 24 def etag header("etag")&.delete('"') end |
#header(name) ⇒ Object
15 16 17 18 |
# File 'lib/tos/response.rb', line 15 def header(name) key = headers.keys.find { |k| k.downcase == name.downcase } key && headers[key] end |
#request_id ⇒ Object
20 21 22 |
# File 'lib/tos/response.rb', line 20 def request_id header("x-tos-request-id") || header("x-tos-id-2") end |