Class: Faraday::Adapter::Patron

Inherits:
Middleware show all
Defined in:
lib/faraday/adapter/patron.rb

Instance Method Summary collapse

Methods inherited from Middleware

#create_form_params, #full_path_for, #initialize, loaded?, #process_body_for_request, setup_parallel_manager

Constructor Details

This class inherits a constructor from Faraday::Middleware

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/faraday/adapter/patron.rb', line 10

def call(env)
  process_body_for_request(env)

  sess = ::Patron::Session.new
  args = [env[:method], env[:url].to_s, env[:request_headers]]
  if Faraday::Connection::METHODS_WITH_BODIES.include?(env[:method])
    args.insert(2, env[:body].to_s)
  end
  resp = sess.send *args

  env.update \
    :status           => resp.status,
    :response_headers => resp.headers.
      inject({}) { |memo, (k, v)| memo.update(k.downcase => v) },
    :body             => resp.body
  env[:response].finish(env)

  @app.call env
rescue Errno::ECONNREFUSED
  raise Error::ConnectionFailed, "connection refused"
end