Skip to content

Commit

Permalink
feat (audience match types): Condition evaluator, Audience combinatio…
Browse files Browse the repository at this point in the history
…n and Project Config PRs consolidation. (#351)

* Type changed to NSObject & a test case added

* added all type attributes in Optimizely and EventBuilder test cases

* attribute filtering in EventBuilder only

* missing types added in attribute filtration

* Added unit test in decision service and Notification Center to support all type of attributes.
One more unit test fixed. For NSNull and Any object other than NSNumber.

* null support for attributes & eventTags Notification Center PR.

* Nullable attribute and eventTags activate listener and track listener

* Generic listener and sendNotifications should have NSDictionary.

* feat (audience match types): Update condition evaluator for new audience match types

* Updates license

* Addresses Review

* feat (audience match types): Update audience evaluator and project config for new audience match types

* Refact:
If no attributes, defaults to empty attributes

* Addressed Code Review comments.

* 1. Merge branch 'sohail/null-attribute-support' into yasir/audience-match-type-evaluator/
2. Fix code indentation.

* null support for attributes & eventTags Notification Center PR.

* Nullable attribute and eventTags activate listener and track listener

* Generic listener and sendNotifications should have NSDictionary.

* Addressed Code Review comments.

* Minor conflicts resolved.

* refact(conditions in typed audiences) - convert from str to array

* Addressed code review comments.

* Addressed code review comments.

* Addressed code review comments

* feat (audience match types): Update condition evaluator for new audience match types. (#336)

* Type changed to NSObject & a test case added

* added all type attributes in Optimizely and EventBuilder test cases

* attribute filtering in EventBuilder only

* missing types added in attribute filtration

* Added unit test in decision service and Notification Center to support all type of attributes.
One more unit test fixed. For NSNull and Any object other than NSNumber.

* null support for attributes & eventTags Notification Center PR.

* Nullable attribute and eventTags activate listener and track listener

* Generic listener and sendNotifications should have NSDictionary.

* feat (audience match types): Update condition evaluator for new audience match types

* Updates license

* Addresses Review

* Addressed Code Review comments.

* 1. Merge branch 'sohail/null-attribute-support' into yasir/audience-match-type-evaluator/
2. Fix code indentation.

* Addressed code review comments.

* Array issue in swift fixed.

* typo corrected.

* feat (audience match types): Update audience evaluator and project config for new audience match types (#337)

* Type changed to NSObject & a test case added

* added all type attributes in Optimizely and EventBuilder test cases

* attribute filtering in EventBuilder only

* missing types added in attribute filtration

* Added unit test in decision service and Notification Center to support all type of attributes.
One more unit test fixed. For NSNull and Any object other than NSNumber.

* null support for attributes & eventTags Notification Center PR.

* Nullable attribute and eventTags activate listener and track listener

* Generic listener and sendNotifications should have NSDictionary.

* feat (audience match types): Update condition evaluator for new audience match types

* Updates license

* Addresses Review

* feat (audience match types): Update audience evaluator and project config for new audience match types

* Refact:
If no attributes, defaults to empty attributes

* Addressed Code Review comments.

* 1. Merge branch 'sohail/null-attribute-support' into yasir/audience-match-type-evaluator/
2. Fix code indentation.

* refact(conditions in typed audiences) - convert from str to array

* Addressed code review comments.

* Addressed code review comments.

* Addressed code review comments

* Array issue in swift fixed.

* typo corrected.

* feat(audience-evaluation) : add support for complex audiences (#343)

* Headers updated.

* Target Membership Updated for OPTLYAudienceBaseCondition.

* Import Headers updated for SDKCore.

* TVOS fix for AudienceBaseCondition.
  • Loading branch information
yasirfolio3 authored and thomaszurkan-optimizely committed Jan 8, 2019
1 parent 2cf848e commit db72170
Show file tree
Hide file tree
Showing 52 changed files with 2,563 additions and 302 deletions.
36 changes: 30 additions & 6 deletions OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,20 @@
90855D0120ED254600A97BEC /* OPTLYControlAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 90855CFC20ED237F00A97BEC /* OPTLYControlAttributes.h */; settings = {ATTRIBUTES = (Public, ); }; };
90855D0D20ED2E0100A97BEC /* OPTLYControlAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 90855D0420ED2B0200A97BEC /* OPTLYControlAttributes.m */; };
90855D0E20ED2E0300A97BEC /* OPTLYControlAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 90855D0420ED2B0200A97BEC /* OPTLYControlAttributes.m */; };
C778BD2521DCDAB500AD38AE /* OPTLYTypedAudienceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C778BD2421DCDAB500AD38AE /* OPTLYTypedAudienceTest.m */; };
C778BD2621DCDAB500AD38AE /* OPTLYTypedAudienceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C778BD2421DCDAB500AD38AE /* OPTLYTypedAudienceTest.m */; };
C77958C3219BFBC300B4CA89 /* OPTLYNSObject+Validation.h in Headers */ = {isa = PBXBuildFile; fileRef = C77958C0219BFBA000B4CA89 /* OPTLYNSObject+Validation.h */; };
C77958C4219BFBC400B4CA89 /* OPTLYNSObject+Validation.h in Headers */ = {isa = PBXBuildFile; fileRef = C77958C0219BFBA000B4CA89 /* OPTLYNSObject+Validation.h */; };
C77958C5219BFBC700B4CA89 /* OPTLYNSObject+Validation.m in Sources */ = {isa = PBXBuildFile; fileRef = C77958C1219BFBA000B4CA89 /* OPTLYNSObject+Validation.m */; };
C77958C6219BFBC800B4CA89 /* OPTLYNSObject+Validation.m in Sources */ = {isa = PBXBuildFile; fileRef = C77958C1219BFBA000B4CA89 /* OPTLYNSObject+Validation.m */; };
C7809D1921C11675005725FF /* OPTLYValidationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C7809D1821C11675005725FF /* OPTLYValidationTest.m */; };
C7809D1A21C11675005725FF /* OPTLYValidationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C7809D1821C11675005725FF /* OPTLYValidationTest.m */; };
C779881321CBC22A002AAEC8 /* OPTLYValidationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C779881221CBC22A002AAEC8 /* OPTLYValidationTest.m */; };
C779881421CBC22A002AAEC8 /* OPTLYValidationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C779881221CBC22A002AAEC8 /* OPTLYValidationTest.m */; };
C78F98B7219ADEA600808062 /* OPTLYAudienceBaseCondition.h in Headers */ = {isa = PBXBuildFile; fileRef = C78F98B4219ADE9600808062 /* OPTLYAudienceBaseCondition.h */; settings = {ATTRIBUTES = (Public, ); }; };
C78F98B8219ADEA700808062 /* OPTLYAudienceBaseCondition.h in Headers */ = {isa = PBXBuildFile; fileRef = C78F98B4219ADE9600808062 /* OPTLYAudienceBaseCondition.h */; settings = {ATTRIBUTES = (Public, ); }; };
C78F98B9219ADEAB00808062 /* OPTLYAudienceBaseCondition.m in Sources */ = {isa = PBXBuildFile; fileRef = C78F98B5219ADE9600808062 /* OPTLYAudienceBaseCondition.m */; };
C78F98BA219ADEAB00808062 /* OPTLYAudienceBaseCondition.m in Sources */ = {isa = PBXBuildFile; fileRef = C78F98B5219ADE9600808062 /* OPTLYAudienceBaseCondition.m */; };
C7ACD4FE218C2E4A008EC52E /* typed_audience_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = C7ACD4FD218C2E4A008EC52E /* typed_audience_datafile.json */; };
C7ACD4FF218C2E51008EC52E /* typed_audience_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = C7ACD4FD218C2E4A008EC52E /* typed_audience_datafile.json */; };
EA064BC71DD3FC8800DF7537 /* OPTLYQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = EA064BC51DD3FC8800DF7537 /* OPTLYQueue.h */; settings = {ATTRIBUTES = (Public, ); }; };
EA064BC81DD3FC8800DF7537 /* OPTLYQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = EA064BC51DD3FC8800DF7537 /* OPTLYQueue.h */; settings = {ATTRIBUTES = (Public, ); }; };
EA064BC91DD3FC8800DF7537 /* OPTLYQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = EA064BC61DD3FC8800DF7537 /* OPTLYQueue.m */; };
Expand Down Expand Up @@ -635,9 +643,13 @@
A52039FD7B704890859320C4 /* Pods-OptimizelySDKCoreiOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelySDKCoreiOSTests.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-OptimizelySDKCoreiOSTests/Pods-OptimizelySDKCoreiOSTests.debug.xcconfig"; sourceTree = "<group>"; };
B333468714C0D4A8633103EF /* Pods-OptimizelySDKCoreiOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelySDKCoreiOSTests.release.xcconfig"; path = "../Pods/Target Support Files/Pods-OptimizelySDKCoreiOSTests/Pods-OptimizelySDKCoreiOSTests.release.xcconfig"; sourceTree = "<group>"; };
BE0C3BD9DC6186DB98A667C2 /* Pods_OptimizelySDKCoreTVOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OptimizelySDKCoreTVOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C778BD2421DCDAB500AD38AE /* OPTLYTypedAudienceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYTypedAudienceTest.m; sourceTree = "<group>"; };
C77958C0219BFBA000B4CA89 /* OPTLYNSObject+Validation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OPTLYNSObject+Validation.h"; sourceTree = "<group>"; };
C77958C1219BFBA000B4CA89 /* OPTLYNSObject+Validation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OPTLYNSObject+Validation.m"; sourceTree = "<group>"; };
C7809D1821C11675005725FF /* OPTLYValidationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OPTLYValidationTest.m; sourceTree = "<group>"; };
C779881221CBC22A002AAEC8 /* OPTLYValidationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYValidationTest.m; sourceTree = "<group>"; };
C78F98B4219ADE9600808062 /* OPTLYAudienceBaseCondition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OPTLYAudienceBaseCondition.h; sourceTree = "<group>"; };
C78F98B5219ADE9600808062 /* OPTLYAudienceBaseCondition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OPTLYAudienceBaseCondition.m; sourceTree = "<group>"; };
C7ACD4FD218C2E4A008EC52E /* typed_audience_datafile.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = typed_audience_datafile.json; sourceTree = "<group>"; };
E2E7211C032DF7A75264FDDB /* Pods-OptimizelySDKCoreTVOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelySDKCoreTVOSTests.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-OptimizelySDKCoreTVOSTests/Pods-OptimizelySDKCoreTVOSTests.debug.xcconfig"; sourceTree = "<group>"; };
EA064BC51DD3FC8800DF7537 /* OPTLYQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYQueue.h; sourceTree = "<group>"; };
EA064BC61DD3FC8800DF7537 /* OPTLYQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYQueue.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1050,6 +1062,8 @@
EA2FAA531DC6F57100B1D81B /* OPTLYAttribute.m */,
EA2FAA541DC6F57100B1D81B /* OPTLYAudience.h */,
EA2FAA551DC6F57100B1D81B /* OPTLYAudience.m */,
C78F98B4219ADE9600808062 /* OPTLYAudienceBaseCondition.h */,
C78F98B5219ADE9600808062 /* OPTLYAudienceBaseCondition.m */,
EA2FAA561DC6F57100B1D81B /* OPTLYBaseCondition.h */,
EA2FAA571DC6F57100B1D81B /* OPTLYBaseCondition.m */,
EA2FAA581DC6F57100B1D81B /* OPTLYCondition.h */,
Expand Down Expand Up @@ -1183,6 +1197,7 @@
EA2FAB941DC6FDFA00B1D81B /* TestData */ = {
isa = PBXGroup;
children = (
C7ACD4FD218C2E4A008EC52E /* typed_audience_datafile.json */,
EA2FAB951DC6FDFA00B1D81B /* BucketerTestsDatafile.json */,
3E92800D1F26AD4700214C58 /* BucketerTestsDatafile2.json */,
5E4C07F21DFF645C0042B1F8 /* UnsupportedVersionDatafile.json */,
Expand Down Expand Up @@ -1259,6 +1274,7 @@
EA2FAB861DC6FDFA00B1D81B /* OptimizelyTest.m */,
3EEC2B0120CB40ED00D096E4 /* OptimizelyV3Test.m */,
EA2FAB871DC6FDFA00B1D81B /* OPTLYAudienceTest.m */,
C778BD2421DCDAB500AD38AE /* OPTLYTypedAudienceTest.m */,
EA2FAB881DC6FDFA00B1D81B /* OPTLYBucketerTest.m */,
EA2FAB891DC6FDFA00B1D81B /* OPTLYBuilderTest.m */,
EA2FAB8A1DC6FDFA00B1D81B /* OPTLYConditionTest.m */,
Expand All @@ -1276,7 +1292,7 @@
EA064BCB1DD3FC9F00DF7537 /* OPTLYQueueTest.m */,
EA2FAB911DC6FDFA00B1D81B /* OPTLYTestHelper.h */,
EA2FAB921DC6FDFA00B1D81B /* OPTLYTestHelper.m */,
C7809D1821C11675005725FF /* OPTLYValidationTest.m */,
C779881221CBC22A002AAEC8 /* OPTLYValidationTest.m */,
EA2FAB941DC6FDFA00B1D81B /* TestData */,
);
path = OptimizelySDKCoreTests;
Expand Down Expand Up @@ -1362,6 +1378,7 @@
EA2FAAA01DC6F57100B1D81B /* OPTLYDatafileKeys.h in Headers */,
EA2FAAB21DC6F57200B1D81B /* OPTLYEventAudience.h in Headers */,
EA2FAA881DC6F57100B1D81B /* OPTLYAttribute.h in Headers */,
C78F98B7219ADEA600808062 /* OPTLYAudienceBaseCondition.h in Headers */,
EA2FAAE81DC6F57200B1D81B /* OPTLYEventParameterKeys.h in Headers */,
EA2FAADC1DC6F57200B1D81B /* OPTLYEventLayerState.h in Headers */,
EA2FAAEE1DC6F57200B1D81B /* OPTLYEventRelatedEvent.h in Headers */,
Expand Down Expand Up @@ -1428,6 +1445,7 @@
EA2FAB131DC6F57200B1D81B /* OPTLYTrafficAllocation.h in Headers */,
EA2FAA891DC6F57100B1D81B /* OPTLYAttribute.h in Headers */,
EA2FAA9B1DC6F57100B1D81B /* OPTLYCondition.h in Headers */,
C78F98B8219ADEA700808062 /* OPTLYAudienceBaseCondition.h in Headers */,
EA2FAAAD1DC6F57200B1D81B /* OPTLYEvent.h in Headers */,
EA2FAA8F1DC6F57100B1D81B /* OPTLYAudience.h in Headers */,
EA2FAB071DC6F57200B1D81B /* OPTLYGroup.h in Headers */,
Expand Down Expand Up @@ -1691,6 +1709,7 @@
EA2FABD81DC6FDFA00B1D81B /* optimizely_7519590183.json in Resources */,
EA2FABD51DC6FDFA00B1D81B /* test_data_50_experiments.json in Resources */,
EA2FABCF1DC6FDFA00B1D81B /* test_data_10_experiments.json in Resources */,
C7ACD4FE218C2E4A008EC52E /* typed_audience_datafile.json in Resources */,
5E4C07F31DFF645C0042B1F8 /* UnsupportedVersionDatafile.json in Resources */,
3E99CF7F1FE02C2D00B16B97 /* optimizely_6372300739_v4.json in Resources */,
3EEC2AF220CB3D9E00D096E4 /* test_data_10_experimentsV3.json in Resources */,
Expand All @@ -1716,6 +1735,7 @@
EA2FABCD1DC6FDFA00B1D81B /* optimizely_6372300739.json in Resources */,
EA2FABD91DC6FDFA00B1D81B /* optimizely_7519590183.json in Resources */,
EA2FABD61DC6FDFA00B1D81B /* test_data_50_experiments.json in Resources */,
C7ACD4FF218C2E51008EC52E /* typed_audience_datafile.json in Resources */,
EA2FABD01DC6FDFA00B1D81B /* test_data_10_experiments.json in Resources */,
3E99CF801FE02C2E00B16B97 /* optimizely_6372300739_v4.json in Resources */,
3EEC2AF320CB3D9E00D096E4 /* test_data_10_experimentsV3.json in Resources */,
Expand Down Expand Up @@ -1955,6 +1975,7 @@
EA2C242F1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.m in Sources */,
EA8FD0E11DE9798E00D950AD /* OPTLYNetworkService.m in Sources */,
EA2FAC171DC6FFC600B1D81B /* OPTLYEventMetric.m in Sources */,
C78F98B9219ADEAB00808062 /* OPTLYAudienceBaseCondition.m in Sources */,
EA2FAC181DC6FFC600B1D81B /* OPTLYEventParameterKeys.m in Sources */,
EA2FAC191DC6FFC600B1D81B /* OPTLYEventRelatedEvent.m in Sources */,
EA2FAC1B1DC6FFC600B1D81B /* OPTLYEventView.m in Sources */,
Expand Down Expand Up @@ -1992,10 +2013,10 @@
59B9E1E220E35C9E002F732E /* OPTLYProjectConfigSwiftTest.swift in Sources */,
EA2FAB9C1DC6FDFA00B1D81B /* OptimizelySDKCoreTests.m in Sources */,
EA2FABA21DC6FDFA00B1D81B /* OptimizelyTest.m in Sources */,
C778BD2521DCDAB500AD38AE /* OPTLYTypedAudienceTest.m in Sources */,
59B9E1D120E28DBC002F732E /* OptimizelySwiftTest.swift in Sources */,
EA2FABC31DC6FDFA00B1D81B /* OPTLYTestHelper.m in Sources */,
EA2FABBD1DC6FDFA00B1D81B /* OPTLYLoggerTest.m in Sources */,
C7809D1921C11675005725FF /* OPTLYValidationTest.m in Sources */,
EA064BCE1DD3FCD700DF7537 /* OPTLYQueueTest.m in Sources */,
5E4C07FB1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m in Sources */,
EA2FABB41DC6FDFA00B1D81B /* OPTLYEventBuilderTest.m in Sources */,
Expand All @@ -2004,6 +2025,7 @@
EA2FABB71DC6FDFA00B1D81B /* OPTLYEventDispatcherTest.m in Sources */,
EA2FABA51DC6FDFA00B1D81B /* OPTLYAudienceTest.m in Sources */,
EA2FABB11DC6FDFA00B1D81B /* OPTLYErrorHandlerTest.m in Sources */,
C779881321CBC22A002AAEC8 /* OPTLYValidationTest.m in Sources */,
0BDF71FF202D04EF00EB9742 /* OPTLYNotificationCenterTest2.swift in Sources */,
EA2FABC01DC6FDFA00B1D81B /* OPTLYProjectConfigTest.m in Sources */,
EA2FABA81DC6FDFA00B1D81B /* OPTLYBucketerTest.m in Sources */,
Expand Down Expand Up @@ -2048,6 +2070,7 @@
EA2FABF21DC6FFA100B1D81B /* OPTLYEventMetric.m in Sources */,
EA2FABF31DC6FFA100B1D81B /* OPTLYEventParameterKeys.m in Sources */,
EA2FABF41DC6FFA100B1D81B /* OPTLYEventRelatedEvent.m in Sources */,
C78F98BA219ADEAB00808062 /* OPTLYAudienceBaseCondition.m in Sources */,
3E858C881F4227F100D53856 /* OPTLYJSONModel.m in Sources */,
EA2FABF61DC6FFA100B1D81B /* OPTLYEventView.m in Sources */,
EA2FABF71DC6FFA100B1D81B /* OPTLYExperiment.m in Sources */,
Expand Down Expand Up @@ -2097,13 +2120,14 @@
3EA818961FFF890E00BEBD41 /* OPTLYNotificationCenterTest.m in Sources */,
EA2FABB81DC6FDFA00B1D81B /* OPTLYEventDispatcherTest.m in Sources */,
EA2FABA61DC6FDFA00B1D81B /* OPTLYAudienceTest.m in Sources */,
C7809D1A21C11675005725FF /* OPTLYValidationTest.m in Sources */,
EA2FABB21DC6FDFA00B1D81B /* OPTLYErrorHandlerTest.m in Sources */,
0BDF7200202D04EF00EB9742 /* OPTLYNotificationCenterTest2.swift in Sources */,
C779881421CBC22A002AAEC8 /* OPTLYValidationTest.m in Sources */,
EA2FABC11DC6FDFA00B1D81B /* OPTLYProjectConfigTest.m in Sources */,
EA2FABA91DC6FDFA00B1D81B /* OPTLYBucketerTest.m in Sources */,
EA9358A21ECD794C00E3F201 /* OPTLYDecisionServiceTest.m in Sources */,
EA2FABAC1DC6FDFA00B1D81B /* OPTLYBuilderTest.m in Sources */,
C778BD2621DCDAB500AD38AE /* OPTLYTypedAudienceTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion OptimizelySDKCore/OptimizelySDKCore/OPTLYAudience.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2016,2018, Optimizely, Inc. and contributors *
* Copyright 2016,2018-2019, 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. *
Expand Down Expand Up @@ -36,5 +36,6 @@

/// Override OPTLYJSONModel set conditions
- (void)setConditionsWithNSString:(NSString *)string;
- (void)setConditionsWithNSArray:(NSArray *)array;

@end
30 changes: 13 additions & 17 deletions OptimizelySDKCore/OptimizelySDKCore/OPTLYAudience.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2016, Optimizely, Inc. and contributors *
* Copyright 2016,2018-2019, 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. *
Expand All @@ -16,6 +16,7 @@

#import "OPTLYAudience.h"
#import "OPTLYDatafileKeys.h"
#import "OPTLYNSObject+Validation.h"

@implementation OPTLYAudience

Expand All @@ -27,34 +28,29 @@ + (OPTLYJSONKeyMapper*)keyMapper
}

- (void)setConditionsWithNSString:(NSString *)string {
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];

NSArray *array = [string getValidConditionsArray];
[self setConditionsWithNSArray:array];
}

- (void)setConditionsWithNSArray:(NSArray *)array {
NSError *err = nil;
NSArray *array = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&err];
if (err != nil) {
NSException *exception = [[NSException alloc] initWithName:err.domain reason:err.localizedFailureReason userInfo:@{@"Error" : err}];
@throw exception;
}

self.conditions = [OPTLYCondition deserializeJSONArray:array error:&err];

self.conditions = [OPTLYCondition deserializeJSONArray:array error:nil];
if (err != nil) {
NSException *exception = [[NSException alloc] initWithName:err.domain reason:err.localizedFailureReason userInfo:@{@"Error" : err}];
@throw exception;
}
}

- (BOOL)evaluateConditionsWithAttributes:(NSDictionary<NSString *, NSObject *> *)attributes {
- (nullable NSNumber *)evaluateConditionsWithAttributes:(NSDictionary<NSString *, NSObject *> *)attributes projectConfig:(nullable OPTLYProjectConfig *)config {
for (NSObject<OPTLYCondition> *condition in self.conditions) {
if ([condition evaluateConditionsWithAttributes:attributes]) {
NSNumber *result = [condition evaluateConditionsWithAttributes:attributes projectConfig:config];
if (result != NULL && [result boolValue] == true) {
// if user satisfies any conditions, return true.
return true;
return [NSNumber numberWithBool:true];
}
}
// if user doesn't satisfy any conditions, return false.
return false;
return [NSNumber numberWithBool:false];
}

@end
33 changes: 33 additions & 0 deletions OptimizelySDKCore/OptimizelySDKCore/OPTLYAudienceBaseCondition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/****************************************************************************
* Copyright 2018-2019, 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. *
***************************************************************************/

#ifdef UNIVERSAL
#import "OPTLYJSONModelLib.h"
#else
#import <OptimizelySDKCore/OPTLYJSONModelLib.h>
#endif
#import "OPTLYCondition.h"

@protocol OPTLYAudienceBaseCondition
@end

@interface OPTLYAudienceBaseCondition : NSObject <OPTLYCondition>

@property (nonatomic, strong) NSString *audienceId;
+(BOOL)isBaseConditionJSON:(NSData *)jsonData;

@end

Loading

0 comments on commit db72170

Please sign in to comment.