Class: Fog::Core::Connection
- Inherits:
-
Object
- Object
- Fog::Core::Connection
- 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.
Constant Summary collapse
- @@user_agents =
[]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url, persistent = false, params = {}) ⇒ Connection
constructor
Prepares the connection and sets defaults for any future requests.
-
#request(params, &block) ⇒ Excon::Response
(also: #original_request)
Makes a request using the connection using Excon.
-
#reset ⇒ Object
Closes the connection.
Constructor Details
#initialize(url, persistent = false, params = {}) ⇒ Connection
Prepares the connection and sets defaults for any future requests.
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 |
Class Method Details
.add_user_agent(str) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/fog/core/connection.rb', line 13 def add_user_agent(str) if /\S+\/[\d|.]+/.match(str) @@user_agents << str else raise "User Agent must be in <app name>/<app version> notation." end end |
Instance Method Details
#request(params, &block) ⇒ Excon::Response Also known as: original_request
Makes a request using the connection using Excon
78 79 80 |
# File 'lib/fog/core/connection.rb', line 78 def request(params, &block) @excon.request(handle_path_prefix_for(params), &block) end |
#reset ⇒ Object
Closes the connection
90 91 92 |
# File 'lib/fog/core/connection.rb', line 90 def reset @excon.reset end |