Class: Lapsoss::HttpClient
- Inherits:
-
Object
- Object
- Lapsoss::HttpClient
- Defined in:
- lib/lapsoss/http_client.rb
Overview
HTTP client wrapper using Faraday with retry logic
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(base_url, config = {}) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(path, body:, headers: {}) ⇒ Object
- #shutdown ⇒ Object
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.}", cause: e ) end |
#shutdown ⇒ Object
40 41 42 |
# File 'lib/lapsoss/http_client.rb', line 40 def shutdown # Faraday connections don't need explicit shutdown end |