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 => 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.
[429, 500, 502, 503, 504].freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Configuration
readonly
private
Configuration instance for this client.
Instance Method Summary collapse
-
#get(path, params: nil) ⇒ Response
private
Makes a GET request to the API.
-
#initialize(configuration) ⇒ Client
constructor
private
Creates a new HTTP client.
-
#post(path, body = {}, params: nil, accept: nil) ⇒ 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
#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.
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.
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 |