diff --git a/FuelSDK-CSharp/ETClient.cs b/FuelSDK-CSharp/ETClient.cs index ff4d5d7..c831245 100644 --- a/FuelSDK-CSharp/ETClient.cs +++ b/FuelSDK-CSharp/ETClient.cs @@ -20,7 +20,7 @@ namespace FuelSDK /// public class ETClient { - public const string SDKVersion = "FuelSDK-C#-v1.1.0"; + public const string SDKVersion = "FuelSDK-C#-v1.1.1"; private FuelSDKConfigurationSection configSection; public string AuthToken { get; private set; } @@ -31,13 +31,30 @@ public class ETClient public JObject Jwt { get; private set; } public string EnterpriseId { get; private set; } public string OrganizationId { get; private set; } - public string Stack { get; private set; } + private string stackKey; + [Obsolete(StackKeyErrorMessage)] + public string Stack + { + get { + if (stackKey != null) + return stackKey; + + stackKey = GetStackFromSoapEndPoint(new Uri(configSection.SoapEndPoint)); + return stackKey; + } + private set + { + stackKey = value; + } + } private static DateTime soapEndPointExpiration; private static DateTime stackKeyExpiration; private static string fetchedSoapEndpoint; private const long cacheDurationInMinutes = 10; + private const string StackKeyErrorMessage = "Tenant specific endpoints doesn't support Stack Key property and this will property will be deprecated in next major release"; + public class RefreshState { public string RefreshKey { get; set; } @@ -143,7 +160,6 @@ public ETClient(NameValueCollection parameters = null, RefreshState refreshState { EnterpriseId = results[0].Client.EnterpriseID.ToString(); OrganizationId = results[0].ID.ToString(); - Stack = StackKey.Instance.Get(long.Parse(EnterpriseId), this); } } } @@ -193,6 +209,14 @@ private string DecodeJWT(string jwt, string key) return json; } + private string GetStackFromSoapEndPoint(Uri uri) + { + var parts = uri.Host.Split('.'); + if (parts.Length < 2 || !parts[0].Equals("webservice", StringComparison.OrdinalIgnoreCase)) + throw new Exception(StackKeyErrorMessage); + return (parts[1] == "exacttarget" ? "s1" : parts[1].ToLower()); + } + private static Binding GetSoapBinding() { return new CustomBinding(new BindingElementCollection diff --git a/FuelSDK-Test/ETClientTest.cs b/FuelSDK-Test/ETClientTest.cs index 9703d94..9b218c4 100644 --- a/FuelSDK-Test/ETClientTest.cs +++ b/FuelSDK-Test/ETClientTest.cs @@ -17,14 +17,6 @@ public void Setup() client2 = new ETClient(); } - [Test()] - public void GetClientStack() - { - Assert.IsNotNull(client1.Stack); - Assert.IsNotNull(client2.Stack); - Assert.AreEqual(client1.Stack, client2.Stack); - } - [Test()] public void TestSoapEndpointCaching() { diff --git a/FuelSDK-Test/StackKeyTest.cs b/FuelSDK-Test/StackKeyTest.cs index c39aa40..5658140 100644 --- a/FuelSDK-Test/StackKeyTest.cs +++ b/FuelSDK-Test/StackKeyTest.cs @@ -1,19 +1,35 @@ using NUnit.Framework; +using System; +using System.Linq; namespace FuelSDK.Test { [TestFixture] public class StackKeyTest { + private const string StackKeyErrorMessage = "Tenant specific endpoints doesn't support Stack Key property and this will property will be deprecated in next major release"; + + [Test] + public void ExceptionOccursIfTSEFormatIsUsedForSoapEndpoint() + { + var client = new ETClient(); + + var exception = Assert.Throws( + () => { var stack = client.Stack; } + ); + + Assert.That(exception.Message, Is.EqualTo(StackKeyErrorMessage)); + } + [Test] - public void MultipleETClientInstancesForTheSameClientIdAndSecretWillHaveTheSameStackKey() + public void StackPropertyIsMarkedAsObsolete() { - ETClient client1 = new ETClient(); - ETClient client2 = new ETClient(); + var type = typeof(ETClient); + var obsoleteAttributes = (ObsoleteAttribute[])type.GetProperty("Stack").GetCustomAttributes(typeof(ObsoleteAttribute), false); - Assert.IsNotNull(client1.Stack); - Assert.IsNotNull(client2.Stack); - Assert.AreEqual(client1.Stack, client2.Stack); + Assert.AreEqual(1, obsoleteAttributes.Length); + Assert.AreEqual(StackKeyErrorMessage, obsoleteAttributes[0].Message); + Assert.AreEqual(false, obsoleteAttributes[0].IsError); } } } diff --git a/README.md b/README.md index b7c0729..d7328bd 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ Salesforce Marketing Cloud Fuel SDK for C# ## Overview ## The Fuel SDK for C# provides easy access to Salesforce Marketing Cloud's Fuel API Family services, including a collection of REST APIs and a SOAP API. These APIs provide access to Salesforce Marketing Cloud functionality via common collection types. +## Latest Version 1.1.1 ## +* Bug fixes + ## New Features in Version 1.1.0 ## * **Added support for your tenant's endpoints - [More Details](https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/your-subdomain-tenant-specific-endpoints.htm) :** The user of the SDK can now configure them through a **App.config** file OR using the “**parameters**” **ETClient** constructor parameter as in the previous version of the SDK. The user of the SDK has to make a copy of the **App.config.transform** file which is found in the **FuelSDK-CSharp** folder, place it in the same folder and rename it to **App.config**. The structure of this file will be the following: diff --git a/nuspecs/FuelSDK-CSharp.nuspec b/nuspecs/FuelSDK-CSharp.nuspec index d56de88..d781539 100644 --- a/nuspecs/FuelSDK-CSharp.nuspec +++ b/nuspecs/FuelSDK-CSharp.nuspec @@ -2,7 +2,7 @@ SFMC.FuelSDK - 1.1.0 + 1.1.1 FuelSDK-CSharp Salesforce Salesforce