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