Permalink
Browse files

Support using sandbox endpoint via configuration

  • Loading branch information...
1 parent 9b92e6e commit 8ae72a9b12378fd2a498f004114fc41a8561a714 Josh Martin committed Jun 7, 2012
View
@@ -17,10 +17,15 @@ def self.configure(opts={})
savon.logger = opts[:logger]
savon.log = opts[:logger] ? true : false
end
+
+ if Api.instance.config.sandbox
+ Api.instance.sandbox!
+ end
end
class Api
include Singleton
+
# @return [Savon::Client]
def client
@client ||= make_client
@@ -32,14 +37,21 @@ def client
# @return [Zuora::Config]
attr_accessor :config
- WSDL = File.expand_path('../../../wsdl/zuora.a.38.0.wsdl', __FILE__)
+ PRODUCTION_WSDL = File.expand_path('../../../wsdl/production/zuora.a.38.0.wsdl', __FILE__)
+ SANDBOX_WSDL = File.expand_path('../../../wsdl/sandbox/zuora.a.38.0.wsdl', __FILE__)
# Is this an authenticated session?
# @return [Boolean]
def authenticated?
self.session.try(:active?)
end
+ # Change client to sandbox url
+ def sandbox!
+ @client = nil
+ self.class.instance.client.wsdl.document = SANDBOX_WSDL
+ end
+
# The XML that was transmited in the last request
# @return [String]
def last_request
@@ -95,7 +107,7 @@ def initialize
def make_client
Savon::Client.new do
- wsdl.document = (defined?(ZUORA_WSDL) && ZUORA_WSDL) || WSDL
+ wsdl.document = defined?(ZUORA_WSDL) ? ZUORA_WSDL : PRODUCTION_WSDL
http.auth.ssl.verify_mode = :none
end
end
View
@@ -204,7 +204,7 @@ def clear_changed_attributes!
@changed_attributes = {}
self
end
-
+
# the name to use when referencing remote Zuora objects
def remote_name
self.class.name.base_name
View
@@ -6,14 +6,23 @@
Zuora::Api.any_instance.stub(:authenticated?).and_return(true)
end
- it "has readable WSDL" do
- File.exists?(Zuora::Api::WSDL).should be
+ it "has readable production WSDL" do
+ File.exists?(Zuora::Api::PRODUCTION_WSDL).should be
end
- it "uses provided WSDL" do
+ it "has readable sandbox WSDL" do
+ File.exists?(Zuora::Api::SANDBOX_WSDL).should be
+ end
+
+ it "uses production WSDL by default" do
Zuora::Api.instance.client.wsdl.endpoint.to_s.should == "https://www.zuora.com/apps/services/a/38.0"
end
+ it "can be configured to use sandbox WSDL" do
+ Zuora.configure(:username => 'example', :password => 'test', :sandbox => true)
+ Zuora::Api.instance.client.wsdl.endpoint.to_s.should == "https://apisandbox.zuora.com/apps/services/a/38.0"
+ end
+
it "can be configured multiple times" do
Zuora.configure(:username => 'example', :password => 'test')
Zuora::Api.instance.config.should be_a_kind_of(Zuora::Config)
@@ -23,7 +32,7 @@
Zuora::Api.instance.config.password.should == 'changed'
end
end
-
+
describe "logger support" do
it "allows using custom logger" do
MockResponse.responds_with(:valid_login) do
File renamed without changes.
Oops, something went wrong.

0 comments on commit 8ae72a9

Please sign in to comment.