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/excon.rb,
lib/faraday/adapter/patron.rb,
lib/faraday/adapter/em_http.rb,
lib/faraday/adapter/net_http.rb,
lib/faraday/adapter/typhoeus.rb,
lib/faraday/adapter/httpclient.rb,
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/adapter/net_http_persistent.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

Adapter is the base class for all Faraday adapters.

See Also:

  • Original class location

Direct Known Subclasses

EMHttp, EMSynchrony, Excon, HTTPClient, NetHttp, Patron, Rack, Typhoeus

Defined Under Namespace

Modules: Parallelism Classes: EMHttp, EMSynchrony, Excon, HTTPClient, NetHttp, NetHttpPersistent, Patron, Rack, Typhoeus

Constant Summary collapse

CONTENT_LENGTH =
'Content-Length'

Instance Attribute Summary

Attributes included from Parallelism

#supports_parallel

Attributes included from DependencyLoader

#load_error

Instance Method Summary collapse

Methods included from AutoloadHelper

all_loaded_constants, autoload_all, load_autoloaded_constants

Methods included from Parallelism

inherited, supports_parallel?

Methods included from DependencyLoader

dependency, inherited, loaded?

Methods included from MiddlewareRegistry

fetch_middleware, load_middleware, lookup_middleware, middleware_mutex, register_middleware, unregister_middleware

Constructor Details

#initialize(_app = nil, opts = {}, &block) ⇒ Adapter

Returns a new instance of Adapter.


44
45
46
47
48
# File 'lib/faraday/adapter.rb', line 44

def initialize(_app = nil, opts = {}, &block)
  @app = ->(env) { env.response }
  @connection_options = opts
  @config_block = block
end

Instance Method Details

#call(env) ⇒ Object


71
72
73
74
# File 'lib/faraday/adapter.rb', line 71

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.


66
67
68
69
# File 'lib/faraday/adapter.rb', line 66

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.


57
58
59
60
61
62
# File 'lib/faraday/adapter.rb', line 57

def connection(env)
  conn = build_connection(env)
  return conn unless block_given?

  yield conn
end