Class: Factorix::HTTP::Response
- Inherits:
-
Object
- Object
- Factorix::HTTP::Response
- Defined in:
- lib/factorix/http/response.rb
Overview
Simple response wrapper for Net::HTTP responses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#content_length ⇒ Integer?
Get Content-Length from headers.
-
#initialize(net_http_response, uri: nil) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
Check if response is successful (2xx).
Constructor Details
#initialize(net_http_response, uri: nil) ⇒ Response
Returns a new instance of Response.
15 16 17 18 19 20 21 |
# File 'lib/factorix/http/response.rb', line 15 def initialize(net_http_response, uri: nil) @code = Integer(net_http_response.code, 10) @body = net_http_response.body @headers = net_http_response.to_hash @raw_response = net_http_response @uri = uri end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/factorix/http/response.rb', line 8 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/factorix/http/response.rb', line 7 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/factorix/http/response.rb', line 9 def headers @headers end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
10 11 12 |
# File 'lib/factorix/http/response.rb', line 10 def raw_response @raw_response end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
11 12 13 |
# File 'lib/factorix/http/response.rb', line 11 def uri @uri end |
Instance Method Details
#content_length ⇒ Integer?
Get Content-Length from headers
31 |
# File 'lib/factorix/http/response.rb', line 31 def content_length = Integer(@headers["content-length"]&.first, 10) |
#success? ⇒ Boolean
Check if response is successful (2xx)
26 |
# File 'lib/factorix/http/response.rb', line 26 def success? = (200..299).cover?(@code) |