Class: Keiyaku::HTTPAdapter
- Inherits:
-
Object
- Object
- Keiyaku::HTTPAdapter
- Includes:
- _Adapter
- Defined in:
- lib/keiyaku/adapters/http.rb,
sig/keiyaku.rbs
Overview
Loaded only by require "keiyaku/adapters/http". Wraps the http.rb gem.
Instance Method Summary collapse
- #call(verb, uri, headers, body) ⇒ Object
-
#initialize(client = nil, timeout: 15) ⇒ HTTPAdapter
constructor
A new instance of HTTPAdapter.
Constructor Details
#initialize(client = nil, timeout: 15) ⇒ HTTPAdapter
Returns a new instance of HTTPAdapter.
20 21 22 23 |
# File 'lib/keiyaku/adapters/http.rb', line 20 def initialize(client = nil, timeout: 15) open, read = Keiyaku.timeouts(timeout) @client = client || HTTP.timeout(connect: open, read:) end |
Instance Method Details
#call(verb, uri, headers, body) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/keiyaku/adapters/http.rb', line 25 def call(verb, uri, headers, body) response = @client.headers(headers).request(verb, uri, body.nil? ? {} : { body: }) [response.code, response.headers.to_h, response.body.to_s] rescue HTTP::ConnectionError, HTTP::TimeoutError, *TRANSPORT_ERRORS => e raise ConnectionError, "#{verb.to_s.upcase} #{uri}: #{e.}" end |