diff --git a/lib/netsuite/configuration.rb b/lib/netsuite/configuration.rb index 89ebb4d6..936cbb24 100644 --- a/lib/netsuite/configuration.rb +++ b/lib/netsuite/configuration.rb @@ -17,6 +17,7 @@ def attributes def connection(params={}, credentials={}) client = Savon.client({ wsdl: cached_wsdl || wsdl, + endpoint: endpoint, read_timeout: read_timeout, open_timeout: open_timeout, namespaces: namespaces, @@ -94,6 +95,18 @@ def api_version=(version) attributes[:api_version] = version end + def endpoint=(endpoint) + attributes[:endpoint] = endpoint + end + + def endpoint(endpoint=nil) + if endpoint + self.endpoint = endpoint + else + attributes[:endpoint] + end + end + def sandbox=(flag) if attributes[:sandbox] != flag attributes[:wsdl] = nil diff --git a/spec/netsuite/configuration_spec.rb b/spec/netsuite/configuration_spec.rb index 7b48a0c6..a6d0920f 100644 --- a/spec/netsuite/configuration_spec.rb +++ b/spec/netsuite/configuration_spec.rb @@ -29,10 +29,12 @@ end describe '#connection' do + EXAMPLE_ENDPOINT = 'https://1023.suitetalk.api.netsuite.com/services/NetSuitePort_2020_2' before(:each) do # reset clears out the password info config.email 'me@example.com' config.password 'me@example.com' + config.endpoint EXAMPLE_ENDPOINT config.account 1023 config.wsdl "my_wsdl" config.api_version "2012_2" @@ -57,6 +59,19 @@ expect(config).to have_received(:cached_wsdl) end + + it 'sets the endpoint on the Savon client' do + # this is ugly/brittle, but it's hard to see how else to test this + savon_configs = config.connection.globals.instance_eval {@options} + expect(savon_configs.fetch(:endpoint)).to eq(EXAMPLE_ENDPOINT) + end + + it 'handles a nil endpoint' do + config.endpoint = nil + # this is ugly/brittle, but it's hard to see how else to test this + savon_configs = config.connection.globals.instance_eval {@options} + expect(savon_configs.fetch(:endpoint)).to eq(nil) + end end describe '#wsdl' do @@ -166,6 +181,23 @@ end end + describe '#endpoint' do + it 'can be set with endpoint=' do + config.endpoint = 42 + expect(config.endpoint).to eq(42) + end + + it 'can be set with just endpoint(value)' do + config.endpoint(42) + expect(config.endpoint).to eq(42) + end + + it 'supports nil endpoints' do + config.endpoint = nil + expect(config.endpoint).to eq(nil) + end + end + describe '#auth_header' do context 'when doing user authentication' do before do