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

[GH-2711] Add Fog::XML::Connection

Attempting to move to using Fog::XML::SAXParserConnection directly
failed because the arguments changed.

This adds another compatibility level with two key differences:

1) It's namespaced within XML so stands out as not being part of core
2) It is NOT creating deprecation warnings so can be used as the final
   step if rewriting to use SAXParserConnection is undesired

So when merged Fog::Connection usage will create noise.

Fog::XML::Connection works the same way and will be extracted to
"fog/xml" when we get to it.

Fog::Core::Connection just wraps Excon.request and leaves the response
body parsing to the provider.
This commit is contained in:
Paul Thornthwaite 2014-02-26 22:07:06 +00:00
parent 7f37977d2e
commit 1768f2a37e
5 changed files with 57 additions and 15 deletions

View file

@ -12,15 +12,14 @@ module Fog
#
# @see https://github.com/geemus/excon/blob/master/lib/excon/connection.rb
#
class Connection < Fog::XML::SAXParserConnection
class Connection < Fog::XML::Connection
def request(params, &block)
if (parser = params.delete(:parser))
Fog::Logger.deprecation("Fog::Connection is deprecated use Fog::XML::SAXParserConnection instead [light_black](#{caller.first})[/]")
super(parser, params)
if params.key?(:parser)
Fog::Logger.deprecation("Fog::Connection is deprecated use Fog::XML::Connection instead [light_black](#{caller.first})[/]")
else
Fog::Logger.deprecation("Fog::Connection is deprecated use Fog::Core::Connection instead [light_black](#{caller.first})[/]")
original_request(params)
end
super(params)
end
end
end

View file

@ -1,5 +1,6 @@
require "nokogiri"
require "fog/core/parser"
require "fog/xml/sax_parser_connection"
module Fog
@ -15,7 +16,14 @@ module Fog
# its services
#
module XML
class Connection < Fog::XML::SAXParserConnection
def request(params, &block)
if (parser = params.delete(:parser))
super(parser, params)
else
original_request(params)
end
end
end
end
end
require "fog/xml/sax_parser_connection"

13
lib/fog/xml/connection.rb Normal file
View file

@ -0,0 +1,13 @@
module Fog
module XML
class Connection < SAXParserConnection
def request(params, &block)
if (parser = params.delete(:parser))
super(parser, params)
else
original_request(params)
end
end
end
end
end

View file

@ -0,0 +1,30 @@
require "minitest/autorun"
require "fog"
# Note this is going to be part of fog-xml eventually
class TestFogXMLConnection < MiniTest::Unit::TestCase
def setup
@connection = Fog::XML::Connection.new("http://localhost")
end
def teardown
Excon.stubs.clear
end
def test_respond_to_request
assert_respond_to @connection, :request
end
def test_request_with_parser
@parser = Fog::ToHashDocument.new
Excon.stub({}, { :status => 200, :body => "<xml></xml>" })
response = @connection.request(:parser => @parser, :mock => true)
assert_equal({ :xml => "" }, response.body)
end
def test_request_without_parser
Excon.stub({}, { :status => 200, :body => "<xml></xml>" })
response = @connection.request(:mock => true)
assert_equal("<xml></xml>", response.body)
end
end

View file

@ -1,8 +0,0 @@
require "minitest/autorun"
class HelloWorldTest < Minitest::Test
# This is a placeholder to ensure minitest is being picked up by rake
def test_truth
assert true
end
end