Module: Faraday

Defined in:
lib/faraday.rb,
lib/faraday/utils.rb,
lib/faraday/error.rb,
lib/faraday/options.rb,
lib/faraday/adapter.rb,
lib/faraday/request.rb,
lib/faraday/response.rb,
lib/faraday/autoload.rb,
lib/faraday/upload_io.rb,
lib/faraday/parameters.rb,
lib/faraday/connection.rb,
lib/faraday/middleware.rb,
lib/faraday/adapter/test.rb,
lib/faraday/adapter/rack.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/token_authentication.rb,
lib/faraday/request/basic_authentication.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb,
test/helper.rb,
test/live_server.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, LiveServerConfig, MiddlewareRegistry, NestedParamsEncoder, Utils Classes: Adapter, ClientError, CompositeReadIO, Connection, ConnectionFailed, ConnectionOptions, Env, Error, LiveServer, Middleware, MissingDependency, Options, ParsingError, ProxyOptions, RackBuilder, Request, RequestOptions, ResourceNotFound, Response, SSLError, SSLOptions, TestCase, TimeoutError

Constant Summary

VERSION =
"0.9.1"
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.



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

def self.default_connection
  @default_connection ||= Connection.new
end

.default_connection_optionsObject

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

Returns a Faraday::ConnectionOptions.



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

def self.default_connection_options
  @default_connection_options ||= ConnectionOptions.new
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



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

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

.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.



67
68
69
70
71
# File 'lib/faraday.rb', line 67

def new(url = nil, options = nil)
  block = block_given? ? Proc.new : nil
  options = options ? default_connection_options.merge(options) : default_connection_options.dup
  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.



78
79
80
81
82
# File 'lib/faraday.rb', line 78

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