Module: Faraday

Extended by:
AutoloadHelper
Defined in:
lib/faraday.rb,
lib/faraday/error.rb,
lib/faraday/utils.rb,
lib/faraday/adapter.rb,
lib/faraday/builder.rb,
lib/faraday/request.rb,
lib/faraday/response.rb,
lib/faraday/upload_io.rb,
lib/faraday/connection.rb,
lib/faraday/middleware.rb,
lib/faraday/adapter/rack.rb,
lib/faraday/adapter/test.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/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

Public: This is the main namespace for Faraday. You can either use it to create Faraday::Connection objects, or access it directly.

Examples

Faraday.get "http://faraday.com"

conn = Faraday.new "http://faraday.com"
conn.get '/'

Defined Under Namespace

Modules: AutoloadHelper, Error, MiddlewareRegistry, Utils Classes: Adapter, Builder, CompositeReadIO, Connection, Middleware, Request, Response

Constant Summary collapse

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

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from AutoloadHelper

all_loaded_constants, autoload_all, load_autoloaded_constants

Class Attribute Details

.default_adapterObject

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



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

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.



96
97
98
# File 'lib/faraday.rb', line 96

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

.default_connection_optionsObject

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

Returns an options Hash.



103
104
105
# File 'lib/faraday.rb', line 103

def self.default_connection_options
  @default_connection_options ||= {}
end

.lib_pathObject

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



20
21
22
# File 'lib/faraday.rb', line 20

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.



17
18
19
# File 'lib/faraday.rb', line 17

def root_path
  @root_path
end

Class Method Details

.new(url = nil, options = {}) ⇒ 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.



62
63
64
65
66
# File 'lib/faraday.rb', line 62

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

.register_middleware(type, mapping = nil) ⇒ Object

Public: Register middleware classes under a short name.

type - A Symbol specifying the kind of middleware (default: :middleware) mapping - A Hash mapping Symbol keys to classes. Classes can be expressed

as fully qualified constant, or a Proc that will be lazily called
to return the former.

Examples

Faraday.register_middleware :aloha => MyModule::Aloha
Faraday.register_middleware :response, :boom => MyModule::Boom

# shortcuts are now available in Builder:
builder.use :aloha
builder.response :boom

Returns nothing.



237
238
239
240
241
# File 'lib/faraday.rb', line 237

def self.register_middleware(type, mapping = nil)
  type, mapping = :middleware, type if mapping.nil?
  component = self.const_get(type.to_s.capitalize)
  component.register_middleware(mapping)
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.



73
74
75
76
77
# File 'lib/faraday.rb', line 73

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