Module: Faraday

Defined in:
lib/faraday.rb,
lib/faraday/error.rb,
lib/faraday/utils.rb,
lib/faraday/adapter.rb,
lib/faraday/methods.rb,
lib/faraday/options.rb,
lib/faraday/request.rb,
lib/faraday/version.rb,
lib/faraday/response.rb,
lib/faraday/connection.rb,
lib/faraday/middleware.rb,
lib/faraday/options/env.rb,
lib/faraday/adapter/test.rb,
lib/faraday/rack_builder.rb,
lib/faraday/request/json.rb,
lib/faraday/response/json.rb,
lib/faraday/utils/headers.rb,
lib/faraday/response/logger.rb,
lib/faraday/adapter_registry.rb,
lib/faraday/logging/formatter.rb,
lib/faraday/utils/params_hash.rb,
lib/faraday/middleware_registry.rb,
lib/faraday/options/ssl_options.rb,
lib/faraday/request/url_encoded.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/encoders/flat_params_encoder.rb,
lib/faraday/encoders/nested_params_encoder.rb

Overview

Faraday namespace.

Defined Under Namespace

Modules: DecodeMethods, EncodeMethods, FlatParamsEncoder, Logging, MiddlewareRegistry, NestedParamsEncoder, Utils Classes: Adapter, AdapterRegistry, BadRequestError, ClientError, ConflictError, Connection, ConnectionFailed, ConnectionOptions, Env, Error, ForbiddenError, InitializationError, Middleware, NilStatusError, Options, ParsingError, ProxyAuthError, ProxyOptions, RackBuilder, Request, RequestOptions, RequestTimeoutError, ResourceNotFound, Response, SSLError, SSLOptions, ServerError, TimeoutError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError

Constant Summary collapse

CONTENT_TYPE =
'Content-Type'
METHODS_WITH_QUERY =
%w[get head delete trace].freeze
METHODS_WITH_BODY =
%w[post put patch].freeze
VERSION =
'2.12.1'

Class Attribute Summary collapse

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



55
56
57
# File 'lib/faraday.rb', line 55

def default_adapter
  @default_adapter
end

.default_adapter_optionsObject

Option for the default_adapter

@return [Hash] default_adapter options


59
60
61
# File 'lib/faraday.rb', line 59

def default_adapter_options
  @default_adapter_options
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:



120
121
122
# File 'lib/faraday.rb', line 120

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


67
68
69
# File 'lib/faraday.rb', line 67

def ignore_env_proxy
  @ignore_env_proxy
end

.lib_pathString

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

Returns:

  • (String)


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

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)


42
43
44
# File 'lib/faraday.rb', line 42

def root_path
  @root_path
end

Class Method Details

.default_connection_optionsFaraday::ConnectionOptions

Gets the default connection options used when calling new.



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

def default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end

.default_connection_options=(options) ⇒ Object

Sets the default options used when calling new.

Parameters:



134
135
136
137
# File 'lib/faraday.rb', line 134

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



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

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

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

Returns:

  • (Boolean)


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

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