Class: Lapsoss::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/lapsoss/http_client.rb

Overview

HTTP client wrapper using Faraday with retry logic

Constant Summary collapse

USER_AGENT =
"lapsoss/#{Lapsoss::VERSION}".freeze

Instance Method Summary collapse

Constructor Details

#initialize(base_url, config = {}) ⇒ HttpClient

Returns a new instance of HttpClient.



13
14
15
16
17
# File 'lib/lapsoss/http_client.rb', line 13

def initialize(base_url, config = {})
  @base_url = base_url
  @config = config
  @connection = build_connection
end

Instance Method Details

#post(path, body:, headers: {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lapsoss/http_client.rb', line 19

def post(path, body:, headers: {})
  response = @connection.post(path) do |req|
    req.body = body
    req.headers.merge!(headers)
  end

  unless response.success?
    raise DeliveryError.new(
      "HTTP #{response.status}: #{response.reason_phrase}",
      response: response
    )
  end

  response
rescue Faraday::Error => e
  raise DeliveryError.new(
    "Network error: #{e.message}",
    cause: e
  )
end

#shutdownObject



40
41
42
# File 'lib/lapsoss/http_client.rb', line 40

def shutdown
  # Faraday connections don't need explicit shutdown
end