Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass the adapter option in initializer, pass it to HTTPI when fetching remote WSDL #44

Merged
merged 2 commits into from
May 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/wasabi/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def self.validate_element_form_default!(value)
end

# Accepts a WSDL +document+ to parse.
def initialize(document = nil)
def initialize(document = nil, adapter = nil)
self.document = document
self.adapter = adapter
end

attr_accessor :document, :request
attr_accessor :document, :request, :adapter

attr_writer :xml

Expand Down Expand Up @@ -138,7 +139,7 @@ def user_defined(namespace)
# Returns the raw WSDL document.
# Can be used as a hook to extend the library.
def xml
@xml ||= Resolver.new(document, request).resolve
@xml ||= Resolver.new(document, request, adapter).resolve
end

# Parses the WSDL document and returns the <tt>Wasabi::Parser</tt>.
Expand Down
7 changes: 4 additions & 3 deletions lib/wasabi/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ def initialize(message, response=nil)
URL = /^http[s]?:/
XML = /^</

def initialize(document, request = nil)
def initialize(document, request = nil, adapter = nil)
@document = document
@request = request || HTTPI::Request.new
@adapter = adapter
end

attr_reader :document, :request
attr_reader :document, :request, :adapter

def resolve
raise ArgumentError, "Unable to resolve: #{document.inspect}" unless document
Expand All @@ -39,7 +40,7 @@ def resolve

def load_from_remote
request.url = document
response = HTTPI.get(request)
response = HTTPI.get(request, adapter)

raise HTTPError.new("Error: #{response.code}", response) if response.error?

Expand Down
2 changes: 1 addition & 1 deletion lib/wasabi/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wasabi
VERSION = "3.2.3"
VERSION = "3.2.4"
end
18 changes: 18 additions & 0 deletions spec/support/adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class FakeAdapterForTest < HTTPI::Adapter::Base

register :fake_adapter_for_test

def initialize(request)
@@requests ||= []
@@requests.push request
@request = request
end

attr_reader :client

def request(method)
@@methods ||= []
@@methods.push method
HTTPI::Response.new(200, {}, 'wsdl_by_adapter')
end
end
11 changes: 11 additions & 0 deletions spec/wasabi/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
xml.should == "wsdl"
end

it "resolves remote documents with custom adapter" do
prev_logging = HTTPI.instance_variable_get(:@log)
HTTPI.log = false # Don't pollute rspec output by request logging
xml = Wasabi::Resolver.new("http://example.com?wsdl", nil, :fake_adapter_for_test).resolve
xml.should == "wsdl_by_adapter"
expect(FakeAdapterForTest.class_variable_get(:@@requests).size).to eq(1)
expect(FakeAdapterForTest.class_variable_get(:@@requests).first.url).to eq(URI.parse("http://example.com?wsdl"))
expect(FakeAdapterForTest.class_variable_get(:@@methods)).to eq([:get])
HTTPI.log = prev_logging
end

it "resolves local documents" do
xml = Wasabi::Resolver.new(fixture(:authentication).path).resolve
xml.should == fixture(:authentication).read
Expand Down