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

#get(path, params: nil) ⇒ 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 GET request to the API.

Parameters:

  • path (String)

    API endpoint path (e.g., "/v1/image/effect")

  • params (Hash, nil) (defaults to: nil)

    Query parameters to merge into the URL (e.g., { source: "project" })

Returns:

Raises:



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

def get(path, params: nil)
  normalized_path = path.sub(%r{^/}, "")
  response = perform_request do |conn|
    conn.get(normalized_path) { |req| req.params.update(params) if params }
  end
  handle_response(response)
end

#post(path, body = {}, params: nil, accept: nil) ⇒ 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

  • params (Hash, nil) (defaults to: nil)

    Query parameters to merge into the URL (e.g., { breadcrumb: "my-tracking-value" })

  • accept (String, nil) (defaults to: nil)

    Per-request Accept header override (e.g., "image/webp"). The connection default stays "application/json".

Returns:

  • (Response)

    Parsed API response. When the response Content-Type is image/*, the body is the raw image String (bytes), not a Hash.

Raises:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/reve_ai/http/client.rb', line 96

def post(path, body = {}, params: nil, accept: nil)
  normalized_path = path.sub(%r{^/}, "")
  response = perform_request do |conn|
    conn.post(normalized_path) do |req|
      req.params.update(params) if params
      req.headers["Accept"] = accept if accept
      req.body = JSON.generate(body)
    end
  end
  handle_response(response)
end