Skip to content
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
12 changes: 6 additions & 6 deletions splitio/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- Flutter (1.0.0)
- Split (3.3.2)
- splitio_ios (0.8.0):
- Split (3.6.0)
- splitio_ios (0.9.0):
- Flutter
- Split (~> 3.3.2)
- Split (~> 3.6.0)

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -20,9 +20,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/splitio_ios/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
Split: 0d4962a6c15180e1857c1a3753e1ae9c91a6150b
splitio_ios: 438ad21d0dfe467670f8b9508773b77b16a71d6b
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
Split: 1e2176aacd6421029bea41413401389d86e3d50a
splitio_ios: ad4f484a6c478bf7285e417ea8252371f66b54ff

PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048

Expand Down
2 changes: 2 additions & 0 deletions splitio/lib/splitio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export 'package:splitio_platform_interface/split_view.dart';
export 'package:splitio_platform_interface/split_certificate_pinning_configuration.dart';
export 'package:splitio_platform_interface/split_evaluation_options.dart';
export 'package:splitio_platform_interface/split_rollout_cache_configuration.dart';
export 'package:splitio_platform_interface/split_fallback_treatment.dart';
export 'package:splitio_platform_interface/split_fallback_treatments_configuration.dart';

typedef ClientReadinessCallback = void Function(SplitClient splitClient);

Expand Down
12 changes: 8 additions & 4 deletions splitio/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ flutter:
dependencies:
flutter:
sdk: flutter
splitio_android: ^1.0.0
splitio_ios: ^1.0.0
splitio_web: ^1.0.0
splitio_platform_interface: ^2.0.0
splitio_android: # ^1.0.0
path: ../splitio_android
splitio_ios: # ^1.0.0
path: ../splitio_ios
splitio_web: # ^1.0.0
path: ../splitio_web
splitio_platform_interface: # ^2.0.0
path: ../splitio_platform_interface
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
2 changes: 1 addition & 1 deletion splitio_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
}

