From 3e99fbf6832f714295baa6d3b5230cfe334982d3 Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:43:41 +0100 Subject: [PATCH 1/8] refactor: create ET endpoints class for shared config --- config/endpoints.yml | 4 +++ .../exact_target_endpoints.rb | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 config/endpoints.yml create mode 100644 lib/marketingcloudsdk/exact_target_endpoints.rb diff --git a/config/endpoints.yml b/config/endpoints.yml new file mode 100644 index 0000000..65e92d7 --- /dev/null +++ b/config/endpoints.yml @@ -0,0 +1,4 @@ +base_api_url: 'https://placeholder.rest.marketingcloudapis.com' +request_token_url: 'https://placeholder.rest.marketingcloudapis.com/v1/requestToken' +soap_wsdl_endpoint: 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl' +soap_service_endpoint: 'https://placeholder.soap.marketingcloudapis.com/Service.asmx' \ No newline at end of file diff --git a/lib/marketingcloudsdk/exact_target_endpoints.rb b/lib/marketingcloudsdk/exact_target_endpoints.rb new file mode 100644 index 0000000..12d4fac --- /dev/null +++ b/lib/marketingcloudsdk/exact_target_endpoints.rb @@ -0,0 +1,25 @@ +module MarketingCloudSDK + class ExactTargetEndpoints + def self.config + YAML.load_file( + File.join('config', 'endpoints.yml') + ) + end + + def self.base_api_url + @base_api_url ||= config['base_api_url'] + end + + def self.request_token_url + @request_token_url ||= config['request_token_url'] + end + + def self.soap_wsdl_endpoint + @soap_wsdl_endpoint ||= config['soap_wsdl_endpoint'] + end + + def self.soap_service_endpoint + @soap_service_endpoint ||= config['soap_service_endpoint'] + end + end +end From d93ff6ea769f065436679e8003919c9b3a47de50 Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:56:35 +0100 Subject: [PATCH 2/8] refactor: use base api url from config --- lib/marketingcloudsdk/client.rb | 5 +++-- lib/new.rb | 10 +++++----- spec/client_spec.rb | 1 + spec/default_values_fallback_spec.rb | 4 ++-- spec/targeting_spec.rb | 5 +++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/marketingcloudsdk/client.rb b/lib/marketingcloudsdk/client.rb index b5c9c7f..7ec5ca3 100644 --- a/lib/marketingcloudsdk/client.rb +++ b/lib/marketingcloudsdk/client.rb @@ -36,6 +36,7 @@ =end require 'securerandom' +require_relative './exact_target_endpoints' module MarketingCloudSDK class Response # not doing accessor so user, can't update these values from response. @@ -103,7 +104,7 @@ def initialize(params={}, debug=false) self.id = client_config["id"] self.secret = client_config["secret"] self.signature = client_config["signature"] - self.base_api_url = !(client_config["base_api_url"].to_s.strip.empty?) ? client_config["base_api_url"] : 'https://www.exacttargetapis.com' + self.base_api_url = !(client_config["base_api_url"].to_s.strip.empty?) ? client_config["base_api_url"] : ExactTargetEndpoints.base_api_url self.request_token_url = client_config["request_token_url"] self.soap_endpoint = client_config["soap_endpoint"] self.use_oAuth2_authentication = client_config["use_oAuth2_authentication"] @@ -116,7 +117,7 @@ def initialize(params={}, debug=false) # Set a default value in case no 'client' params is sent if (!self.base_api_url) - self.base_api_url = 'https://www.exacttargetapis.com' + self.base_api_url = ExactTargetEndpoints.base_api_url end if (self.request_token_url.to_s.strip.empty?) diff --git a/lib/new.rb b/lib/new.rb index 1588f7e..af477fc 100644 --- a/lib/new.rb +++ b/lib/new.rb @@ -43,7 +43,7 @@ require 'json' require 'yaml' require 'jwt' - +require_relative './marketing_cloud_sdk/exact_target_endpoints' def indifferent_access key, hash hash[key.to_sym] || hash[key.to_s] @@ -227,7 +227,7 @@ def refreshToken(force = nil) #If we don't already have a token or the token expires within 5 min(300 seconds), get one if ((@authToken.nil? || Time.new + 300 > @authTokenExpiration) || force) then begin - uri = URI.parse("https://auth.exacttargetapis.com/v1/requestToken?legacy=1") + uri = URI.parse("#{MarketingCloudSDK::ExactTargetEndpoints.base_api_url}/v1/requestToken?legacy=1") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) @@ -318,7 +318,7 @@ def CreateDataExtensions(dataExtensionDefinitions) protected def determineStack() begin - uri = URI.parse("https://www.exacttargetapis.com/platform/v1/endpoints/soap?access_token=" + @authToken) + uri = URI.parse("#{MarketingCloudSDK::ExactTargetEndpoints.base_api_url}/platform/v1/endpoints/soap?access_token=" + @authToken) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true @@ -908,7 +908,7 @@ def initialize(authStub, endpoint) class ET_Campaign < ET_CUDSupportRest def initialize super - @endpoint = 'https://www.exacttargetapis.com/hub/v1/campaigns/{id}' + @endpoint = "#{MarketingCloudSDK::ExactTargetEndpoints.base_api_url}/hub/v1/campaigns/{id}" @urlProps = ["id"] @urlPropsRequired = [] end @@ -916,7 +916,7 @@ def initialize class Asset < ET_CUDSupportRest def initialize super - @endpoint = 'https://www.exacttargetapis.com/hub/v1/campaigns/{id}/assets/{assetId}' + @endpoint = "#{MarketingCloudSDK::ExactTargetEndpoints.base_api_url}/hub/v1/campaigns/{id}/assets/{assetId}" @urlProps = ["id", "assetId"] @urlPropsRequired = ["id"] end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index ab5a11b..51dc083 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper.rb' require 'public_or_web_integration_credentials' +require './lib/marketingcloudsdk/exact_target_endpoints' def get_test_stub {'client' => { diff --git a/spec/default_values_fallback_spec.rb b/spec/default_values_fallback_spec.rb index d35d85b..c449263 100644 --- a/spec/default_values_fallback_spec.rb +++ b/spec/default_values_fallback_spec.rb @@ -8,7 +8,7 @@ 'base_api_url' => ''} it 'Should use REST endpoint default value if base_api_url endpoint is an empty string in config' do - expect(client1.base_api_url).to eq 'https://www.exacttargetapis.com' + expect(client1.base_api_url).to eq 'https://placeholder.rest.marketingcloudapis.com' end it 'Should use Auth endpoint default value if request_token_url attribute is not in config' do @@ -22,7 +22,7 @@ 'base_api_url' => ' '} it 'Should use REST endpoint default value if REST endpoint is a blank string in config' do - expect(client2.base_api_url).to eq 'https://www.exacttargetapis.com' + expect(client2.base_api_url).to eq 'https://placeholder.rest.marketingcloudapis.com' end end diff --git a/spec/targeting_spec.rb b/spec/targeting_spec.rb index 4c5b8f0..e602639 100644 --- a/spec/targeting_spec.rb +++ b/spec/targeting_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require './lib/marketingcloudsdk/exact_target_endpoints' describe MarketingCloudSDK::Targeting do @@ -15,12 +16,12 @@ describe '#get_soap_endpoint' do let(:client) { c = Class.new.new.extend(MarketingCloudSDK::Targeting) - c.stub(:base_api_url).and_return('https://www.exacttargetapis.com') + c.stub(:base_api_url).and_return(MarketingCloudSDK::ExactTargetEndpoints.base_api_url) c.stub(:access_token).and_return('open_sesame') c.stub(:get_soap_endpoint_from_file).and_return(nil) c.stub(:set_soap_endpoint_to_file).and_return(nil) c.stub(:get) - .with('https://www.exacttargetapis.com/platform/v1/endpoints/soap',{'access_token'=>'open_sesame'}) + .with("#{MarketingCloudSDK::ExactTargetEndpoints.base_api_url}/platform/v1/endpoints/soap",{'access_token'=>'open_sesame'}) .and_return({'url' => 'S#.authentication.target'}) c } From 2d18f7ebe70fda5a5724cd24bf72d21c6418fc58 Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:58:18 +0100 Subject: [PATCH 3/8] refactor: use request token URL from shared config --- lib/marketingcloudsdk/client.rb | 2 +- spec/default_values_fallback_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/marketingcloudsdk/client.rb b/lib/marketingcloudsdk/client.rb index 7ec5ca3..c3ba1e2 100644 --- a/lib/marketingcloudsdk/client.rb +++ b/lib/marketingcloudsdk/client.rb @@ -124,7 +124,7 @@ def initialize(params={}, debug=false) if(use_oAuth2_authentication == true) raise 'request_token_url (Auth TSE) is mandatory when using OAuth2 authentication' else - self.request_token_url = 'https://auth.exacttargetapis.com/v1/requestToken' + self.request_token_url = ExactTargetEndpoints.request_token_url end end diff --git a/spec/default_values_fallback_spec.rb b/spec/default_values_fallback_spec.rb index c449263..1d15a3a 100644 --- a/spec/default_values_fallback_spec.rb +++ b/spec/default_values_fallback_spec.rb @@ -12,7 +12,7 @@ end it 'Should use Auth endpoint default value if request_token_url attribute is not in config' do - expect(client1.request_token_url).to eq 'https://auth.exacttargetapis.com/v1/requestToken' + expect(client1.request_token_url).to eq 'https://placeholder.rest.marketingcloudapis.com/v1/requestToken' end end From 9e2f2c1a39cd0d9f27822257c7de1f104471720f Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:04:32 +0100 Subject: [PATCH 4/8] refactor: use soap wsdl endpoint from shared config --- lib/marketingcloudsdk/soap.rb | 3 ++- spec/client_spec.rb | 4 ++-- spec/soap_spec.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/marketingcloudsdk/soap.rb b/lib/marketingcloudsdk/soap.rb index 19d2bb3..e8f0664 100644 --- a/lib/marketingcloudsdk/soap.rb +++ b/lib/marketingcloudsdk/soap.rb @@ -115,6 +115,7 @@ def unpack_rslts raw end end + require_relative './exact_target_endpoints' module Soap attr_accessor :wsdl, :debug#, :internal_token @@ -140,7 +141,7 @@ def debug end def wsdl - @wsdl ||= 'https://webservice.exacttarget.com/etframework.wsdl' + @wsdl ||= ExactTargetEndpoints.soap_wsdl_endpoint end def soap_client diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 51dc083..2e4dc88 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -78,7 +78,7 @@ def get_test_stub it 'with wsdl set to default value if not set in params' do client = MarketingCloudSDK::Client.new(get_test_stub) - expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl' + expect(client.wsdl).to eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl'' end it 'with application_type set to \'server\' if application_type is not set in params' do @@ -169,7 +169,7 @@ def get_test_stub end it'#wsdl returns default wsdl' do - expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl' + expect(client.wsdl).to eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl'' end end end diff --git a/spec/soap_spec.rb b/spec/soap_spec.rb index 4f224c3..5780f29 100644 --- a/spec/soap_spec.rb +++ b/spec/soap_spec.rb @@ -30,7 +30,7 @@ it { should respond_to(:package_folders=) } its(:debug) { should be false } - its(:wsdl) { should eq 'https://webservice.exacttarget.com/etframework.wsdl' } + its(:wsdl) { should eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl' } describe '#header' do it 'raises an exception when internal_token is missing' do From e8e93f97afcd35a611a6ff3c8507ff37ba43929d Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:10:22 +0100 Subject: [PATCH 5/8] refactor: use soap service endpoint from config --- lib/marketingcloudsdk/targeting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/marketingcloudsdk/targeting.rb b/lib/marketingcloudsdk/targeting.rb index 2eaa4d3..81d64ee 100644 --- a/lib/marketingcloudsdk/targeting.rb +++ b/lib/marketingcloudsdk/targeting.rb @@ -94,6 +94,6 @@ def get_soap_endpoint @endpoint = response['url'] set_soap_endpoint_to_file @endpoint rescue => e - @endpoint = 'https://webservice.exacttarget.com/Service.asmx' + @endpoint = ExactTargetEndpoints.soap_service_endpoint end end From 96e98fab794950f4bfe1d3b2ec6db3ff3277523a Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:12:38 +0100 Subject: [PATCH 6/8] Bump version from 1.3.1 to 2.0.0 - major version since APIs 1.3.1 used will be deprecated --- Gemfile.lock | 2 +- lib/marketingcloudsdk/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 13acc58..23acdb9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sfmc-fuelsdk-ruby (1.3.1) + sfmc-fuelsdk-ruby (2.0.0) json (>= 2.2.0) jwt (>= 2.1.0) savon (>= 2.12.1) diff --git a/lib/marketingcloudsdk/version.rb b/lib/marketingcloudsdk/version.rb index 526eca4..af42573 100644 --- a/lib/marketingcloudsdk/version.rb +++ b/lib/marketingcloudsdk/version.rb @@ -35,5 +35,5 @@ =end module MarketingCloudSDK - VERSION = "1.3.1" + VERSION = "2.0.0" end From 4c26ffdc4b35b36ffd03338119da4e8987fc2918 Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:19:08 +0100 Subject: [PATCH 7/8] docs: add instructions on how to use tenant-specific endpoints --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1d255c0..fda11e9 100755 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ ExactTarget Fuel SDK / SalesforceMarektingCloudSDK for Ruby ## Overview ## The Fuel SDK for Ruby provides easy access to ExactTarget's Fuel API Family services, including a collection of REST APIs and a SOAP API. These APIs provide access to ExactTarget functionality via common collection types such as array/hash. +## New Features in Version 2.0.0 ## + +- @JadeDickinson added support for tenant-specific endpoints. + - To use this feature, copy config/endpoints.yml from this Gem to ./config/endpoints.yml in your application using FuelSDK-Ruby. + - You must then replace the placeholder values with your tenant-specific endpoints - see the following links for more details: + - [SOAP API](https://help.salesforce.com/s/articleView?id=000356497&type=1) + - [REST API](https://help.salesforce.com/s/articleView?id=000356498&type=1) + ## New Features in Version 1.3.1 ## - **Updated below packages to latest version** - savon: ">= 2.12.1" From c52d673f877a636c58f758d561ac9717c30821ca Mon Sep 17 00:00:00 2001 From: Jade Dickinson <14929975+JadeDickinson@users.noreply.github.com> Date: Mon, 18 Jul 2022 16:20:37 +0100 Subject: [PATCH 8/8] fix: remove stray apostrophes --- spec/client_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 2e4dc88..814538d 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -78,7 +78,7 @@ def get_test_stub it 'with wsdl set to default value if not set in params' do client = MarketingCloudSDK::Client.new(get_test_stub) - expect(client.wsdl).to eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl'' + expect(client.wsdl).to eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl' end it 'with application_type set to \'server\' if application_type is not set in params' do @@ -169,7 +169,7 @@ def get_test_stub end it'#wsdl returns default wsdl' do - expect(client.wsdl).to eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl'' + expect(client.wsdl).to eq 'https://placeholder.soap.marketingcloudapis.com/etframework.wsdl' end end end