Class: Faraday::Adapter::Patron

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

Constant Summary

Constants inherited from Faraday::Adapter

CONTENT_TYPE, DEFAULT_BOUNDARY, FORM_TYPE, MULTIPART_TYPE

Instance Method Summary collapse

Methods inherited from Faraday::Adapter

#full_path_for, #has_multipart?, #process_body_for_request, #process_to_params

Methods included from Faraday::AutoloadHelper

#all_loaded_constants, #autoload_all, #load_autoloaded_constants, #lookup_module, #register_lookup_modules

Methods inherited from Middleware

#initialize, loaded?, 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)
  super

  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.new(Errno::ECONNREFUSED)
end

#create_multipart(env, params, boundary = nil) ⇒ Object

TODO: build in support for multipart streaming if patron supports it.



33
34
35
36
# File 'lib/faraday/adapter/patron.rb', line 33

def create_multipart(env, params, boundary = nil)
  stream = super
  stream.read
end