Skip to content

Commit 5341259

Browse files
User profile feature.
1 parent 702fa9f commit 5341259

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ typedef void (^OPTLYBuilderBlock)(OPTLYBuilder * _Nullable builder);
4747
/// User profile stores user-specific data, like bucketing.
4848
@property (nonatomic, strong, nullable) id<OPTLYUserProfile> userProfile;
4949

50+
@property (nonatomic, strong, nullable) id<OPTLYUserProfile> userProfile;
51+
5052
/// Create an Optimizely Builder object.
5153
+ (nullable instancetype)builderWithBlock:(nonnull OPTLYBuilderBlock)block;
5254

OptimizelySDKCore/OptimizelySDKCore/OPTLYLoggerMessages.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ extern NSString *const OPTLYLoggerMessagesNoVariationFoundForExperimentWithLiveV
6969
// ---- debug ----
7070
extern NSString *const OPTLYLoggerMessagesBucketAssigned;
7171

72-
// ---- User Profile ----
73-
// Debug
74-
extern NSString *const OPTLYLoggerMessagesUserProfileVariation;
75-
extern NSString *const OPTLYLoggerMessagesUserProfileNoVariation;
76-
extern NSString *const OPTLYLoggerMessagesUserProfileRemoveVariation;
77-
extern NSString *const OPTLYLoggerMessagesUserProfileRemoveVariationNotFound;
78-
7972
// ---- Event Dispatcher ----
8073
// info
8174
extern NSString *const OPTLYLoggerMessagesConversionSuccess;
@@ -128,6 +121,13 @@ extern NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetTVOSWarning;
128121
extern NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNumberEventsTVOSWarning;
129122
extern NSString *const OPTLYLoggerMessagesDataStoreDatabaseRemoveTVOSWarning;
130123

124+
// ---- User Profile ----
125+
// Debug
126+
extern NSString *const OPTLYLoggerMessagesUserProfileVariation;
127+
extern NSString *const OPTLYLoggerMessagesUserProfileNoVariation;
128+
extern NSString *const OPTLYLoggerMessagesUserProfileRemoveVariation;
129+
extern NSString *const OPTLYLoggerMessagesUserProfileRemoveVariationNotFound;
130+
131131
@interface OPTLYLoggerMessages : NSObject
132132

133133
@end

OptimizelySDKCore/OptimizelySDKCore/OPTLYLoggerMessages.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@
128128
NSString *const OPTLYLoggerMessagesDataStoreDatabaseGetNumberEventsTVOSWarning = @"[DATABASE] tvOS can only get number of events from cache. eventType: %ld.";
129129
NSString *const OPTLYLoggerMessagesDataStoreDatabaseRemoveTVOSWarning = @"[DATABASE] tvOS can only remove data from cache> Number of events: %ld, eventType: %ld.";
130130

131-
131+
// ---- User Profile ----
132+
// Debug
133+
NSString *const OPTLYLoggerMessagesUserProfileVariation = @"Variation %@ for user %@, experiment %@ found.";
134+
NSString *const OPTLYLoggerMessagesUserProfileNoVariation = @"Variation for user %@, experiment %@ not found.";
135+
NSString *const OPTLYLoggerMessagesUserProfileRemoveVariation = @"Removed variation %@ for user %@, experiment %@.";
136+
NSString *const OPTLYLoggerMessagesUserProfileRemoveVariationNotFound = @"Not removing variation for user %@, experiment %@. Variation not found.";
132137

133138
@implementation OPTLYLoggerMessages
134139

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@
1717
#import <Foundation/Foundation.h>
1818
#import <JSONModel/JSONModelLib.h>
1919

