Class: Fog::Core::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/core/connection.rb

Overview

Fog::Core::Connection is a generic class to contain a HTTP link to an API.

It is intended to be subclassed by providers who can then add their own modifications such as authentication or response object.

Direct Known Subclasses

XML::SAXParserConnection

Instance Method Summary collapse

Constructor Details

#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

  • :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’



27
28
29
30
31
32
33
34
35
# File 'lib/fog/core/connection.rb', line 27

def initialize(url, persistent=false, params={})
  unless params.has_key?(:debug_response)
    params[:debug_response] = true
  end
  params[:headers] ||= {}
  params[:headers]['User-Agent'] ||= "fog/#{Fog::VERSION}"
  params.merge!(:persistent => params.fetch(:persistent, persistent))
  @excon = Excon.new(url, params)
end

Instance Method Details

#request(params, &block) ⇒ Excon::Response Also known as: original_request

Makes a request using the connection using Excon

Parameters:

Options Hash (params):

  • :body (String)

    text to be sent over a socket

  • :headers (Hash<Symbol, String>)

    The default headers to supply in a request

  • :host (String)

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

  • :path (String)

    appears after ‘scheme://host:port/’

  • :port (Fixnum)

    The port on which to connect, to the destination host

  • :query (Hash)

    appended to the ‘scheme://host:port/path/’ in the form of ‘?key=value’

  • :scheme (String)

    The protocol; ‘https’ causes OpenSSL to be used

  • :response_block (Proc)

Returns:

  • (Excon::Response)

Raises:

  • (Excon::Errors::StubNotFound)
  • (Excon::Errors::Timeout)
  • (Excon::Errors::SocketError)


55
56
57
# File 'lib/fog/core/connection.rb', line 55

def request(params, &block)
  @excon.request(params, &block)
end

#resetObject

Closes the connection



67
68
69
# File 'lib/fog/core/connection.rb', line 67

def reset
  @excon.reset
end