2010-03-26 11:15:27 -07:00
|
|
|
module Fog
|
|
|
|
class Connection
|
2009-07-13 18:22:42 -07:00
|
|
|
|
2011-01-20 07:56:29 +08:00
|
|
|
def initialize(url, persistent=false, params={})
|
|
|
|
@excon = Excon.new(url, params)
|
2010-06-19 18:56:38 -07:00
|
|
|
@persistent = persistent
|
2010-03-26 11:15:27 -07:00
|
|
|
end
|
2009-07-14 16:04:39 -07:00
|
|
|
|
2010-05-09 16:23:03 -07:00
|
|
|
def request(params, &block)
|
2010-06-19 18:56:38 -07:00
|
|
|
unless @persistent
|
|
|
|
reset
|
|
|
|
end
|
2010-05-09 16:23:03 -07:00
|
|
|
unless block_given?
|
|
|
|
if (parser = params.delete(:parser))
|
|
|
|
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
2012-03-17 13:39:43 -05:00
|
|
|
params[:response_block] = lambda { |chunk, remaining, total| body << chunk }
|
2010-05-09 16:23:03 -07:00
|
|
|
end
|
2009-07-13 18:22:42 -07:00
|
|
|
end
|
|
|
|
|
2010-05-09 16:23:03 -07:00
|
|
|
response = @excon.request(params, &block)
|
2012-02-18 10:54:23 -06:00
|
|
|
|
2010-03-26 11:15:27 -07:00
|
|
|
if parser
|
|
|
|
body.finish
|
|
|
|
response.body = parser.response
|
2009-07-14 16:04:39 -07:00
|
|
|
end
|
2009-08-07 00:28:53 -07:00
|
|
|
|
2010-03-26 11:15:27 -07:00
|
|
|
response
|
2009-07-13 18:22:42 -07:00
|
|
|
end
|
|
|
|
|
2010-06-19 18:56:38 -07:00
|
|
|
def reset
|
|
|
|
@excon.reset
|
|
|
|
end
|
|
|
|
|
2009-07-13 18:22:42 -07:00
|
|
|
end
|
|
|
|
end
|