Class: ReveAI::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/reve_ai/response.rb

Overview

Base response wrapper for API responses.

Provides access to HTTP status, headers, and parsed response body.

See Also:

Direct Known Subclasses

ImageResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, headers:, body:) ⇒ Response

Creates a new response wrapper.

Parameters:

  • HTTP status code

  • Response headers

  • Parsed response body



24
25
26
27
28
# File 'lib/reve_ai/response.rb', line 24

def initialize(status:, headers:, body:)
  @status = status
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyHash (readonly)

Returns Parsed response body.

Returns:

  • Parsed response body



17
18
19
# File 'lib/reve_ai/response.rb', line 17

def body
  @body
end

#headersHash (readonly)

Returns Response headers.

Returns:

  • Response headers



14
15
16
# File 'lib/reve_ai/response.rb', line 14

def headers
  @headers
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • HTTP status code



11
12
13
# File 'lib/reve_ai/response.rb', line 11

def status
  @status
end

Instance Method Details

#request_idString?

Returns the request ID for this response.

Useful for debugging and support requests.

Returns:

  • Request ID from body or headers



42
43
44
# File 'lib/reve_ai/response.rb', line 42

def request_id
  body[:request_id] || headers["x-reve-request-id"]
end

#success?Boolean

Checks if the response indicates success (2xx status).

Returns:

  • true if status is between 200 and 299



33
34
35
# File 'lib/reve_ai/response.rb', line 33

def success?
  status >= 200 && status < 300
end