Skip to content
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

Feat: added SDKkey and environment key in project config #265

Merged
merged 4 commits into from
Jun 16, 2021
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020, Optimizely
* Copyright 2020-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -326,7 +326,7 @@ public void TestGetOptimizelyConfigService()
};

OptimizelyConfig optimizelyConfig = new OptimizelyConfigService(datafileProjectConfig).GetOptimizelyConfig();
OptimizelyConfig expectedOptimizelyConfig = new OptimizelyConfig(datafileProjectConfig.Revision, experimentsMap, featuresMap);
OptimizelyConfig expectedOptimizelyConfig = new OptimizelyConfig(datafileProjectConfig.Revision, datafileProjectConfig.SDKKey, datafileProjectConfig.EnvironmentKey, experimentsMap, featuresMap);
Assert.IsTrue(TestData.CompareObjects(optimizelyConfig, expectedOptimizelyConfig));
}

Expand All @@ -338,10 +338,14 @@ public void TestGetOptimizelyConfigService()
public void TestOptimizelyConfigEntity()
{
OptimizelyConfig expectedOptlyFeature = new OptimizelyConfig("123",
"testSdkKey",
"Development",
new Dictionary<string, OptimizelyExperiment>(),
new Dictionary<string, OptimizelyFeature>()
);
Assert.AreEqual(expectedOptlyFeature.Revision, "123");
Assert.AreEqual(expectedOptlyFeature.SDKKey, "testSdkKey");
Assert.AreEqual(expectedOptlyFeature.EnvironmentKey, "Development");
Assert.AreEqual(expectedOptlyFeature.ExperimentsMap, new Dictionary<string, OptimizelyExperiment>());
Assert.AreEqual(expectedOptlyFeature.FeaturesMap, new Dictionary<string, OptimizelyFeature>());
}
Expand Down
6 changes: 5 additions & 1 deletion OptimizelySDK.Tests/ProjectConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020, Optimizely
* Copyright 2017-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -63,6 +63,10 @@ public void TestInit()
Assert.AreEqual("7720880029", Config.ProjectId);
// Check Revision
Assert.AreEqual("15", Config.Revision);
// Check SDK key
Assert.AreEqual("TestData", Config.SDKKey);
// Check Environment key
Assert.AreEqual("Production", Config.EnvironmentKey);
// Check SendFlagDecision
Assert.IsTrue(Config.SendFlagDecisions);

Expand Down
2 changes: 2 additions & 0 deletions OptimizelySDK.Tests/TestData.json
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@
}
],
"revision": "15",
"sdkKey": "TestData",
"environmentKey": "Production",
"anonymizeIP": false,
"sendFlagDecisions": true,
"botFiltering": true
Expand Down
4 changes: 3 additions & 1 deletion OptimizelySDK.Tests/emptydatafile.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
"attributes": [],
"accountId": "10367498574",
"events": [],
"revision": "241"
"revision": "241",
"sdkKey": "emptydatafile",
"environmentKey": "Production"
}
6 changes: 4 additions & 2 deletions OptimizelySDK.Tests/typed_audience_datafile.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,7 @@
]
}
],
"revision": "3"
}
"revision": "3",
"sdkKey": "typedAudienceDatafile",
"environmentKey": "Production"
}
14 changes: 12 additions & 2 deletions OptimizelySDK/Config/DatafileProjectConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020, Optimizely
* Copyright 2019-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,10 +65,20 @@ public enum OPTLYSDKVersion


/// <summary>
/// Revision of the dataflie.
/// Revision of the datafile.
/// </summary>
public string Revision { get; set; }

/// <summary>
/// SDK key of the datafile.
/// </summary>
public string SDKKey { get; set; }

/// <summary>
/// Environment key of the datafile.
/// </summary>
public string EnvironmentKey { get; set; }

/// <summary>
/// SendFlagDecisions determines whether impressions events are sent for ALL decision types.
/// </summary>
Expand Down
19 changes: 17 additions & 2 deletions OptimizelySDK/OptlyConfig/OptimizelyConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020, Optimizely
* Copyright 2019-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,18 +14,23 @@
* limitations under the License.
*/

using Newtonsoft.Json;
using System.Collections.Generic;

namespace OptimizelySDK.OptlyConfig
{
public class OptimizelyConfig
{
public string Revision { get; private set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string SDKKey { get; private set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string EnvironmentKey { get; private set; }
public IDictionary<string, OptimizelyExperiment> ExperimentsMap { get; private set; }
public IDictionary<string, OptimizelyFeature> FeaturesMap { get; private set; }

private string _datafile;

public OptimizelyConfig(string revision, IDictionary<string, OptimizelyExperiment> experimentsMap, IDictionary<string, OptimizelyFeature> featuresMap, string datafile = null)
{
Revision = revision;
Expand All @@ -34,6 +39,16 @@ public OptimizelyConfig(string revision, IDictionary<string, OptimizelyExperimen
_datafile = datafile;
}

public OptimizelyConfig(string revision, string sdkKey, string environmentKey, IDictionary<string, OptimizelyExperiment> experimentsMap, IDictionary<string, OptimizelyFeature> featuresMap, string datafile = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break functionality.

Add one more constructor and leave this constructor as it is.

{
Revision = revision;
SDKKey = sdkKey;
EnvironmentKey = environmentKey;
ExperimentsMap = experimentsMap;
FeaturesMap = featuresMap;
_datafile = datafile;
}

/// <summary>
/// Get the datafile associated with OptimizelyConfig.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion OptimizelySDK/OptlyConfig/OptimizelyConfigService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020, Optimizely
* Copyright 2019-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,8 @@ public OptimizelyConfigService(ProjectConfig projectConfig)
var experimentMap = GetExperimentsMap(projectConfig);
var featureMap = GetFeaturesMap(projectConfig, experimentMap);
OptimizelyConfig = new OptimizelyConfig(projectConfig.Revision,
projectConfig.SDKKey,
projectConfig.EnvironmentKey,
experimentMap,
featureMap,
projectConfig.ToDatafile());
Expand Down
13 changes: 11 additions & 2 deletions OptimizelySDK/ProjectConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020, Optimizely
* Copyright 2019-2021, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,10 +40,19 @@ public interface ProjectConfig


/// <summary>
/// Revision of the dataflie.
/// Revision of the datafile.
/// </summary>
string Revision { get; set; }

/// <summary>
/// SDK key of the datafile.
/// </summary>
string SDKKey { get; set; }

/// <summary>
/// Environment key of the datafile.
/// </summary>
string EnvironmentKey { get; set; }

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