module Faraday

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

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'

Constants

Parts
Timer
UploadIO
VERSION

Attributes

default_adapter[R]

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

default_connection[W]

Public: Sets the default Faraday::Connection for simple scripts that access the Faraday constant directly.

Faraday.get "https://faraday.com"
default_connection_options[W]

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

lib_path[RW]

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

root_path[RW]

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.

Public Class Methods

const_missing(name) click to toggle source
Calls superclass method
# 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
default_connection() click to toggle source

Gets the default connection used for simple scripts.

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

# File lib/faraday.rb, line 110
def self.default_connection
  @default_connection ||= Connection.new
end
default_connection_options() click to toggle source

Gets the default connection options used when calling #new.

Returns a Faraday::ConnectionOptions.

# File lib/faraday.rb, line 117
def self.default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end

Public Instance Methods

default_adapter=(adapter) click to toggle source

Public: Updates default adapter while resetting default_connection.

Returns the new default_adapter.

# File lib/faraday.rb, line 88
def default_adapter=(adapter)
  @default_connection = nil
  @default_adapter = adapter
end
new(url = nil, options = nil) click to toggle source

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.

# 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) click to toggle source

Internal: Requires internal Faraday libraries.

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

Returns nothing.

# File lib/faraday.rb, line 78
def require_libs(*libs)
  libs.each do |lib|
    require "#{lib_path}/#{lib}"
  end
end

Private Instance Methods

method_missing(name, *args, &block) click to toggle source

Internal: Proxies method calls on the Faraday constant to default_connection.

# File lib/faraday.rb, line 98
def method_missing(name, *args, &block)
  default_connection.send(name, *args, &block)
end