Module: Faraday

Defined in:
lib/faraday.rb,
lib/faraday/error.rb,
lib/faraday/utils.rb,
lib/faraday/adapter.rb,
lib/faraday/options.rb,
lib/faraday/request.rb,
lib/faraday/autoload.rb,
lib/faraday/response.rb,
lib/faraday/upload_io.rb,
lib/faraday/connection.rb,
lib/faraday/middleware.rb,
lib/faraday/parameters.rb,
lib/faraday/adapter/rack.rb,
lib/faraday/adapter/test.rb,
lib/faraday/rack_builder.rb,
lib/faraday/adapter/excon.rb,
lib/faraday/request/retry.rb,
lib/faraday/adapter/patron.rb,
lib/faraday/adapter/em_http.rb,
lib/faraday/response/logger.rb,
lib/faraday/adapter/net_http.rb,
lib/faraday/adapter/typhoeus.rb,
lib/faraday/request/multipart.rb,
lib/faraday/adapter/httpclient.rb,
lib/faraday/request/url_encoded.rb,
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/response/raise_error.rb,
lib/faraday/request/authorization.rb,
lib/faraday/request/instrumentation.rb,
lib/faraday/adapter/net_http_persistent.rb,
lib/faraday/request/basic_authentication.rb,
lib/faraday/request/token_authentication.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

Rely on autoloading instead of explicit require; helps avoid the “already initialized constant” warning on Ruby 1.8.7 when NetHttp is refereced below. require ‘faraday/adapter/net_http’

Defined Under Namespace

Modules: AutoloadHelper, FlatParamsEncoder, MiddlewareRegistry, NestedParamsEncoder, Utils Classes: Adapter, ClientError, CompositeReadIO, Connection, ConnectionFailed, ConnectionOptions, Env, Error, Middleware, MissingDependency, Options, ParsingError, ProxyOptions, RackBuilder, Request, RequestOptions, ResourceNotFound, Response, SSLError, SSLOptions, TimeoutError

Constant Summary collapse

VERSION =
"0.12.2"
Timer =
Timeout
UploadIO =
::UploadIO
Parts =
::Parts

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_adapterObject

Public: Gets or sets the Symbol key identifying a default Adapter to use for the default Faraday::Connection.



29
30
31
# File 'lib/faraday.rb', line 29

def default_adapter
  @default_adapter
end

.default_connectionObject

Gets the default connection used for simple scripts.

Returns a Faraday::Connection, configured with the #default_adapter.



111
112
113
# File 'lib/faraday.rb', line 111

def self.default_connection
  @default_connection ||= Connection.new(default_connection_options)
end

.lib_pathObject

Public: Gets or sets the path that the Faraday libs are loaded from.



25
26
27
# File 'lib/faraday.rb', line 25

def lib_path
  @lib_path
end

.root_pathObject

Public: Gets or sets the root path that Faraday is being loaded from. This is the root from where the libraries are auto-loaded from.



22
23
24
# File 'lib/faraday.rb', line 22

def root_path
  @root_path
end

Class Method Details

.const_missing(name) ⇒ Object



229
230
231
232
233
234
235
236
# File 'lib/faraday.rb', line 229

def self.const_missing(name)
  if name.to_sym == :Builder
    warn "Faraday::Builder is now Faraday::RackBuilder."
    const_set name, RackBuilder
  else
    super
  end
end

.default_connection_optionsObject

Gets the default connection options used when calling Faraday#new.

Returns a Faraday::ConnectionOptions.



118
119
120
# File 'lib/faraday.rb', line 118

def self.default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end

.default_connection_options=(options) ⇒ Object

Public: Sets the default options used when calling Faraday#new.



123
124
125
126
# File 'lib/faraday.rb', line 123

def self.default_connection_options=(options)
  @default_connection = nil
  @default_connection_options = ConnectionOptions.from(options)
end

.new(url = nil, options = nil) ⇒ Object

Public: Initializes a new Faraday::Connection.

url - The optional String base URL to use as a prefix for all

requests.  Can also be the options Hash.

options - The optional Hash used to configure this Faraday::Connection.

Any of these values will be set on every request made, unless
overridden for a specific request.
:url     - String base URL.
:params  - Hash of URI query unencoded key/value pairs.
:headers - Hash of unencoded HTTP header key/value pairs.
:request - Hash of request options.
:ssl     - Hash of SSL options.
:proxy   - Hash of Proxy options.

Examples

Faraday.new 'http://faraday.com'

# http://faraday.com?page=1
Faraday.new 'http://faraday.com', :params => {:page => 1}

# same

Faraday.new :url => 'http://faraday.com',
  :params => {:page => 1}

Returns a Faraday::Connection.



64
65
66
67
68
# File 'lib/faraday.rb', line 64

def new(url = nil, options = nil)
  block = block_given? ? Proc.new : nil
  options = options ? default_connection_options.merge(options) : default_connection_options
  Faraday::Connection.new(url, options, &block)
end

.require_libs(*libs) ⇒ Object Also known as: require_lib

Internal: Requires internal Faraday libraries.

*libs - One or more relative String names to Faraday classes.

Returns nothing.



75
76
77
78
79
# File 'lib/faraday.rb', line 75

def require_libs(*libs)
  libs.each do |lib|
    require "#{lib_path}/#{lib}"
  end
end

.respond_to?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/faraday.rb', line 92

def respond_to?(symbol, include_private = false)
  default_connection.respond_to?(symbol, include_private) || super
end