Class: ReveAI::HTTP::Client Private
- Inherits:
-
Object
- Object
- ReveAI::HTTP::Client
- 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.
{ 400 => BadRequestError, 401 => , 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.
[429, 500, 502, 503, 504].freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Configuration
readonly
private
Configuration instance for this client.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Client
constructor
private
Creates a new HTTP client.
-
#post(path, body = {}) ⇒ Response
private
Makes a POST request to the API.
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.
38 39 40 |
# File 'lib/reve_ai/http/client.rb', line 38 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Configuration (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.
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.
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 |