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
Public: Gets or sets the Symbol key identifying a default Adapter to use for the default Faraday::Connection.
Public: Sets the default Faraday::Connection for simple scripts that access the Faraday constant directly.
Faraday.get "https://faraday.com"
Public: Tells faraday to ignore the environment proxy (http_proxy).
Public: Gets or sets the path that the Faraday libs are loaded from.
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
# 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
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
Gets the default connection used for simple scripts.
Returns a Faraday::Connection, configured with the default_adapter.
# File lib/faraday.rb, line 115 def self.default_connection @default_connection ||= Connection.new(default_connection_options) end
Gets the default connection options used when calling Faraday#new.
Returns a Faraday::ConnectionOptions.
# File lib/faraday.rb, line 122 def self.default_connection_options @default_connection_options ||= ConnectionOptions.new end
Public: Sets the default options used when calling Faraday#new.
# File lib/faraday.rb, line 127 def self.default_connection_options=(options) @default_connection = nil @default_connection_options = ConnectionOptions.from(options) end
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 Faraday::Connection.new(url, options, &block) end
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
# File lib/faraday.rb, line 95 def respond_to?(symbol, include_private = false) default_connection.respond_to?(symbol, include_private) || super end
Private Class Methods
Internal: Proxies method calls on the Faraday constant to default_connection.
# File lib/faraday.rb, line 102 def method_missing(name, *args, &block) default_connection.send(name, *args, &block) end