dependencies {
implementation 'io.split.client:android-client:5.3.1'
implementation 'io.split.client:android-client:5.4.2'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.12.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import io.split.android.client.network.CertificatePinningConfiguration;
import io.split.android.client.shared.UserConsent;
import io.split.android.client.utils.logger.SplitLogLevel;
import io.split.android.client.fallback.FallbackTreatmentsConfiguration;
import io.split.android.client.fallback.FallbackTreatment;

class SplitClientConfigHelper {

Expand Down Expand Up @@ -55,6 +57,11 @@ class SplitClientConfigHelper {
private static final String ROLLOUT_CACHE_CONFIGURATION = "rolloutCacheConfiguration";
private static final String ROLLOUT_CACHE_CONFIGURATION_EXPIRATION = "expirationDays";
private static final String ROLLOUT_CACHE_CONFIGURATION_CLEAR_ON_INIT = "clearOnInit";
private static final String FALLBACK_TREATMENTS = "fallbackTreatments";
private static final String FALLBACK_TREATMENTS_GLOBAL = "global";
private static final String FALLBACK_TREATMENTS_BY_FLAG = "byFlag";
private static final String FALLBACK_TREATMENT_VALUE = "treatment";
private static final String FALLBACK_TREATMENT_CONFIG = "config";

/**
* Creates a {@link SplitClientConfig} object from a map.
Expand Down Expand Up @@ -262,6 +269,29 @@ static SplitClientConfig fromMap(@NonNull Map<String, Object> configurationMap,
}
}

Map<String, Object> fallbackTreatments = getObjectMap(configurationMap, FALLBACK_TREATMENTS);
if (fallbackTreatments != null) {
Map<String, Object> global = getObjectMap(fallbackTreatments, FALLBACK_TREATMENTS_GLOBAL);
Map<String, Object> byFlag = getObjectMap(fallbackTreatments, FALLBACK_TREATMENTS_BY_FLAG);
if (global != null || byFlag != null) {
FallbackTreatmentsConfiguration.Builder fallbackTreatmentsBuilder = FallbackTreatmentsConfiguration.builder();
if (global != null) {
fallbackTreatmentsBuilder.global(new FallbackTreatment(getString(global, FALLBACK_TREATMENT_VALUE), getString(global, FALLBACK_TREATMENT_CONFIG)));
}
if (byFlag != null) {
Map<String, FallbackTreatment> byFlagMap = new HashMap<>();
for (Map.Entry<String, Object> entry : byFlag.entrySet()) {
Map<String, Object> byFlagFallbackTreatment = getObjectMap(byFlag, entry.getKey());
if (byFlagFallbackTreatment != null) {
byFlagMap.put(entry.getKey(), new FallbackTreatment(getString(byFlagFallbackTreatment, FALLBACK_TREATMENT_VALUE), getString(byFlagFallbackTreatment, FALLBACK_TREATMENT_CONFIG)));
}
}
fallbackTreatmentsBuilder.byFlag(byFlagMap);
}
builder.fallbackTreatments(fallbackTreatmentsBuilder.build());
}
}

return builder.serviceEndpoints(serviceEndpointsBuilder.build()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import io.split.android.client.utils.logger.LogPrinter;
import io.split.android.client.utils.logger.Logger;
import io.split.android.client.utils.logger.SplitLogLevel;
import io.split.android.client.fallback.FallbackTreatmentsConfiguration;
import io.split.android.client.fallback.FallbackTreatment;

public class SplitClientConfigHelperTest {

Expand Down Expand Up @@ -235,4 +237,33 @@ public void rolloutCacheConfigurationValuesAreMappedCorrectly() {
assertEquals(5, splitClientConfig.rolloutCacheConfiguration().getExpirationDays());
assertTrue(splitClientConfig.rolloutCacheConfiguration().isClearOnInit());
}

@Test
public void fallbackTreatmentsValuesAreMappedCorrectly() {
Map<String, Object> globalFallbackTreatment = new HashMap<>();
globalFallbackTreatment.put("treatment", "global-control");
globalFallbackTreatment.put("config", "global-config");

Map<String, Object> feature1FallbackTreatment = new HashMap<>();
feature1FallbackTreatment.put("treatment", "feature1-control");
feature1FallbackTreatment.put("config", null);

Map<String, Object> byFlagFallbackTreatments = new HashMap<>();
byFlagFallbackTreatments.put("feature1", feature1FallbackTreatment);

Map<String, Object> fallbackTreatmentsValues = new HashMap<>();
fallbackTreatmentsValues.put("global", globalFallbackTreatment);
fallbackTreatmentsValues.put("byFlag", byFlagFallbackTreatments);

Map<String, Object> configValues = new HashMap<>();
configValues.put("fallbackTreatments", fallbackTreatmentsValues);

SplitClientConfig splitClientConfig = SplitClientConfigHelper
.fromMap(configValues, mock(ImpressionListener.class));

FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = splitClientConfig.fallbackTreatments();

assertEquals(new FallbackTreatment("global-control", "global-config"), fallbackTreatmentsConfiguration.getGlobal());
assertEquals(Map.of("feature1", new FallbackTreatment("feature1-control", null)), fallbackTreatmentsConfiguration.getByFlag());
}
}
3 changes: 2 additions & 1 deletion splitio_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ flutter:
dependencies:
flutter:
sdk: flutter
splitio_platform_interface: ^2.0.0
splitio_platform_interface: # ^2.0.0
path: ../splitio_platform_interface

dev_dependencies:
flutter_test:
Expand Down
14 changes: 7 additions & 7 deletions splitio_ios/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- Flutter (1.0.0)
- Split (3.3.2)
- splitio_ios (0.8.0):
- Split (3.6.0)
- splitio_ios (0.9.0):
- Flutter
- Split (~> 3.3.2)
- Split (~> 3.6.0)

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -20,10 +20,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/splitio_ios/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
Split: 0d4962a6c15180e1857c1a3753e1ae9c91a6150b
splitio_ios: 438ad21d0dfe467670f8b9508773b77b16a71d6b
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
Split: 1e2176aacd6421029bea41413401389d86e3d50a
splitio_ios: ad4f484a6c478bf7285e417ea8252371f66b54ff

PODFILE CHECKSUM: aed42fc5c94ade572556b7ed357c5c57f1bd83a2
PODFILE CHECKSUM: ba5baa820782b9e142d3ba97a6b84de9feaaceda

COCOAPODS: 1.16.2
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,29 @@ class SplitClientConfigHelperTests: XCTestCase {
XCTAssertEqual(5, actualConfig.expirationDays)
XCTAssertTrue(actualConfig.clearOnInit)
}

func testFallbackTreatmentsConfigurationValuesAreMappedCorrectly() {
let configValues = [
"fallbackTreatments": [
"global": [
"treatment": "on",
"config": "{\"key\": \"value\"}"
],
"byFlag": [
"feature1": [
"treatment": "off",
"config": nil
]
]
]
]

let splitClientConfig: SplitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil)
let actualConfig = splitClientConfig.fallbackTreatments

XCTAssertEqual("on", actualConfig.global?.treatment)
XCTAssertEqual("{\"key\": \"value\"}", actualConfig.global?.config)
XCTAssertEqual("off", actualConfig.byFlag["feature1"]?.treatment)
XCTAssertNil(actualConfig.byFlag["feature1"]?.config)
}
}
29 changes: 29 additions & 0 deletions splitio_ios/ios/Classes/SplitClientConfigHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class SplitClientConfigHelper {
static private let ROLLOUT_CACHE_CONFIGURATION = "rolloutCacheConfiguration"
static private let ROLLOUT_CACHE_CONFIGURATION_EXPIRATION = "expirationDays"
static private let ROLLOUT_CACHE_CONFIGURATION_CLEAR_ON_INIT = "clearOnInit"
static private let FALLBACK_TREATMENTS = "fallbackTreatments";
static private let FALLBACK_TREATMENTS_GLOBAL = "global";
static private let FALLBACK_TREATMENTS_BY_FLAG = "byFlag";
static private let FALLBACK_TREATMENT_VALUE = "treatment";
static private let FALLBACK_TREATMENT_CONFIG = "config";

static func fromMap(configurationMap: [String: Any?], impressionListener: SplitImpressionListener?) -> SplitClientConfig {
let config = SplitClientConfig()
Expand Down Expand Up @@ -253,6 +258,30 @@ class SplitClientConfigHelper {
config.rolloutCacheConfiguration = rolloutCacheConfigurationBuilder.build()
}

if let fallbackTreatmentConfig = configurationMap[FALLBACK_TREATMENTS] as? [String: Any?] {
let fallbackTreatmentConfiguration = FallbackTreatmentsConfig.builder()

if let globalTreatment = fallbackTreatmentConfig[FALLBACK_TREATMENTS_GLOBAL] as? [String: Any?] {
fallbackTreatmentConfiguration.global(FallbackTreatment(
treatment: globalTreatment[FALLBACK_TREATMENT_VALUE] as! String,
config: globalTreatment[FALLBACK_TREATMENT_CONFIG] as? String
))
}

if let byFlagTreatments = fallbackTreatmentConfig[FALLBACK_TREATMENTS_BY_FLAG] as? [String: [String: Any?]] {
var byFlag: [String: FallbackTreatment] = [:]
for (key, value) in byFlagTreatments {
byFlag[key] = FallbackTreatment(
treatment: value[FALLBACK_TREATMENT_VALUE] as! String,
config: value[FALLBACK_TREATMENT_CONFIG] as? String
)
}
fallbackTreatmentConfiguration.byFlag(byFlag)
}

config.fallbackTreatments = fallbackTreatmentConfiguration.build()
}

return config
}

Expand Down
4 changes: 2 additions & 2 deletions splitio_ios/ios/splitio_ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'splitio_ios'
s.version = '0.8.0'
s.version = '0.9.0'
s.summary = 'split.io official Flutter plugin.'
s.description = <<-DESC
split.io official Flutter plugin.
Expand All @@ -15,7 +15,7 @@ split.io official Flutter plugin.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'Split', '~> 3.3.2'
s.dependency 'Split', '~> 3.6.0'
s.platform = :ios, '9.0'

# Flutter.framework does not contain a i386 slice.
Expand Down
3 changes: 2 additions & 1 deletion splitio_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ flutter:
dependencies:
flutter:
sdk: flutter
splitio_platform_interface: ^2.0.0
splitio_platform_interface: # ^2.0.0
path: ../splitio_platform_interface

dev_dependencies:
flutter_test:
Expand Down
3 changes: 2 additions & 1 deletion splitio_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ flutter:
dependencies:
flutter:
sdk: flutter
splitio_platform_interface: ^2.0.0
splitio_platform_interface: # ^2.0.0
path: ../splitio_platform_interface
flutter_web_plugins:
sdk: flutter
web: ">=0.5.0 <2.0.0"
Expand Down