Skip to content

Adds IOptimizely interface #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions OptimizelySDK.Net35/OptimizelySDK.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 3 additions & 0 deletions OptimizelySDK.Net40/OptimizelySDK.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
135 changes: 135 additions & 0 deletions OptimizelySDK/IOptimizely.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* 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
{
/// <summary>
/// Returns true if the IOptimizely instance was initialized with a valid datafile
/// </summary>
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);

#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 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 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);

#endregion
}
}
6 changes: 3 additions & 3 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace OptimizelySDK
{
public class Optimizely
public class Optimizely : IOptimizely
{
private Bucketer Bucketer;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 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>
Expand Down
1 change: 1 addition & 0 deletions OptimizelySDK/OptimizelySDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down