module Faraday

This is the main namespace for Faraday.

It provides methods to create {Connection} objects, and HTTP-related methods to use directly.

@example Helpful class methods for easy usage

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

@example Helpful class method `.new` to create {Connection} objects.

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

Faraday namespace.

Constants

FilePart

@!method initialize(filename_or_io, content_type, filename = nil, opts = {})

@param filename_or_io [String, IO] Either a String filename to a local
  file or an open IO object.
@param content_type [String] String content type of the file data.
@param filename [String] Optional String filename, usually to add context
  to a given IO object.
@param opts [Hash] Optional Hash of String key/value pairs to describethis
  this uploaded file. Expected Header keys include:
  * Content-Transfer-Encoding - Defaults to "binary"
  * Content-Disposition - Defaults to "form-data"
  * Content-Type - Defaults to the content_type argument.
  * Content-ID - Optional.

@return [Faraday::FilePart]

@!attribute [r] content_type The uploaded binary data's content type.

@return [String]

@!attribute [r] original_filename The base filename, taken either from the filename_or_io or filename arguments in initialize.

@return [String]

@!attribute [r] opts Extra String key/value pairs to make up the header for this uploaded file.

@return [Hash]

@!attribute [r] io The open IO object for the uploaded file.

@return [IO]

METHODS_WITH_BODY
METHODS_WITH_QUERY
Parts
Timer
UploadIO

Multipart value used to POST a file.

@deprecated Use FilePart instead of this class. It behaves identically, with

a matching name to ParamPart.
VERSION

Attributes

default_adapter[R]

@overload default_adapter

Gets the Symbol key identifying a default Adapter to use
for the default {Faraday::Connection}. Defaults to `:net_http`.
@return [Symbol] the default adapter

@overload default_adapter=(adapter)

Updates default adapter while resetting {.default_connection}.
@return [Symbol] the new default_adapter.
default_connection[W]

Documented below, see default_connection

ignore_env_proxy[RW]

Tells Faraday to ignore the environment proxy (http_proxy). Defaults to `false`. @return [Boolean]

lib_path[RW]

Gets or sets the path that the Faraday libs are loaded from. @return [String]

root_path[RW]

The root path that Faraday is being loaded from.

This is the root from where the libraries are auto-loaded.

@return [String]

Public Class Methods

default_adapter=(adapter) click to toggle source

Documented elsewhere, see default_adapter reader

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

@overload default_connection

Gets the default connection used for simple scripts.
@return [Faraday::Connection] a connection configured with
the default_adapter.

@overload default_connection=(connection)

@param connection [Faraday::Connection]
Sets the default {Faraday::Connection} for simple scripts that
access the Faraday constant directly, such as
<code>Faraday.get "https://faraday.com"</code>.
# File lib/faraday.rb, line 147
def default_connection
  @default_connection ||= Connection.new(default_connection_options)
end
default_connection_options() click to toggle source

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

@return [Faraday::ConnectionOptions]

# File lib/faraday.rb, line 154
def default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end
default_connection_options=(options) click to toggle source

Sets the default options used when calling {Faraday#new}.

@param options [Hash, Faraday::ConnectionOptions]

# File lib/faraday.rb, line 161
def default_connection_options=(options)
  @default_connection = nil
  @default_connection_options = ConnectionOptions.from(options)
end
new(url = nil, options = {}, &block) click to toggle source

Initializes a new {Connection}.

@param url [String,Hash] The optional String base URL to use as a prefix

for all requests.  Can also be the options Hash. Any of these
values will be set on every request made, unless overridden
for a specific request.

@param options [Hash] @option options [String] :url Base URL @option options [Hash] :params Hash of unencoded URI query params. @option options [Hash] :headers Hash of unencoded HTTP headers. @option options [Hash] :request Hash of request options. @option options [Hash] :ssl Hash of SSL options. @option options [Hash] :proxy Hash of Proxy options. @return [Faraday::Connection]

@example With an URL argument

Faraday.new 'http://faraday.com'
# => Faraday::Connection to http://faraday.com

@example With an URL argument and an options hash

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

@example With everything in an options hash

Faraday.new url: 'http://faraday.com',
            params: { page: 1 }
# => Faraday::Connection to http://faraday.com?page=1
# File lib/faraday.rb, line 110
def new(url = nil, options = {}, &block)
  options = default_connection_options.merge(options)
  Faraday::Connection.new(url, options, &block)
end
require_lib(*libs)
Alias for: require_libs
require_libs(*libs) click to toggle source

@private Internal: Requires internal Faraday libraries.

@param libs [Array] one or more relative String names to Faraday classes. @return [void]

# File lib/faraday.rb, line 120
def require_libs(*libs)
  libs.each do |lib|
    require "#{lib_path}/#{lib}"
  end
end
Also aliased as: require_lib
respond_to_missing?(symbol, include_private = false) click to toggle source
Calls superclass method
# File lib/faraday.rb, line 134
def respond_to_missing?(symbol, include_private = false)
  default_connection.respond_to?(symbol, include_private) || super
end

Private Class Methods

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

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

Calls superclass method
# File lib/faraday.rb, line 170
def method_missing(name, *args, &block)
  if default_connection.respond_to?(name)
    default_connection.send(name, *args, &block)
  else
    super
  end
end