20-
<<<<<<< HEAD
2120
@class OPTLYAttribute, OPTLYAudience, OPTLYBucketer, OPTLYEvent, OPTLYExperiment, OPTLYGroup, OPTLYVariation, OPTLYVariable;
2221
@protocol OPTLYAttribute, OPTLYAudience, OPTLYBucketer, OPTLYErrorHandler, OPTLYEvent, OPTLYExperiment, OPTLYGroup, OPTLYLogger, OPTLYUserProfile, OPTLYVariable, OPTLYVariation;
23-
=======
24-
@class OPTLYExperiment, OPTLYGroup, OPTLYEvent, OPTLYAttribute, OPTLYAudience, OPTLYVariation, OPTLYVariable, OPTLYBucketer;
25-
@protocol OPTLYExperiment, OPTLYEvent, OPTLYAudience, OPTLYAttribute, OPTLYGroup, OPTLYVariable, OPTLYLogger, OPTLYErrorHandler, OPTLYBucketer;
26-
>>>>>>> Introduce live variable class and getters (#35)
2722

2823
/*
2924
This class represents all the data contained in the project datafile
@@ -69,7 +64,6 @@
6964
withLogger:(nullable id<OPTLYLogger>)logger
7065
withErrorHandler:(nullable id<OPTLYErrorHandler>)errorHandler
7166
withUserProfile:(nullable id<OPTLYUserProfile>)userProfile;
72-
7367
/**
7468
* Get an Experiment object for a key.
7569
*/

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
#import "OPTLYUserProfile.h"
3131
#import "OPTLYVariable.h"
3232
#import "OPTLYUserProfile.h"
33+
<<<<<<< HEAD
3334
=======
3435
#import "OPTLYVariable.h"
3536
>>>>>>> Introduce live variable class and getters (#35)
37+
=======
38+
>>>>>>> User profile feature.
3639

3740
NSString * const kClientEngine = @"objective-c-sdk-core";
3841

@@ -90,6 +93,7 @@ - (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
9093

9194
if (userProfile) {
9295
if ([OPTLYUserProfile conformsToOPTLYUserProfileProtocol:[userProfile class]]) {
96+
<<<<<<< HEAD
9397
_userProfile = (id<OPTLYUserProfile, Ignore>)userProfile;
9498
} else {
9599
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain
@@ -101,6 +105,11 @@ - (nullable instancetype)initWithDatafile:(nullable NSData *)datafile
101105
NSString *logMessage = OPTLYErrorHandlerMessagesUserProfileInvalid;
102106
[_logger logMessage:logMessage withLevel:OptimizelyLogLevelError];
103107
}
108+
=======
109+
_userProfile = userProfile;
110+
}
111+
// TODO - log error
112+
>>>>>>> User profile feature.
104113
}
105114

106115
OPTLYProjectConfig* projectConfig = nil;

OptimizelySDKUserProfile/OptimizelySDKUserProfileTests/OptimizelySDKUserProfileTests.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ - (void)setUp {
4848
}];
4949
[self.userProfile save:kUserId1 experiment:kExperimentKey1 variation:kVariationKey1];
5050
[self.userProfile save:kUserId2 experiment:kExperimentKey2 variation:kVariationKey2];
51+
<<<<<<< HEAD
5152
[self.userProfile save:kUserId3 experiment:kExperimentKey3a variation:kVariationKey3a];
5253
[self.userProfile save:kUserId3 experiment:kExperimentKey3b variation:kVariationKey3b];
5354
[self.userProfile save:kUserId3 experiment:kExperimentKey3c variation:kVariationKey3c];
55+
=======
56+
[self.userProfile save:kUserId3 experiment:kExperimentKey3 variation:kVariationKey3];
57+
>>>>>>> User profile feature.
5458
[super setUp];
5559
}
5660

@@ -65,7 +69,11 @@ - (void)testUserProfileInitWithBuilderBlock
6569
XCTAssert([self.userProfile.logger isKindOfClass:[OPTLYLoggerDefault class]]);
6670
}
6771

72+
<<<<<<< HEAD
6873
- (void)testSaveUserData
74+
=======
75+
- (void)testSave
76+
>>>>>>> User profile feature.
6977
{
7078
NSDictionary *userData = [self.userProfile.dataStore getUserDataForType:OPTLYDataStoreDataTypeUserProfile];
7179
NSArray *users = [userData allKeys];
@@ -108,6 +116,7 @@ - (void)testGetVariation
108116

109117
NSString *variationKey3c = [self.userProfile getVariationFor:kUserId3 experiment:kExperimentKey3c];
110118
XCTAssert([variationKey3c isEqualToString:kVariationKey3c], @"Invalid variation for userId 3c for getVariation.");
119+
111120
}
112121

113122
- (void)testRemoveVariation
@@ -121,6 +130,7 @@ - (void)testRemoveVariation
121130
XCTAssertNotNil(variationKey2, @"Variation for userId 1 should not have been removed.");
122131

123132
[self.userProfile remove:kUserId3 experiment:kExperimentKey2];
133+
124134
NSString *variationKey3a = [self.userProfile getVariationFor:kUserId3 experiment:kExperimentKey3a];
125135
XCTAssertNotNil(variationKey3a, @"Variation for userId 3a should not have been removed.");
126136

0 commit comments

Comments
 (0)