1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/connection.rb

36 lines
684 B
Ruby
Raw Normal View History

2010-03-26 14:15:27 -04:00
module Fog
class Connection
def initialize(url, persistent=false, params={})
@excon = Excon.new(url, params)
@persistent = persistent
2010-03-26 14:15:27 -04:00
end
def request(params, &block)
unless @persistent
reset
end
unless block_given?
if (parser = params.delete(:parser))
body = Nokogiri::XML::SAX::PushParser.new(parser)
block = lambda { |chunk, remaining, total| body << chunk }
end
end
response = @excon.request(params, &block)
2010-03-26 14:15:27 -04:00
if parser
body.finish
response.body = parser.response
end
2009-08-07 03:28:53 -04:00
2010-03-26 14:15:27 -04:00
response
end
def reset
@excon.reset
end
end
end