Class: Faraday::Adapter

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

Test

Defined Under Namespace

Modules: Parallelism Classes: Test

Constant Summary collapse

CONTENT_LENGTH =
'Content-Length'

Instance Attribute Summary

Attributes included from Parallelism

#supports_parallel

Instance Method Summary collapse

Methods included from MiddlewareRegistry

lookup_middleware, register_middleware, registered_middleware, unregister_middleware

Methods included from Parallelism

inherited, supports_parallel?

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

#closeObject

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.

Parameters:

  • env (Faraday::Env, Hash)

    The env object for a faraday request.

Yields:

  • (conn)

Returns:

  • The return value of the given block, or the HTTP connection object if no block is given.



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