Method: Fog::Core::Connection#initialize

Defined in:
lib/fog/core/connection.rb

#initialize(url, persistent = false, params = {}) ⇒ Connection

Prepares the connection and sets defaults for any future requests.

Parameters:

  • url (String)

    The destination URL

  • persistent (Boolean) (defaults to: false)
  • params (Hash) (defaults to: {})

Options Hash (params):

  • :body (String)

    Default text to be sent over a socket. Only used if :body absent in Connection#request params

  • :headers (Hash<Symbol, String>)

    The default headers to supply in a request. Only used if params is not supplied to Connection#request

  • :host (String)

    The destination host’s reachable DNS name or IP, in the form of a String

  • :path (String)

    Default path; appears after ‘scheme://host:port/’. Only used if params is not supplied to Connection#request

  • :path_prefix (String)

    Sticky version of the “path” arg. :XSpath_prefix => “foo/bar” with a request with :path => “blech” sends a request to path “foo/bar/blech”

  • :port (Fixnum)

    The port on which to connect, to the destination host

  • :query (Hash)

    Default query; appended to the ‘scheme://host:port/path/’ in the form of ‘?key=value’. Will only be used if params is not supplied to Connection#request

  • :scheme (String)

    The protocol; ‘https’ causes OpenSSL to be used

  • :proxy (String)

    Proxy server; e.g. ‘myproxy.com:8888

  • :retry_limit (Fixnum)

    Set how many times we’ll retry a failed request. (Default 4)

  • :instrumentor (Class)

    Responds to #instrument as in ActiveSupport::Notifications

  • :instrumentor_name (String)

    Name prefix for #instrument events. Defaults to ‘excon’



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fog/core/connection.rb', line 46

def initialize(url, persistent = false, params = {})
  @path_prefix = params.delete(:path_prefix)

  if @path_prefix && params[:path]
    raise ArgumentError, "optional arg 'path' is invalid when 'path_prefix' is provided"
  end

  params[:debug_response] = true unless params.key?(:debug_response)
  params[:headers] ||= {}
  params.merge!(:persistent => params.fetch(:persistent, persistent))
  params[:headers]["User-Agent"] ||= user_agent
  @excon = Excon.new(url, params)
end