Class: Ace::LLM::Atoms::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/llm/atoms/http_client.rb

Overview

HTTPClient provides basic HTTP operations using Faraday This is an atom - it has no dependencies on other parts of this gem

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTTPClient

Returns a new instance of HTTPClient.

Options Hash (options):

  • :timeout (Integer) — default: 30

    Request timeout in seconds

  • :open_timeout (Integer) — default: 10

    Connection open timeout in seconds

  • :max_retries (Integer) — default: 3

    Maximum number of retries

  • :retry_statuses (Array<Integer>) — default: [429, 500, 502, 503, 504]

    Status codes to retry

  • :retry_delay (Float) — default: 1.0

    Initial retry delay in seconds



17
18
19
20
21
22
23
# File 'lib/ace/llm/atoms/http_client.rb', line 17

def initialize(options = {})
  @timeout = options.fetch(:timeout, 30).to_i
  @open_timeout = options.fetch(:open_timeout, 10).to_i
  @max_retries = options.fetch(:max_retries, 3).to_i
  @retry_statuses = options.fetch(:retry_statuses, [429, 500, 502, 503, 504])
  @retry_delay = options.fetch(:retry_delay, 1.0).to_f
end

Instance Method Details

#delete(url, **options) ⇒ Faraday::Response

Perform a DELETE request

Options Hash (**options):

  • :params (Hash) — default: {}

    Query parameters

  • :headers (Hash) — default: {}

    Request headers



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ace/llm/atoms/http_client.rb', line 83

def delete(url, **options)
  params = options.fetch(:params, {})
  headers = options.fetch(:headers, {})

  execute_with_retry do
    connection(url).delete do |req|
      req.params = params unless params.empty?
      req.headers.merge!(headers) unless headers.empty?
    end
  end
end

#get(url, **options) ⇒ Faraday::Response

Perform a GET request

Options Hash (**options):

  • :params (Hash) — default: {}

    Query parameters

  • :headers (Hash) — default: {}

    Request headers



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/llm/atoms/http_client.rb', line 31

def get(url, **options)
  params = options.fetch(:params, {})
  headers = options.fetch(:headers, {})

  execute_with_retry do
    connection(url).get do |req|
      req.params = params unless params.empty?
      req.headers.merge!(headers) unless headers.empty?
    end
  end
end

#post(url, body = nil, **options) ⇒ Faraday::Response

Perform a POST request

Options Hash (**options):

  • :headers (Hash) — default: {}

    Request headers



49
50
51
52
53
54
55
56
57
58
# File 'lib/ace/llm/atoms/http_client.rb', line 49

def post(url, body = nil, **options)
  headers = options.fetch(:headers, {})

  execute_with_retry do
    connection(url).post do |req|
      req.body = body
      req.headers.merge!(headers) unless headers.empty?
    end
  end
end

#put(url, body = nil, **options) ⇒ Faraday::Response

Perform a PUT request

Options Hash (**options):

  • :headers (Hash) — default: {}

    Request headers



66
67
68
69
70
71
72
73
74
75
# File 'lib/ace/llm/atoms/http_client.rb', line 66

def put(url, body = nil, **options)
  headers = options.fetch(:headers, {})

  execute_with_retry do
    connection(url).put do |req|
      req.body = body
      req.headers.merge!(headers) unless headers.empty?
    end
  end
end