Class: Ace::LLM::Atoms::HTTPClient
- Inherits:
-
Object
- Object
- Ace::LLM::Atoms::HTTPClient
- 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
-
#delete(url, **options) ⇒ Faraday::Response
Perform a DELETE request.
-
#get(url, **options) ⇒ Faraday::Response
Perform a GET request.
-
#initialize(options = {}) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
-
#post(url, body = nil, **options) ⇒ Faraday::Response
Perform a POST request.
-
#put(url, body = nil, **options) ⇒ Faraday::Response
Perform a PUT request.
Constructor Details
#initialize(options = {}) ⇒ HTTPClient
Returns a new instance of HTTPClient.
17 18 19 20 21 22 23 |
# File 'lib/ace/llm/atoms/http_client.rb', line 17 def initialize( = {}) @timeout = .fetch(:timeout, 30).to_i @open_timeout = .fetch(:open_timeout, 10).to_i @max_retries = .fetch(:max_retries, 3).to_i @retry_statuses = .fetch(:retry_statuses, [429, 500, 502, 503, 504]) @retry_delay = .fetch(:retry_delay, 1.0).to_f end |
Instance Method Details
#delete(url, **options) ⇒ Faraday::Response
Perform a DELETE request
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ace/llm/atoms/http_client.rb', line 83 def delete(url, **) params = .fetch(:params, {}) headers = .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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ace/llm/atoms/http_client.rb', line 31 def get(url, **) params = .fetch(:params, {}) headers = .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
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, **) headers = .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
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, **) headers = .fetch(:headers, {}) execute_with_retry do connection(url).put do |req| req.body = body req.headers.merge!(headers) unless headers.empty? end end end |