Class: Keiyaku::FaradayAdapter
- Inherits:
-
Object
- Object
- Keiyaku::FaradayAdapter
- Includes:
- _Adapter
- Defined in:
- lib/keiyaku/adapters/faraday.rb,
sig/keiyaku.rbs
Overview
Loaded only by require "keiyaku/adapters/faraday". Faraday's own types
are deliberately not named here: the signature has to resolve whether or
not the gem is installed.
Instance Method Summary collapse
- #call(verb, uri, headers, body) ⇒ Object
-
#initialize(connection = nil, timeout: nil, **options) ⇒ FaradayAdapter
constructor
A new instance of FaradayAdapter.
Constructor Details
#initialize(connection = nil, timeout: nil, **options) ⇒ FaradayAdapter
Returns a new instance of FaradayAdapter.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/keiyaku/adapters/faraday.rb', line 22 def initialize(connection = nil, timeout: nil, **) if timeout # Faraday has its own spelling for these, and a connection that was # handed in already carries whatever it was built with. Accepting the # option and dropping it would be the worst of the three. raise ArgumentError, "timeout: has no effect on a connection you built; set it on that" if connection open, read = Keiyaku.timeouts(timeout) [:request] = { open_timeout: open, timeout: read }.merge([:request] || {}) end @connection = connection || Faraday.new(**) end |
Instance Method Details
#call(verb, uri, headers, body) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/keiyaku/adapters/faraday.rb', line 36 def call(verb, uri, headers, body) response = @connection.run_request(verb, uri, body, headers) [response.status, response.headers.to_h, response.body] rescue Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError => e raise ConnectionError, "#{verb.to_s.upcase} #{uri}: #{e.}" end |