Class: Faraday::Adapter
- Inherits:
-
Object
- Object
- Faraday::Adapter
- Extended by:
- Parallelism, MiddlewareRegistry
- Defined in:
- lib/faraday/adapter.rb,
lib/faraday/adapter/test.rb
Overview
Base class for all Faraday adapters. Adapters are responsible for fulfilling a Faraday request.
Direct Known Subclasses
Defined Under Namespace
Modules: Parallelism Classes: Test
Constant Summary collapse
- CONTENT_LENGTH =
'Content-Length'
Instance Attribute Summary
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
lookup_middleware, register_middleware, registered_middleware, unregister_middleware
Methods included from Parallelism
Constructor Details
#initialize(_app = nil, opts = {}, &block) ⇒ Adapter
Returns a new instance of Adapter.
28 29 30 31 32 |
# File 'lib/faraday/adapter.rb', line 28 def initialize(_app = nil, opts = {}, &block) @app = lambda(&:response) @connection_options = opts @config_block = block end |
Instance Method Details
#call(env) ⇒ Object
55 56 57 58 |
# File 'lib/faraday/adapter.rb', line 55 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.
50 51 52 53 |
# File 'lib/faraday/adapter.rb', line 50 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.
41 42 43 44 45 46 |
# File 'lib/faraday/adapter.rb', line 41 def connection(env) conn = build_connection(env) return conn unless block_given? yield conn end |