Skip to content

Commit 18bc2f0

Browse files
authored
Feat: added SDKkey and environment key in project config (#265)
1 parent 25ad73c commit 18bc2f0

File tree

9 files changed

+63
-13
lines changed

9 files changed

+63
-13
lines changed

OptimizelySDK.Tests/OptimizelyConfigTests/OptimizelyConfigTest.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020, Optimizely
2+
* Copyright 2020-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -326,7 +326,7 @@ public void TestGetOptimizelyConfigService()
326326
};
327327

328328
OptimizelyConfig optimizelyConfig = new OptimizelyConfigService(datafileProjectConfig).GetOptimizelyConfig();
329-
OptimizelyConfig expectedOptimizelyConfig = new OptimizelyConfig(datafileProjectConfig.Revision, experimentsMap, featuresMap);
329+
OptimizelyConfig expectedOptimizelyConfig = new OptimizelyConfig(datafileProjectConfig.Revision, datafileProjectConfig.SDKKey, datafileProjectConfig.EnvironmentKey, experimentsMap, featuresMap);
330330
Assert.IsTrue(TestData.CompareObjects(optimizelyConfig, expectedOptimizelyConfig));
331331
}
332332

@@ -338,10 +338,14 @@ public void TestGetOptimizelyConfigService()
338338
public void TestOptimizelyConfigEntity()
339339
{
340340
OptimizelyConfig expectedOptlyFeature = new OptimizelyConfig("123",
341+
"testSdkKey",
342+
"Development",
341343
new Dictionary<string, OptimizelyExperiment>(),
342344
new Dictionary<string, OptimizelyFeature>()
343345
);
344346
Assert.AreEqual(expectedOptlyFeature.Revision, "123");
347+
Assert.AreEqual(expectedOptlyFeature.SDKKey, "testSdkKey");
348+
Assert.AreEqual(expectedOptlyFeature.EnvironmentKey, "Development");
345349
Assert.AreEqual(expectedOptlyFeature.ExperimentsMap, new Dictionary<string, OptimizelyExperiment>());
346350
Assert.AreEqual(expectedOptlyFeature.FeaturesMap, new Dictionary<string, OptimizelyFeature>());
347351
}

OptimizelySDK.Tests/ProjectConfigTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020, Optimizely
2+
* Copyright 2017-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,6 +63,10 @@ public void TestInit()
6363
Assert.AreEqual("7720880029", Config.ProjectId);
6464
// Check Revision
6565
Assert.AreEqual("15", Config.Revision);
66+
// Check SDK key
67+
Assert.AreEqual("TestData", Config.SDKKey);
68+
// Check Environment key
69+
Assert.AreEqual("Production", Config.EnvironmentKey);
6670
// Check SendFlagDecision
6771
Assert.IsTrue(Config.SendFlagDecisions);
6872

OptimizelySDK.Tests/TestData.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,8 @@
939939
}
940940
],
941941
"revision": "15",
942+
"sdkKey": "TestData",
943+
"environmentKey": "Production",
942944
"anonymizeIP": false,
943945
"sendFlagDecisions": true,
944946
"botFiltering": true

OptimizelySDK.Tests/emptydatafile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
"attributes": [],
1212
"accountId": "10367498574",
1313
"events": [],
14-
"revision": "241"
14+
"revision": "241",
15+
"sdkKey": "emptydatafile",
16+
"environmentKey": "Production"
1517
}

OptimizelySDK.Tests/typed_audience_datafile.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,7 @@
367367
]
368368
}
369369
],
370-
"revision": "3"
371-
}
370+
"revision": "3",
371+
"sdkKey": "typedAudienceDatafile",
372+
"environmentKey": "Production"
373+
}

OptimizelySDK/Config/DatafileProjectConfig.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,10 +65,20 @@ public enum OPTLYSDKVersion
6565

6666

6767
/// <summary>
68-
/// Revision of the dataflie.
68+
/// Revision of the datafile.
6969
/// </summary>
7070
public string Revision { get; set; }
7171

72+
/// <summary>
73+
/// SDK key of the datafile.
74+
/// </summary>
75+
public string SDKKey { get; set; }
76+
77+
/// <summary>
78+
/// Environment key of the datafile.
79+
/// </summary>
80+
public string EnvironmentKey { get; set; }
81+
7282
/// <summary>
7383
/// SendFlagDecisions determines whether impressions events are sent for ALL decision types.
7484
/// </summary>

OptimizelySDK/OptlyConfig/OptimizelyConfig.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,18 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17+
using Newtonsoft.Json;
1718
using System.Collections.Generic;
1819

1920
namespace OptimizelySDK.OptlyConfig
2021
{
2122
public class OptimizelyConfig
2223
{
2324
public string Revision { get; private set; }
25+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
26+
public string SDKKey { get; private set; }
27+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
28+
public string EnvironmentKey { get; private set; }
2429
public IDictionary<string, OptimizelyExperiment> ExperimentsMap { get; private set; }
2530
public IDictionary<string, OptimizelyFeature> FeaturesMap { get; private set; }
2631

2732
private string _datafile;
28-
33+
2934
public OptimizelyConfig(string revision, IDictionary<string, OptimizelyExperiment> experimentsMap, IDictionary<string, OptimizelyFeature> featuresMap, string datafile = null)
3035
{
3136
Revision = revision;
@@ -34,6 +39,16 @@ public OptimizelyConfig(string revision, IDictionary<string, OptimizelyExperimen
3439
_datafile = datafile;
3540
}
3641

42+
public OptimizelyConfig(string revision, string sdkKey, string environmentKey, IDictionary<string, OptimizelyExperiment> experimentsMap, IDictionary<string, OptimizelyFeature> featuresMap, string datafile = null)
43+
{
44+
Revision = revision;
45+
SDKKey = sdkKey;
46+
EnvironmentKey = environmentKey;
47+
ExperimentsMap = experimentsMap;
48+
FeaturesMap = featuresMap;
49+
_datafile = datafile;
50+
}
51+
3752
/// <summary>
3853
/// Get the datafile associated with OptimizelyConfig.
3954
/// </summary>

OptimizelySDK/OptlyConfig/OptimizelyConfigService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,8 @@ public OptimizelyConfigService(ProjectConfig projectConfig)
3434
var experimentMap = GetExperimentsMap(projectConfig);
3535
var featureMap = GetFeaturesMap(projectConfig, experimentMap);
3636
OptimizelyConfig = new OptimizelyConfig(projectConfig.Revision,
37+
projectConfig.SDKKey,
38+
projectConfig.EnvironmentKey,
3739
experimentMap,
3840
featureMap,
3941
projectConfig.ToDatafile());

OptimizelySDK/ProjectConfig.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020, Optimizely
2+
* Copyright 2019-2021, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,10 +40,19 @@ public interface ProjectConfig
4040

4141

4242
/// <summary>
43-
/// Revision of the dataflie.
43+
/// Revision of the datafile.
4444
/// </summary>
4545
string Revision { get; set; }
4646

47+
/// <summary>
48+
/// SDK key of the datafile.
49+
/// </summary>
50+
string SDKKey { get; set; }
51+
52+
/// <summary>
53+
/// Environment key of the datafile.
54+
/// </summary>
55+
string EnvironmentKey { get; set; }
4756

4857
/// <summary>
4958
/// SendFlagDecisions determines whether impressions events are sent for ALL decision types.

0 commit comments

Comments
 (0)