Class: ReveAI::Response
- Inherits:
-
Object
- Object
- ReveAI::Response
- Defined in:
- lib/reve_ai/response.rb
Overview
Base response wrapper for API responses.
Provides access to HTTP status, headers, and response body. The body is a parsed Hash for JSON responses, or the raw image String (bytes) when the API answers with a binary body (Accept: image/); in that case all metadata is carried by the X-Reve- response headers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Hash, String
readonly
Parsed response body, or raw bytes String for binary (image/*) responses.
-
#headers ⇒ Hash
readonly
Response headers.
-
#status ⇒ Integer
readonly
HTTP status code.
Instance Method Summary collapse
-
#binary? ⇒ Boolean
Checks if the response body is raw binary data (e.g., image bytes).
-
#initialize(status:, headers:, body:) ⇒ Response
constructor
Creates a new response wrapper.
-
#request_id ⇒ String?
Returns the request ID for this response.
-
#success? ⇒ Boolean
Checks if the response indicates success (2xx status).
Constructor Details
#initialize(status:, headers:, body:) ⇒ Response
Creates a new response wrapper.
29 30 31 32 33 |
# File 'lib/reve_ai/response.rb', line 29 def initialize(status:, headers:, body:) @status = status @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Hash, String (readonly)
Returns Parsed response body, or raw bytes String for binary (image/*) responses.
22 23 24 |
# File 'lib/reve_ai/response.rb', line 22 def body @body end |
#headers ⇒ Hash (readonly)
Returns Response headers.
18 19 20 |
# File 'lib/reve_ai/response.rb', line 18 def headers @headers end |
#status ⇒ Integer (readonly)
Returns HTTP status code.
15 16 17 |
# File 'lib/reve_ai/response.rb', line 15 def status @status end |
Instance Method Details
#binary? ⇒ Boolean
Checks if the response body is raw binary data (e.g., image bytes).
45 46 47 |
# File 'lib/reve_ai/response.rb', line 45 def binary? !body.is_a?(Hash) end |
#request_id ⇒ String?
Returns the request ID for this response.
Useful for debugging and support requests.
54 55 56 |
# File 'lib/reve_ai/response.rb', line 54 def request_id body_value(:request_id) || headers["x-reve-request-id"] end |
#success? ⇒ Boolean
Checks if the response indicates success (2xx status).
38 39 40 |
# File 'lib/reve_ai/response.rb', line 38 def success? status >= 200 && status < 300 end |