Class: ReveAI::HTTP::Client Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Low-level HTTP client using Faraday.

Handles connection management, request/response processing, error handling, and automatic retries for transient failures.

Constant Summary collapse

ERROR_CODE_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns Mapping of HTTP status codes to error classes.

Returns:

  • (Hash{Integer => Class})

    Mapping of HTTP status codes to error classes

{
  400 => BadRequestError,
  401 => UnauthorizedError,
  402 => InsufficientCreditsError,
  403 => ForbiddenError,
  404 => NotFoundError,
  422 => UnprocessableEntityError,
  429 => RateLimitError
}.freeze
RETRY_STATUSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns HTTP status codes that trigger automatic retry.

Returns:

  • (Array<Integer>)

    HTTP status codes that trigger automatic retry

[429, 500, 502, 503, 504].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Client

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new HTTP client.

Parameters:



38
39
40
# File 'lib/reve_ai/http/client.rb', line 38

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationConfiguration (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Configuration instance for this client.

Returns:



32
33
34
# File 'lib/reve_ai/http/client.rb', line 32

def configuration
  @configuration
end

Instance Method Details

#post(path, body = {}) ⇒ Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes a POST request to the API.

Parameters:

  • path (String)

    API endpoint path (e.g., “/v1/image/create”)

  • body (Hash) (defaults to: {})

    Request body to send as JSON

Returns:

Raises:



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/reve_ai/http/client.rb', line 62

def post(path, body = {})
  normalized_path = path.sub(%r{^/}, "")
  response = connection.post(normalized_path) { |req| req.body = JSON.generate(body) }
  handle_response(response)
rescue Faraday::TimeoutError => e
  raise TimeoutError, "Request timed out: #{e.message}"
rescue Faraday::ConnectionFailed => e
  handle_connection_failed(e)
rescue Faraday::Error => e
  raise NetworkError, "Network error: #{e.message}"
end