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

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, FlatParamsEncoder, MiddlewareRegistry, NestedParamsEncoder, Utils Classes: Adapter, ClientError, CompositeReadIO, Connection, ConnectionFailed, ConnectionOptions, Env, Error, Middleware, Options, ParsingError, ProxyOptions, RackBuilder, Request, RequestOptions, ResourceNotFound, Response, RetriableResponse, SSLError, SSLOptions, TimeoutError

Constant Summary collapse

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



115
116
117
# File 'lib/faraday.rb', line 115

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

.ignore_env_proxyObject

Public: Tells faraday to ignore the environment proxy (http_proxy).



38
39
40
# File 'lib/faraday.rb', line 38

def ignore_env_proxy
  @ignore_env_proxy
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



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

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.



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

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.



127
128
129
130
# File 'lib/faraday.rb', line 127

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.



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

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

Returns:

  • (Boolean)


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

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