Class: Fog::Connection

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

Direct Known Subclasses

IBM::Connection

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Connection.



4
5
6
7
8
9
10
11
12
# File 'lib/fog/core/connection.rb', line 4

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}"
  @excon = Excon.new(url, params)
  @persistent = persistent
end

Instance Method Details

#request(params, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/core/connection.rb', line 14

def request(params, &block)
  unless @persistent
    reset
  end
  unless block_given?
    if (parser = params.delete(:parser))
      body = Nokogiri::XML::SAX::PushParser.new(parser)
      params[:response_block] = lambda { |chunk, remaining, total| body << chunk }
    end
  end

  response = @excon.request(params, &block)

  if parser
    body.finish
    response.body = parser.response
  end

  response
end

#resetObject



35
36
37
# File 'lib/fog/core/connection.rb', line 35

def reset
  @excon.reset
end