Skip to content

Commit

Permalink
fix for issue savonrb#51
Browse files Browse the repository at this point in the history
added the :soap_endpoint option to Savon::Client#new for specifying a custom soap endpoint per instance.
  • Loading branch information
rubiii committed Mar 27, 2010
1 parent 1504cdf commit 84f10fc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
19 changes: 15 additions & 4 deletions lib/savon/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ module Savon
#
# client = Savon::Client.new "http://example.com/UserService?wsdl", :proxy => "http://proxy.example.com"
#
# == Forcing a particular SOAP endpoint
#
# In case you don't want to use the SOAP endpoint specified in the WSDL, you can tell Savon to use
# another SOAP endpoint.
#
# client = Savon::Client.new "http://example.com/UserService?wsdl", :soap_endpoint => "http://localhost/UserService"
#
# == Savon::WSDL
#
# You can access Savon::WSDL via:
Expand All @@ -40,11 +47,15 @@ module Savon
# client.request
class Client

# Expects a SOAP +endpoint+ string. Also accepts an optional hash of +options+ for specifying
# a +:proxy+ server to use.
# Expects a SOAP +endpoint+ string. Also accepts a Hash of +options+.
#
# ==== Options:
#
# [proxy] the proxy server to use
# [soap_endpoint] force to use this SOAP endpoint
def initialize(endpoint, options = {})
@request = Request.new endpoint, options
@wsdl = WSDL.new @request
@request = Request.new endpoint, options.delete(:proxy)
@wsdl = WSDL.new @request, options.delete(:soap_endpoint)
end

# Returns the Savon::WSDL.
Expand Down
7 changes: 3 additions & 4 deletions lib/savon/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ class Request
# Content-Types by SOAP version.
ContentType = { 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }

# Expects a SOAP +endpoint+ String. Also accepts an optional Hash
# of +options+ for specifying a proxy server.
def initialize(endpoint, options = {})
# Expects a WSDL or SOAP +endpoint+ and accepts a custom +proxy+ address.
def initialize(endpoint, proxy = nil)
@endpoint = URI endpoint
@proxy = options[:proxy] ? URI(options[:proxy]) : URI("")
@proxy = proxy ? URI(proxy) : URI("")
end

# Returns the endpoint URI.
Expand Down
6 changes: 3 additions & 3 deletions lib/savon/wsdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ module Savon
# end
class WSDL

# Initializer, expects a Savon::Request.
def initialize(request)
@request, @enabled = request, true
# Expects a Savon::Request and accepts a custom +soap_endpoint+.
def initialize(request, soap_endpoint = nil)
@request, @enabled, @soap_endpoint = request, true, soap_endpoint
end

# Sets whether to use the WSDL.
Expand Down
5 changes: 5 additions & 0 deletions spec/savon/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
client.request.http.proxy_address == "http://proxy"
end

it "should accept a SOAP endpoint via an optional Hash of options" do
client = Savon::Client.new EndpointHelper.wsdl_endpoint, :soap_endpoint => "http://localhost"
client.wsdl.soap_endpoint.should == "http://localhost"
end

it "should have a method that returns the Savon::WSDL" do
@client.wsdl.should be_a(Savon::WSDL)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/savon/wsdl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
Savon::WSDL.new Savon::Request.new(EndpointHelper.wsdl_endpoint)
end

it "it accepts a custom SOAP endpoint" do
wsdl = Savon::WSDL.new Savon::Request.new(EndpointHelper.wsdl_endpoint), "http://localhost"
wsdl.soap_endpoint.should == "http://localhost"
end

it "is enabled by default" do
@wsdl.enabled?.should be_true
end
Expand Down

0 comments on commit 84f10fc

Please sign in to comment.