Class: Faraday::Adapter
- Inherits:
-
Object
- Object
- Faraday::Adapter
- Extended by:
- Parallelism, AutoloadHelper, DependencyLoader, MiddlewareRegistry
- Defined in:
- lib/faraday/adapter.rb,
lib/faraday/autoload.rb,
lib/faraday/adapter/rack.rb,
lib/faraday/adapter/test.rb,
lib/faraday/adapter/patron.rb,
lib/faraday/adapter/typhoeus.rb,
lib/faraday/adapter/httpclient.rb
Overview
Adapter is the base class for all Faraday adapters.
Direct Known Subclasses
HTTPClient, Patron, Rack, Test, Typhoeus
Defined Under Namespace
Modules: Parallelism Classes: HTTPClient, Patron, Rack, Test, Typhoeus
Constant Summary collapse
- CONTENT_LENGTH =
'Content-Length'
Instance Attribute Summary
Attributes included from DependencyLoader
Attributes included from Parallelism
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#close ⇒ Object
Close any persistent connections.
-
#connection(env) {|conn| ... } ⇒ Object
Yields or returns an adapter’s configured connection.
-
#initialize(_app = nil, opts = {}, &block) ⇒ Adapter
constructor
A new instance of Adapter.
Methods included from MiddlewareRegistry
fetch_middleware, load_middleware, lookup_middleware, middleware_mutex, register_middleware, unregister_middleware
Methods included from DependencyLoader
dependency, inherited, loaded?, new
Methods included from Parallelism
Methods included from AutoloadHelper
all_loaded_constants, autoload_all, load_autoloaded_constants
Constructor Details
#initialize(_app = nil, opts = {}, &block) ⇒ Adapter
Returns a new instance of Adapter.
36 37 38 39 40 |
# File 'lib/faraday/adapter.rb', line 36 def initialize(_app = nil, opts = {}, &block) @app = ->(env) { env.response } @connection_options = opts @config_block = block end |
Instance Method Details
#call(env) ⇒ Object
63 64 65 66 |
# File 'lib/faraday/adapter.rb', line 63 def call(env) env.clear_body if env.needs_body? env.response = Response.new end |
#close ⇒ Object
Close any persistent connections. The adapter should still be usable after calling close.
58 59 60 61 |
# File 'lib/faraday/adapter.rb', line 58 def close # Possible implementation: # @app.close if @app.respond_to?(:close) end |
#connection(env) {|conn| ... } ⇒ Object
Yields or returns an adapter’s configured connection. Depends on #build_connection being defined on this adapter.
49 50 51 52 53 54 |
# File 'lib/faraday/adapter.rb', line 49 def connection(env) conn = build_connection(env) return conn unless block_given? yield conn end |