Class: Faraday::Adapter

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

See Also:

  • Original class location

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

#load_error

Attributes included from Parallelism

#supports_parallel

Instance Method Summary collapse

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

inherited, supports_parallel?

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

#closeObject

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.

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.



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