Skip to content

Commit 32c0dca

Browse files
Nevettmikeproeng37
authored andcommitted
refactor(interface): Adds IOptimizely interface (#93)
1 parent 4c51bde commit 32c0dca

File tree

6 files changed

+146
-3
lines changed

6 files changed

+146
-3
lines changed

OptimizelySDK.Net35/OptimizelySDK.Net35.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
<Compile Include="..\OptimizelySDK\Exceptions\OptimizelyException.cs">
116116
<Link>Exceptions\OptimizelyException.cs</Link>
117117
</Compile>
118+
<Compile Include="..\OptimizelySDK\IOptimizely.cs">
119+
<Link>IOptimizely.cs</Link>
120+
</Compile>
118121
<Compile Include="..\OptimizelySDK\Logger\DefaultLogger.cs">
119122
<Link>Logger\DefaultLogger.cs</Link>
120123
</Compile>

OptimizelySDK.Net40/OptimizelySDK.Net40.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
<Compile Include="..\OptimizelySDK\Exceptions\OptimizelyException.cs">
117117
<Link>Exceptions\OptimizelyException.cs</Link>
118118
</Compile>
119+
<Compile Include="..\OptimizelySDK\IOptimizely.cs">
120+
<Link>IOptimizely.cs</Link>
121+
</Compile>
119122
<Compile Include="..\OptimizelySDK\Logger\DefaultLogger.cs">
120123
<Link>Logger\DefaultLogger.cs</Link>
121124
</Compile>

OptimizelySDK.NetStandard16/OptimizelySDK.NetStandard16.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<Compile Include="..\OptimizelySDK\Event\Dispatcher\IEventDispatcher.cs" />
3838
<Compile Include="..\OptimizelySDK\Event\LogEvent.cs" />
3939
<Compile Include="..\OptimizelySDK\Exceptions\OptimizelyException.cs" />
40+
<Compile Include="..\OptimizelySDK\IOptimizely.cs" />
4041
<Compile Include="..\OptimizelySDK\Logger\DefaultLogger.cs" />
4142
<Compile Include="..\OptimizelySDK\Logger\ILogger.cs" />
4243
<Compile Include="..\OptimizelySDK\Logger\NoOpLogger.cs" />

OptimizelySDK/IOptimizely.cs

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
* Copyright 2018, Optimizely, Inc. and contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
using OptimizelySDK.Entity;
17+
using System.Collections.Generic;
18+
19+
namespace OptimizelySDK
20+
{
21+
public interface IOptimizely
22+
{
23+
/// <summary>
24+
/// Returns true if the IOptimizely instance was initialized with a valid datafile
25+
/// </summary>
26+
bool IsValid { get; }
27+
28+
/// <summary>
29+
/// Buckets visitor and sends impression event to Optimizely.
30+
/// </summary>
31+
/// <param name="experimentKey">experimentKey string Key identifying the experiment</param>
32+
/// <param name="userId">string ID for user</param>
33+
/// <param name="userAttributes">associative array of Attributes for the user</param>
34+
/// <returns>null|Variation Representing variation</returns>
35+
Variation Activate(string experimentKey, string userId, UserAttributes userAttributes = null);
36+
37+
/// <summary>
38+
/// Sends conversion event to Optimizely.
39+
/// </summary>
40+
/// <param name="eventKey">Event key representing the event which needs to be recorded</param>
41+
/// <param name="userId">ID for user</param>
42+
/// <param name="userAttributes">Attributes of the user</param>
43+
/// <param name="eventTags">eventTags array Hash representing metadata associated with the event.</param>
44+
void Track(string eventKey, string userId, UserAttributes userAttributes = null, EventTags eventTags = null);
45+
46+
/// <summary>
47+
/// Get variation where user will be bucketed
48+
/// </summary>
49+
/// <param name="experimentKey">experimentKey string Key identifying the experiment</param>
50+
/// <param name="userId">ID for the user</param>
51+
/// <param name="userAttributes">Attributes for the users</param>
52+
/// <returns>null|Variation Representing variation</returns>
53+
Variation GetVariation(string experimentKey, string userId, UserAttributes userAttributes = null);
54+
55+
/// <summary>
56+
/// Force a user into a variation for a given experiment.
57+
/// </summary>
58+
/// <param name="experimentKey">The experiment key</param>
59+
/// <param name="userId">The user ID</param>
60+
/// <param name="variationKey">The variation key specifies the variation which the user will be forced into.
61+
/// If null, then clear the existing experiment-to-variation mapping.</param>
62+
/// <returns>A boolean value that indicates if the set completed successfully.</returns>
63+
bool SetForcedVariation(string experimentKey, string userId, string variationKey);
64+
65+
/// <summary>
66+
/// Gets the forced variation key for the given user and experiment.
67+
/// </summary>
68+
/// <param name="experimentKey">The experiment key</param>
69+
/// <param name="userId">The user ID</param>
70+
/// <returns>null|string The variation key.</returns>
71+
Variation GetForcedVariation(string experimentKey, string userId);
72+
73+
#region FeatureFlag APIs
74+
75+
/// <summary>
76+
/// Determine whether a feature is enabled.
77+
/// Send an impression event if the user is bucketed into an experiment using the feature.
78+
/// </summary>
79+
/// <param name="featureKey">The feature key</param>
80+
/// <param name="userId">The user ID</param>
81+
/// <param name="userAttributes">The user's attributes.</param>
82+
/// <returns>True if feature is enabled, false or null otherwise</returns>
83+
bool IsFeatureEnabled(string featureKey, string userId, UserAttributes userAttributes = null);
84+
85+
/// <summary>
86+
/// Gets boolean feature variable value.
87+
/// </summary>
88+
/// <param name="featureKey">The feature flag key</param>
89+
/// <param name="variableKey">The variable key</param>
90+
/// <param name="userId">The user ID</param>
91+
/// <param name="userAttributes">The user's attributes</param>
92+
/// <returns>bool | Feature variable value or null</returns>
93+
bool? GetFeatureVariableBoolean(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null);
94+
95+
/// <summary>
96+
/// Gets double feature variable value.
97+
/// </summary>
98+
/// <param name="featureKey">The feature flag key</param>
99+
/// <param name="variableKey">The variable key</param>
100+
/// <param name="userId">The user ID</param>
101+
/// <param name="userAttributes">The user's attributes</param>
102+
/// <returns>double | Feature variable value or null</returns>
103+
double? GetFeatureVariableDouble(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null);
104+
105+
/// <summary>
106+
/// Gets integer feature variable value.
107+
/// </summary>
108+
/// <param name="featureKey">The feature flag key</param>
109+
/// <param name="variableKey">The variable key</param>
110+
/// <param name="userId">The user ID</param>
111+
/// <param name="userAttributes">The user's attributes</param>
112+
/// <returns>int | Feature variable value or null</returns>
113+
int? GetFeatureVariableInteger(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null);
114+
115+
/// <summary>
116+
/// Gets string feature variable value.
117+
/// </summary>
118+
/// <param name="featureKey">The feature flag key</param>
119+
/// <param name="variableKey">The variable key</param>
120+
/// <param name="userId">The user ID</param>
121+
/// <param name="userAttributes">The user's attributes</param>
122+
/// <returns>string | Feature variable value or null</returns>
123+
string GetFeatureVariableString(string featureKey, string variableKey, string userId, UserAttributes userAttributes = null);
124+
125+
/// <summary>
126+
/// Get the list of features that are enabled for the user.
127+
/// </summary>
128+
/// <param name="userId">The user Id</param>
129+
/// <param name="userAttributes">The user's attributes</param>
130+
/// <returns>List of the feature keys that are enabled for the user.</returns>
131+
List<string> GetEnabledFeatures(string userId, UserAttributes userAttributes = null);
132+
133+
#endregion
134+
}
135+
}

OptimizelySDK/Optimizely.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace OptimizelySDK
2929
{
30-
public class Optimizely
30+
public class Optimizely : IOptimizely
3131
{
3232
private Bucketer Bucketer;
3333

@@ -152,7 +152,7 @@ private bool ValidatePreconditions(Experiment experiment, string userId, UserAtt
152152
/// </summary>
153153
/// <param name="experimentKey">experimentKey string Key identifying the experiment</param>
154154
/// <param name="userId">string ID for user</param>
155-
/// <param name="attributes">associative array of Attributes for the user</param>
155+
/// <param name="userAttributes">associative array of Attributes for the user</param>
156156
/// <returns>null|Variation Representing variation</returns>
157157
public Variation Activate(string experimentKey, string userId, UserAttributes userAttributes = null)
158158
{
@@ -360,7 +360,7 @@ public Variation GetForcedVariation(string experimentKey, string userId)
360360
/// Determine whether a feature is enabled.
361361
/// Send an impression event if the user is bucketed into an experiment using the feature.
362362
/// </summary>
363-
/// <param name="experimentKey">The experiment key</param>
363+
/// <param name="featureKey">The feature key</param>
364364
/// <param name="userId">The user ID</param>
365365
/// <param name="userAttributes">The user's attributes.</param>
366366
/// <returns>True if feature is enabled, false or null otherwise</returns>

OptimizelySDK/OptimizelySDK.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="Event\Dispatcher\IEventDispatcher.cs" />
9393
<Compile Include="Event\LogEvent.cs" />
9494
<Compile Include="Exceptions\OptimizelyException.cs" />
95+
<Compile Include="IOptimizely.cs" />
9596
<Compile Include="Logger\DefaultLogger.cs" />
9697
<Compile Include="Logger\ILogger.cs" />
9798
<Compile Include="Logger\NoOpLogger.cs" />

0 commit comments

Comments
 (0)