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.

API:

  • private

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:

  • Mapping of HTTP status codes to error classes

API:

  • private

{
  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:

  • HTTP status codes that trigger automatic retry

API:

  • private

[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:

  • Configuration instance

API:

  • private



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:

  • Configuration instance for this client

API:

  • private



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:

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

  • (defaults to: {})

    Request body to send as JSON

Returns:

  • Parsed API response

Raises:

  • if request times out

  • if connection fails

  • for other network errors

  • on 400 responses

  • on 401 responses

  • on 402 responses

  • on 403 responses

  • on 404 responses

  • on 422 responses

  • on 429 responses

  • on 5xx responses

API:

  • private



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