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/file_part.rb,
lib/faraday/connection.rb,
lib/faraday/middleware.rb,
lib/faraday/param_part.rb,
lib/faraday/options/env.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/utils/headers.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/adapter_registry.rb,
lib/faraday/deprecated_class.rb,
lib/faraday/dependency_loader.rb,
lib/faraday/logging/formatter.rb,
lib/faraday/request/multipart.rb,
lib/faraday/utils/params_hash.rb,
lib/faraday/adapter/httpclient.rb,
lib/faraday/middleware_registry.rb,
lib/faraday/options/ssl_options.rb,
lib/faraday/request/url_encoded.rb,
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/response/raise_error.rb,
lib/faraday/options/proxy_options.rb,
lib/faraday/request/authorization.rb,
lib/faraday/options/request_options.rb,
lib/faraday/request/instrumentation.rb,
lib/faraday/options/connection_options.rb,
lib/faraday/adapter/net_http_persistent.rb,
lib/faraday/encoders/flat_params_encoder.rb,
lib/faraday/request/basic_authentication.rb,
lib/faraday/request/token_authentication.rb,
lib/faraday/encoders/nested_params_encoder.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

Faraday namespace.

Defined Under Namespace

Modules: AutoloadHelper, DecodeMethods, DependencyLoader, DeprecatedClass, EncodeMethods, FlatParamsEncoder, Logging, MiddlewareRegistry, NestedParamsEncoder, Utils Classes: Adapter, AdapterRegistry, BadRequestError, ClientError, CompositeReadIO, ConflictError, Connection, ConnectionFailed, ConnectionOptions, Env, Error, ForbiddenError, Middleware, Options, ParamPart, ParsingError, ProxyAuthError, ProxyOptions, RackBuilder, Request, RequestOptions, ResourceNotFound, Response, RetriableResponse, SSLError, SSLOptions, ServerError, TimeoutError, UnauthorizedError, UnprocessableEntityError

Constant Summary collapse

VERSION =
'0.16.2'
METHODS_WITH_QUERY =
%w[get head delete connect trace].freeze
METHODS_WITH_BODY =
%w[post put patch].freeze
Timer =
Timeout
FilePart =

The uploaded binary data’s content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:

::UploadIO
UploadIO =
Deprecated.

Use FilePart instead of this class. It behaves identically, with a matching name to ParamPart.

Multipart value used to POST a file.

::UploadIO
Parts =
::Parts

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_adapterSymbol .default_adapter=(adapter) ⇒ Symbol

Overloads:

  • .default_adapterSymbol

    Gets the Symbol key identifying a default Adapter to use for the default Connection. Defaults to ‘:net_http`.

    Returns:

    • (Symbol)

      the default adapter

  • .default_adapter=(adapter) ⇒ Symbol

    Updates default adapter while resetting default_connection.

    Returns:

    • (Symbol)

      the new default_adapter.



45
46
47
# File 'lib/faraday.rb', line 45

def default_adapter
  @default_adapter
end

.default_connectionFaraday::Connection .default_connection=(connection) ⇒ Object

Overloads:

  • .default_connectionFaraday::Connection

    Gets the default connection used for simple scripts. the default_adapter.

    Returns:

  • .default_connection=(connection) ⇒ Object

    Sets the default Connection for simple scripts that access the Faraday constant directly, such as Faraday.get "https://faraday.com".

    Parameters:



137
138
139
# File 'lib/faraday.rb', line 137

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

.ignore_env_proxyBoolean

Tells Faraday to ignore the environment proxy (http_proxy). Defaults to ‘false`.

Returns:

  • (Boolean)


53
54
55
# File 'lib/faraday.rb', line 53

def ignore_env_proxy
  @ignore_env_proxy
end

.lib_pathString

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

Returns:

  • (String)


36
37
38
# File 'lib/faraday.rb', line 36

def lib_path
  @lib_path
end

.root_pathString

The root path that Faraday is being loaded from.

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

Returns:

  • (String)


32
33
34
# File 'lib/faraday.rb', line 32

def root_path
  @root_path
end

Instance Attribute Details

#content_typeFaraday::FilePart, ... (readonly)

The uploaded binary data’s content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:



53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

#ioFaraday::FilePart, ... (readonly)

The uploaded binary data’s content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:



53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

#optsFaraday::FilePart, ... (readonly)

The uploaded binary data’s content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:



53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

#original_filenameFaraday::FilePart, ... (readonly)

The uploaded binary data’s content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:



53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

Class Method Details

.default_connection_optionsFaraday::ConnectionOptions

Gets the default connection options used when calling new.



144
145
146
# File 'lib/faraday.rb', line 144

def self.default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end

.default_connection_options=(options) ⇒ Object

Sets the default options used when calling new.

Parameters:



151
152
153
154
# File 'lib/faraday.rb', line 151

def self.default_connection_options=(options)
  @default_connection = nil
  @default_connection_options = ConnectionOptions.from(options)
end

.new(url = nil, options = {}, &block) ⇒ Faraday::Connection

Initializes a new Connection.

Examples:

With an URL argument

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

With an URL argument and an options hash

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

With everything in an options hash

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

Parameters:

  • url (String, Hash) (defaults to: nil)

    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.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :url (String)

    Base URL

  • :params (Hash)

    Hash of unencoded URI query params.

  • :headers (Hash)

    Hash of unencoded HTTP headers.

  • :request (Hash)

    Hash of request options.

  • :ssl (Hash)

    Hash of SSL options.

  • :proxy (Hash)

    Hash of Proxy options.

Returns:



82
83
84
85
# File 'lib/faraday.rb', line 82

def new(url = nil, options = {}, &block)
  options = default_connection_options.merge(options)
  Faraday::Connection.new(url, options, &block)
end

.require_libs(*libs) ⇒ void Also known as: require_lib

This method returns an undefined value.

Internal: Requires internal Faraday libraries.

Parameters:

  • libs (Array)

    one or more relative String names to Faraday classes.



92
93
94
95
96
# File 'lib/faraday.rb', line 92

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

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

Returns:

  • (Boolean)


106
107
108
# File 'lib/faraday.rb', line 106

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

Instance Method Details

#initialize(filename_or_io, content_type, filename = nil, opts = {}) ⇒ Object

Parameters:

  • filename_or_io (String, IO)

    Either a String filename to a local file or an open IO object.

  • content_type (String)

    String content type of the file data.

  • filename (String) (defaults to: nil)

    Optional String filename, usually to add context to a given IO object.

  • opts (Hash) (defaults to: {})

    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.



53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO