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/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" 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/client.rb b/lib/marketingcloudsdk/client.rb index b5c9c7f..c3ba1e2 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,14 +117,14 @@ 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?) 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/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 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/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 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 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..814538d 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' => { @@ -77,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 @@ -168,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/default_values_fallback_spec.rb b/spec/default_values_fallback_spec.rb index d35d85b..1d15a3a 100644 --- a/spec/default_values_fallback_spec.rb +++ b/spec/default_values_fallback_spec.rb @@ -8,11 +8,11 @@ '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 - 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 @@ -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/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 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 }