Class: Philiprehberger::HttpClient::Response
- Inherits:
-
Object
- Object
- Philiprehberger::HttpClient::Response
- Defined in:
- lib/philiprehberger/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.
-
#metrics ⇒ Metrics?
readonly
Returns request timing metrics (nil if not available).
-
#redirects ⇒ Array<String>
readonly
Returns the redirect chain (empty if no redirects occurred).
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status:, body:, headers: {}, streaming: false, request_id: nil) ⇒ Response
constructor
A new instance of Response.
-
#json ⇒ Hash, Array
Parses the response body as JSON.
-
#ok? ⇒ Boolean
Returns true if the status code is in the 2xx range.
-
#redirected? ⇒ Boolean
Returns true if the response was redirected.
-
#streaming? ⇒ Boolean
Returns true if the response was streamed.
Constructor Details
#initialize(status:, body:, headers: {}, streaming: false, request_id: nil) ⇒ Response
Returns a new instance of Response.
15 16 17 18 19 20 21 22 23 |
# File 'lib/philiprehberger/http_client/response.rb', line 15 def initialize(status:, body:, headers: {}, streaming: false, request_id: nil) @status = status @body = body @headers = headers @streaming = streaming @request_id = request_id @metrics = nil @redirects = [] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/philiprehberger/http_client/response.rb', line 8 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/philiprehberger/http_client/response.rb', line 8 def headers @headers end |
#metrics ⇒ Metrics? (readonly)
Returns request timing metrics (nil if not available).
50 51 52 |
# File 'lib/philiprehberger/http_client/response.rb', line 50 def metrics @metrics end |
#redirects ⇒ Array<String> (readonly)
Returns the redirect chain (empty if no redirects occurred).
55 56 57 |
# File 'lib/philiprehberger/http_client/response.rb', line 55 def redirects @redirects end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
8 9 10 |
# File 'lib/philiprehberger/http_client/response.rb', line 8 def request_id @request_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/philiprehberger/http_client/response.rb', line 8 def status @status end |
Instance Method Details
#json ⇒ Hash, Array
Parses the response body as JSON.
43 44 45 |
# File 'lib/philiprehberger/http_client/response.rb', line 43 def json @json ||= JSON.parse(body) end |
#ok? ⇒ Boolean
Returns true if the status code is in the 2xx range.
28 29 30 |
# File 'lib/philiprehberger/http_client/response.rb', line 28 def ok? status >= 200 && status < 300 end |
#redirected? ⇒ Boolean
Returns true if the response was redirected.
60 61 62 |
# File 'lib/philiprehberger/http_client/response.rb', line 60 def redirected? !redirects.empty? end |
#streaming? ⇒ Boolean
Returns true if the response was streamed.
35 36 37 |
# File 'lib/philiprehberger/http_client/response.rb', line 35 def streaming? @streaming end |