Class: Fizzy::Response
- Inherits:
-
Object
- Object
- Fizzy::Response
- Defined in:
- lib/fizzy/http.rb
Overview
Wraps an HTTP response.
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Response body.
-
#headers ⇒ Hash
readonly
Response headers.
-
#status ⇒ Integer
readonly
HTTP status code.
Instance Method Summary collapse
-
#initialize(body:, status:, headers:) ⇒ Response
constructor
A new instance of Response.
-
#json ⇒ Hash, Array
Parses the response body as JSON.
-
#success? ⇒ Boolean
Returns whether the response was successful (2xx).
Constructor Details
#initialize(body:, status:, headers:) ⇒ Response
Returns a new instance of Response.
390 391 392 393 394 |
# File 'lib/fizzy/http.rb', line 390 def initialize(body:, status:, headers:) @body = body @status = status @headers = headers end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns response body.
382 383 384 |
# File 'lib/fizzy/http.rb', line 382 def body @body end |
#headers ⇒ Hash (readonly)
Returns response headers.
388 389 390 |
# File 'lib/fizzy/http.rb', line 388 def headers @headers end |
#status ⇒ Integer (readonly)
Returns HTTP status code.
385 386 387 |
# File 'lib/fizzy/http.rb', line 385 def status @status end |
Instance Method Details
#json ⇒ Hash, Array
Parses the response body as JSON.
398 399 400 401 402 403 |
# File 'lib/fizzy/http.rb', line 398 def json @json ||= begin Security.check_body_size!(@body, Security::MAX_RESPONSE_BODY_BYTES) JSON.parse(@body) end end |
#success? ⇒ Boolean
Returns whether the response was successful (2xx).
407 408 409 |
# File 'lib/fizzy/http.rb', line 407 def success? status >= 200 && status < 300 end |