From e58789727116402b8539bc9de070d643caada9bc Mon Sep 17 00:00:00 2001 From: Chris Nevett <chris.nevett@myunidays.com> Date: Thu, 9 Aug 2018 18:24:33 +0100 Subject: [PATCH 1/2] Adds IOptimizely interface --- .../OptimizelySDK.Net35.csproj | 3 + .../OptimizelySDK.Net40.csproj | 3 + .../OptimizelySDK.NetStandard16.csproj | 1 + OptimizelySDK/IOptimizely.cs | 140 ++++++++++++++++++ OptimizelySDK/Optimizely.cs | 6 +- OptimizelySDK/OptimizelySDK.csproj | 1 + 6 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 OptimizelySDK/IOptimizely.cs diff --git a/OptimizelySDK.Net35/OptimizelySDK.Net35.csproj b/OptimizelySDK.Net35/OptimizelySDK.Net35.csproj index c89f5c86..93b868c7 100644 --- a/OptimizelySDK.Net35/OptimizelySDK.Net35.csproj +++ b/OptimizelySDK.Net35/OptimizelySDK.Net35.csproj @@ -115,6 +115,9 @@ <Compile Include="..\OptimizelySDK\Exceptions\OptimizelyException.cs"> <Link>Exceptions\OptimizelyException.cs</Link> </Compile> + <Compile Include="..\OptimizelySDK\IOptimizely.cs"> + <Link>IOptimizely.cs</Link> + </Compile> <Compile Include="..\OptimizelySDK\Logger\DefaultLogger.cs"> <Link>Logger\DefaultLogger.cs</Link> </Compile> diff --git a/OptimizelySDK.Net40/OptimizelySDK.Net40.csproj b/OptimizelySDK.Net40/OptimizelySDK.Net40.csproj index 20daf229..b8c5cf5c 100644 --- a/OptimizelySDK.Net40/OptimizelySDK.Net40.csproj +++ b/OptimizelySDK.Net40/OptimizelySDK.Net40.csproj @@ -116,6 +116,9 @@ <Compile Include="..\OptimizelySDK\Exceptions\OptimizelyException.cs"> <Link>Exceptions\OptimizelyException.cs</Link> </Compile> + <Compile Include="..\OptimizelySDK\IOptimizely.cs"> + <Link>IOptimizely.cs</Link> + </Compile> <Compile Include="..\OptimizelySDK\Logger\DefaultLogger.cs"> <Link>Logger\DefaultLogger.cs</Link> </Compile> diff --git a/OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj b/OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj index 134e5ede..1364493c 100644 --- a/OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj +++ b/OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj @@ -37,6 +37,7 @@ <Compile Include="..\OptimizelySDK\Event\Dispatcher\IEventDispatcher.cs" /> <Compile Include="..\OptimizelySDK\Event\LogEvent.cs" /> <Compile Include="..\OptimizelySDK\Exceptions\OptimizelyException.cs" /> + <Compile Include="..\OptimizelySDK\IOptimizely.cs" /> <Compile Include="..\OptimizelySDK\Logger\DefaultLogger.cs" /> <Compile Include="..\OptimizelySDK\Logger\ILogger.cs" /> <Compile Include="..\OptimizelySDK\Logger\NoOpLogger.cs" /> diff --git a/OptimizelySDK/IOptimizely.cs b/OptimizelySDK/IOptimizely.cs new file mode 100644 index 00000000..aaad59f8 --- /dev/null +++ b/OptimizelySDK/IOptimizely.cs @@ -0,0 +1,140 @@ +/** + * Copyright 2018, Optimizely, Inc. and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using OptimizelySDK.Entity; +using System.Collections.Generic; + +namespace OptimizelySDK +{ + public interface IOptimizely + { + bool IsValid { get; } + + /// <summary> + /// Buckets visitor and sends impression event to Optimizely. + /// </summary> + /// <param name="experimentKey">experimentKey string Key identifying the experiment</param> + /// <param name="userId">string ID for user</param> + /// <param name="userAttributes">associative array of Attributes for the user</param> + /// <returns>null|Variation Representing variation</returns> + Variation Activate(string experimentKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Sends conversion event to Optimizely. + /// </summary> + /// <param name="eventKey">Event key representing the event which needs to be recorded</param> + /// <param name="userId">ID for user</param> + /// <param name="userAttributes">Attributes of the user</param> + /// <param name="eventTags">eventTags array Hash representing metadata associated with the event.</param> + void Track(string eventKey, string userId, UserAttributes userAttributes = null, EventTags eventTags = null); + + /// <summary> + /// Get variation where user will be bucketed + /// </summary> + /// <param name="experimentKey">experimentKey string Key identifying the experiment</param> + /// <param name="userId">ID for the user</param> + /// <param name="userAttributes">Attributes for the users</param> + /// <returns>null|Variation Representing variation</returns> + Variation GetVariation(string experimentKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Force a user into a variation for a given experiment. + /// </summary> + /// <param name="experimentKey">The experiment key</param> + /// <param name="userId">The user ID</param> + /// <param name="variationKey">The variation key specifies the variation which the user will be forced into. + /// If null, then clear the existing experiment-to-variation mapping.</param> + /// <returns>A boolean value that indicates if the set completed successfully.</returns> + bool SetForcedVariation(string experimentKey, string userId, string variationKey); + + /// <summary> + /// Gets the forced variation key for the given user and experiment. + /// </summary> + /// <param name="experimentKey">The experiment key</param> + /// <param name="userId">The user ID</param> + /// <returns>null|string The variation key.</returns> + Variation GetForcedVariation(string experimentKey, string userId); + + /// <summary> + /// Determine whether a feature is enabled. + /// Send an impression event if the user is bucketed into an experiment using the feature. + /// </summary> + /// <param name="featureKey">The experiment key</param> + /// <param name="userId">The user ID</param> + /// <param name="userAttributes">The user's attributes.</param> + /// <returns>True if feature is enabled, false or null otherwise</returns> + bool IsFeatureEnabled(string featureKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Gets the feature variable value for given type. + /// </summary> + /// <param name="featureKey">The feature flag key</param> + /// <param name="variableKey">The variable key</param> + /// <param name="userId">The user ID</param> + /// <param name="userAttributes">The user's attributes</param> + /// <param name="variableType">Variable type</param> + /// <returns>string | null Feature variable value</returns> + string GetFeatureVariableValueForType(string featureKey, string variableKey, string userId, + UserAttributes userAttributes, FeatureVariable.VariableType variableType); + + /// <summary> + /// Gets boolean feature variable value. + /// </summary> + /// <param name="featureKey">The feature flag key</param> + /// <param name="variableKey">The variable key</param> + /// <param name="userId">The user ID</param> + /// <param name="userAttributes">The user's attributes</param> + /// <returns>bool | Feature variable value or null</returns> + bool? GetFeatureVariableBoolean(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Gets double feature variable value. + /// </summary> + /// <param name="featureKey">The feature flag key</param> + /// <param name="variableKey">The variable key</param> + /// <param name="userId">The user ID</param> + /// <param name="userAttributes">The user's attributes</param> + /// <returns>double | Feature variable value or null</returns> + double? GetFeatureVariableDouble(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Gets integer feature variable value. + /// </summary> + /// <param name="featureKey">The feature flag key</param> + /// <param name="variableKey">The variable key</param> + /// <param name="userId">The user ID</param> + /// <param name="userAttributes">The user's attributes</param> + /// <returns>int | Feature variable value or null</returns> + int? GetFeatureVariableInteger(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Gets string feature variable value. + /// </summary> + /// <param name="featureKey">The feature flag key</param> + /// <param name="variableKey">The variable key</param> + /// <param name="userId">The user ID</param> + /// <param name="userAttributes">The user's attributes</param> + /// <returns>string | Feature variable value or null</returns> + string GetFeatureVariableString(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null); + + /// <summary> + /// Get the list of features that are enabled for the user. + /// </summary> + /// <param name="userId">The user Id</param> + /// <param name="userAttributes">The user's attributes</param> + /// <returns>List of the feature keys that are enabled for the user.</returns> + List<string> GetEnabledFeatures(string userId, UserAttributes userAttributes = null); + } +} diff --git a/OptimizelySDK/Optimizely.cs b/OptimizelySDK/Optimizely.cs index 06d59d37..cd05a3ca 100644 --- a/OptimizelySDK/Optimizely.cs +++ b/OptimizelySDK/Optimizely.cs @@ -27,7 +27,7 @@ namespace OptimizelySDK { - public class Optimizely + public class Optimizely : IOptimizely { private Bucketer Bucketer; @@ -152,7 +152,7 @@ private bool ValidatePreconditions(Experiment experiment, string userId, UserAtt /// </summary> /// <param name="experimentKey">experimentKey string Key identifying the experiment</param> /// <param name="userId">string ID for user</param> - /// <param name="attributes">associative array of Attributes for the user</param> + /// <param name="userAttributes">associative array of Attributes for the user</param> /// <returns>null|Variation Representing variation</returns> public Variation Activate(string experimentKey, string userId, UserAttributes userAttributes = null) { @@ -360,7 +360,7 @@ public Variation GetForcedVariation(string experimentKey, string userId) /// Determine whether a feature is enabled. /// Send an impression event if the user is bucketed into an experiment using the feature. /// </summary> - /// <param name="experimentKey">The experiment key</param> + /// <param name="featureKey">The experiment key</param> /// <param name="userId">The user ID</param> /// <param name="userAttributes">The user's attributes.</param> /// <returns>True if feature is enabled, false or null otherwise</returns> diff --git a/OptimizelySDK/OptimizelySDK.csproj b/OptimizelySDK/OptimizelySDK.csproj index b021922d..887d8537 100644 --- a/OptimizelySDK/OptimizelySDK.csproj +++ b/OptimizelySDK/OptimizelySDK.csproj @@ -92,6 +92,7 @@ <Compile Include="Event\Dispatcher\IEventDispatcher.cs" /> <Compile Include="Event\LogEvent.cs" /> <Compile Include="Exceptions\OptimizelyException.cs" /> + <Compile Include="IOptimizely.cs" /> <Compile Include="Logger\DefaultLogger.cs" /> <Compile Include="Logger\ILogger.cs" /> <Compile Include="Logger\NoOpLogger.cs" /> From 49cb7d148a13c85d8972f117f6554f3fe316609e Mon Sep 17 00:00:00 2001 From: Chris Nevett <chris.nevett@myunidays.com> Date: Mon, 20 Aug 2018 12:20:38 +0100 Subject: [PATCH 2/2] Improves xmldocs and removes an interface method --- OptimizelySDK/IOptimizely.cs | 21 ++++++++------------- OptimizelySDK/Optimizely.cs | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/OptimizelySDK/IOptimizely.cs b/OptimizelySDK/IOptimizely.cs index aaad59f8..edd25e8a 100644 --- a/OptimizelySDK/IOptimizely.cs +++ b/OptimizelySDK/IOptimizely.cs @@ -20,6 +20,9 @@ namespace OptimizelySDK { public interface IOptimizely { + /// <summary> + /// Returns true if the IOptimizely instance was initialized with a valid datafile + /// </summary> bool IsValid { get; } /// <summary> @@ -67,28 +70,18 @@ public interface IOptimizely /// <returns>null|string The variation key.</returns> Variation GetForcedVariation(string experimentKey, string userId); + #region FeatureFlag APIs + /// <summary> /// Determine whether a feature is enabled. /// Send an impression event if the user is bucketed into an experiment using the feature. /// </summary> - /// <param name="featureKey">The experiment key</param> + /// <param name="featureKey">The feature key</param> /// <param name="userId">The user ID</param> /// <param name="userAttributes">The user's attributes.</param> /// <returns>True if feature is enabled, false or null otherwise</returns> bool IsFeatureEnabled(string featureKey, string userId, UserAttributes userAttributes = null); - /// <summary> - /// Gets the feature variable value for given type. - /// </summary> - /// <param name="featureKey">The feature flag key</param> - /// <param name="variableKey">The variable key</param> - /// <param name="userId">The user ID</param> - /// <param name="userAttributes">The user's attributes</param> - /// <param name="variableType">Variable type</param> - /// <returns>string | null Feature variable value</returns> - string GetFeatureVariableValueForType(string featureKey, string variableKey, string userId, - UserAttributes userAttributes, FeatureVariable.VariableType variableType); - /// <summary> /// Gets boolean feature variable value. /// </summary> @@ -136,5 +129,7 @@ string GetFeatureVariableValueForType(string featureKey, string variableKey, str /// <param name="userAttributes">The user's attributes</param> /// <returns>List of the feature keys that are enabled for the user.</returns> List<string> GetEnabledFeatures(string userId, UserAttributes userAttributes = null); + + #endregion } } diff --git a/OptimizelySDK/Optimizely.cs b/OptimizelySDK/Optimizely.cs index cd05a3ca..62df0dd3 100644 --- a/OptimizelySDK/Optimizely.cs +++ b/OptimizelySDK/Optimizely.cs @@ -360,7 +360,7 @@ public Variation GetForcedVariation(string experimentKey, string userId) /// Determine whether a feature is enabled. /// Send an impression event if the user is bucketed into an experiment using the feature. /// </summary> - /// <param name="featureKey">The experiment key</param> + /// <param name="featureKey">The feature key</param> /// <param name="userId">The user ID</param> /// <param name="userAttributes">The user's attributes.</param> /// <returns>True if feature is enabled, false or null otherwise</returns>