Class: Keiyaku::FaradayAdapter

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(connection = nil, timeout: nil, **options) ⇒ FaradayAdapter

Returns a new instance of FaradayAdapter.

Parameters:

  • connection (Object) (defaults to: nil)
  • timeout: (timeout, nil) (defaults to: nil)
  • (Object)


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, **options)
  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)
    options[:request] = { open_timeout: open, timeout: read }.merge(options[:request] || {})
  end

  @connection = connection || Faraday.new(**options)
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.message}"
end