Class: OctaSpace::Response
- Inherits:
-
Object
- Object
- OctaSpace::Response
- Defined in:
- lib/octaspace/response.rb
Overview
Wraps a raw Faraday response, providing a stable SDK interface
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#client_error? ⇒ Boolean
True for 4xx status codes.
-
#error? ⇒ Boolean
True for any non-2xx error.
-
#initialize(faraday_response) ⇒ Response
constructor
A new instance of Response.
-
#request_id ⇒ String?
X-Request-Id header value.
-
#retry_after ⇒ Integer?
Retry-After header value in seconds.
-
#server_error? ⇒ Boolean
True for 5xx status codes.
-
#success? ⇒ Boolean
True for 2xx status codes.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(faraday_response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 |
# File 'lib/octaspace/response.rb', line 9 def initialize(faraday_response) @status = faraday_response.status @headers = faraday_response.headers @body = faraday_response.body # Faraday :json middleware parses JSON body into a Hash/Array automatically @data = faraday_response.body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/octaspace/response.rb', line 6 def body @body end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/octaspace/response.rb', line 6 def data @data end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/octaspace/response.rb', line 6 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/octaspace/response.rb', line 6 def status @status end |
Instance Method Details
#client_error? ⇒ Boolean
Returns true for 4xx status codes.
21 |
# File 'lib/octaspace/response.rb', line 21 def client_error? = (400..499).cover?(status) |
#error? ⇒ Boolean
Returns true for any non-2xx error.
27 |
# File 'lib/octaspace/response.rb', line 27 def error? = client_error? || server_error? |
#request_id ⇒ String?
Returns X-Request-Id header value.
30 |
# File 'lib/octaspace/response.rb', line 30 def request_id = headers["x-request-id"] |
#retry_after ⇒ Integer?
Returns Retry-After header value in seconds.
33 |
# File 'lib/octaspace/response.rb', line 33 def retry_after = headers["retry-after"]&.to_i |
#server_error? ⇒ Boolean
Returns true for 5xx status codes.
24 |
# File 'lib/octaspace/response.rb', line 24 def server_error? = (500..599).cover?(status) |
#success? ⇒ Boolean
Returns true for 2xx status codes.
18 |
# File 'lib/octaspace/response.rb', line 18 def success? = (200..299).cover?(status) |
#to_s ⇒ Object Also known as: inspect
35 36 37 |
# File 'lib/octaspace/response.rb', line 35 def to_s "#<OctaSpace::Response status=#{status}>" end |