Skip to content

Commit a5629da

Browse files
Added a timer to the datafile manager to periodically download the datafile. Also moved the datafile manager protocol to core as the core should have a basic datafile downloader (the network classes will be moved to core as well in another commit.). Cleaned up the headers and was being more deligent about alphabetizing imports and initializing modules.
1 parent c59e28d commit a5629da

File tree

19 files changed

+210
-60
lines changed

19 files changed

+210
-60
lines changed

OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@
218218
EA87A02B1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EA87A0281DE31453002E9EF7 /* OPTLYUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; };
219219
EA87A02C1DE31453002E9EF7 /* OPTLYUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = EA87A0291DE31453002E9EF7 /* OPTLYUserProfile.m */; };
220220
EA87A02D1DE31453002E9EF7 /* OPTLYUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = EA87A0291DE31453002E9EF7 /* OPTLYUserProfile.m */; };
221+
EA8FD0FC1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
222+
EA8FD0FD1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
223+
EA8FD0FE1DEB12A400D950AD /* OPTLYDatafileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */; };
224+
EA8FD0FF1DEB12A400D950AD /* OPTLYDatafileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */; };
221225
/* End PBXBuildFile section */
222226

223227
/* Begin PBXContainerItemProxy section */
@@ -369,6 +373,8 @@
369373
EA5249631DC7B69A00AF6685 /* OPTLYEventDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYEventDispatcher.m; sourceTree = "<group>"; };
370374
EA87A0281DE31453002E9EF7 /* OPTLYUserProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OPTLYUserProfile.h; path = OptimizelySDKCore/OPTLYUserProfile.h; sourceTree = "<group>"; };
371375
EA87A0291DE31453002E9EF7 /* OPTLYUserProfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OPTLYUserProfile.m; path = OptimizelySDKCore/OPTLYUserProfile.m; sourceTree = "<group>"; };
376+
EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYDatafileManager.h; sourceTree = "<group>"; };
377+
EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYDatafileManager.m; sourceTree = "<group>"; };
372378
F5B1C4BBC7682A657C92ABD3 /* Pods_OptimizelySDKCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OptimizelySDKCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
373379
F6CC17F155793CF43AB7A3D9 /* Pods-OptimizelySDKCoreTVOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelySDKCoreTVOS.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-OptimizelySDKCoreTVOS/Pods-OptimizelySDKCoreTVOS.debug.xcconfig"; sourceTree = "<group>"; };
374380
/* End PBXFileReference section */
@@ -627,9 +633,10 @@
627633
EA2FA83F1DC5E11F00B1D81B /* Bucketer */,
628634
EA2FA90B1DC6F17400B1D81B /* Builder */,
629635
EA2FA8401DC5E13A00B1D81B /* Data Models */,
636+
EA8FD0F91DEB120C00D950AD /* Datafile Manager */,
630637
EA2FA8411DC5E14700B1D81B /* Error Handler */,
631638
EA2FA8421DC5E15700B1D81B /* Event Builder */,
632-
EA5249611DC7B64C00AF6685 /* EventDispatcher */,
639+
EA5249611DC7B64C00AF6685 /* Event Dispatcher */,
633640
EA87A0271DE3142A002E9EF7 /* UserProfile */,
634641
EA2FA8451DC5E1A300B1D81B /* Loggers */,
635642
EA2FA83D1DC5E0E900B1D81B /* Utilities */,
@@ -661,13 +668,13 @@
661668
path = OptimizelySDKCoreTests;
662669
sourceTree = "<group>";
663670
};
664-
EA5249611DC7B64C00AF6685 /* EventDispatcher */ = {
671+
EA5249611DC7B64C00AF6685 /* Event Dispatcher */ = {
665672
isa = PBXGroup;
666673
children = (
667674
EA5249621DC7B69A00AF6685 /* OPTLYEventDispatcher.h */,
668675
EA5249631DC7B69A00AF6685 /* OPTLYEventDispatcher.m */,
669676
);
670-
name = EventDispatcher;
677+
name = "Event Dispatcher";
671678
sourceTree = "<group>";
672679
};
673680
EA87A0271DE3142A002E9EF7 /* UserProfile */ = {
@@ -680,6 +687,15 @@
680687
path = ..;
681688
sourceTree = "<group>";
682689
};
690+
EA8FD0F91DEB120C00D950AD /* Datafile Manager */ = {
691+
isa = PBXGroup;
692+
children = (
693+
EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */,
694+
EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */,
695+
);
696+
name = "Datafile Manager";
697+
sourceTree = "<group>";
698+
};
683699
/* End PBXGroup section */
684700

685701
/* Begin PBXHeadersBuildPhase section */
@@ -705,6 +721,7 @@
705721
EA2C242D1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */,
706722
EA87A02A1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */,
707723
EA064BC71DD3FC8800DF7537 /* OPTLYQueue.h in Headers */,
724+
EA8FD0FC1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */,
708725
EA2FAB791DC6F5F400B1D81B /* OPTLYMacros.h in Headers */,
709726
EA2FAAF41DC6F57200B1D81B /* OPTLYEventTicket.h in Headers */,
710727
EA2FAB121DC6F57200B1D81B /* OPTLYTrafficAllocation.h in Headers */,
@@ -753,6 +770,7 @@
753770
EA2FAB741DC6F5F400B1D81B /* OPTLYLog.h in Headers */,
754771
EA87A02B1DE31453002E9EF7 /* OPTLYUserProfile.h in Headers */,
755772
EA064BC81DD3FC8800DF7537 /* OPTLYQueue.h in Headers */,
773+
EA8FD0FD1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */,
756774
EA2C242E1DE6A2470063ADA0 /* OPTLYProjectConfigBuilder.h in Headers */,
757775
EA2FAC7B1DC70EBC00B1D81B /* murmur3.h in Headers */,
758776
EA2FAB7A1DC6F5F400B1D81B /* OPTLYMacros.h in Headers */,
@@ -1153,6 +1171,7 @@
11531171
EA2FAC261DC6FFC600B1D81B /* OPTLYLoggerMessages.m in Sources */,
11541172
EA2FAC291DC6FFC600B1D81B /* OPTLYLog.m in Sources */,
11551173
EA2C24351DE7887C0063ADA0 /* OPTLYVariationVariable.m in Sources */,
1174+
EA8FD0FE1DEB12A400D950AD /* OPTLYDatafileManager.m in Sources */,
11561175
EA2FAC2A1DC6FFC600B1D81B /* OPTLYValidator.m in Sources */,
11571176
);
11581177
runOnlyForDeploymentPostprocessing = 0;
@@ -1221,6 +1240,7 @@
12211240
EA2FAC011DC6FFA100B1D81B /* OPTLYLoggerMessages.m in Sources */,
12221241
EA2FAC041DC6FFA100B1D81B /* OPTLYLog.m in Sources */,
12231242
EA2C24361DE7887C0063ADA0 /* OPTLYVariationVariable.m in Sources */,
1243+
EA8FD0FF1DEB12A400D950AD /* OPTLYDatafileManager.m in Sources */,
12241244
EA2FAC051DC6FFA100B1D81B /* OPTLYValidator.m in Sources */,
12251245
);
12261246
runOnlyForDeploymentPostprocessing = 0;

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#import <Foundation/Foundation.h>
1818

1919
@class OPTLYBucketer, OPTLYEventBuilder, OPTLYEventBuilderDefault, OPTLYProjectConfig;
20-
@protocol OPTLYErrorHandler, OPTLYEventBuilder, OPTLYEventDispatcher, OPTLYLogger, OPTLYProjectConfig, OPTLYUserProfile;
20+
@protocol OPTLYDatafileManager, OPTLYErrorHandler, OPTLYEventBuilder, OPTLYEventDispatcher, OPTLYLogger, OPTLYUserProfile;
2121

2222
/**
2323
* This class contains the information on how your Optimizely instance will be built.
@@ -46,6 +46,8 @@ typedef void (^OPTLYBuilderBlock)(OPTLYBuilder * _Nullable builder);
4646
@property (nonatomic, readwrite, strong, nullable) id<OPTLYLogger> logger;
4747
/// User profile stores user-specific data, like bucketing.
4848
@property (nonatomic, readwrite, strong, nullable) id<OPTLYUserProfile> userProfile;
49+
/// The datafile manager that will download the datafile for the manager
50+
@property (nonatomic, readwrite, strong, nullable) id<OPTLYDatafileManager> datafileManager;
4951

5052
/// Create an Optimizely Builder object.
5153
+ (nullable instancetype)builderWithBlock:(nonnull OPTLYBuilderBlock)block;

OptimizelySDKCore/OptimizelySDKCore/OPTLYBuilder.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#import "OPTLYBucketer.h"
1818
#import "OPTLYBuilder.h"
19+
#import "OPTLYDatafileManager.h"
1920
#import "OPTLYErrorHandler.h"
2021
#import "OPTLYEventBuilder.h"
2122
#import "OPTLYEventDispatcher.h"
@@ -85,6 +86,13 @@ - (NSData *)datafile {
8586
return _datafile;
8687
}
8788

89+
- (id<OPTLYDatafileManager>)datafileManager {
90+
if (!_datafileManager) {
91+
_datafileManager = [[OPTLYDatafileManagerNoOp alloc] init];
92+
}
93+
return _datafileManager;
94+
}
95+
8896
- (id<OPTLYErrorHandler>)errorHandler {
8997
if (!_errorHandler) {
9098
_errorHandler = [[OPTLYErrorHandlerNoOp alloc] init];

OptimizelySDKShared/OptimizelySDKShared/OPTLYDatafileManager.h renamed to OptimizelySDKCore/OptimizelySDKCore/OPTLYDatafileManager.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
***************************************************************************/
1616

1717
#import <Foundation/Foundation.h>
18-
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
19-
#import <OptimizelySDKCore/OPTLYLogger.h>
20-
#import <OptimizelySDKShared/OPTLYHTTPRequestManager.h>
21-
22-
23-
@protocol OPTLYErrorHandler, OPTLYLogger;
2418

2519
@protocol OPTLYDatafileManager <NSObject>
2620

@@ -30,7 +24,7 @@
3024
* @param completion Completion handler.
3125
*/
3226
- (void)downloadDatafile:(nonnull NSString *)projectId
33-
completionHandler:(nullable OPTLYHTTPRequestManagerResponse)completion;
27+
completionHandler:(nullable void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completion;
3428

3529
@end
3630

OptimizelySDKShared/OptimizelySDKShared/OPTLYDatafileManager.m renamed to OptimizelySDKCore/OptimizelySDKCore/OPTLYDatafileManager.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ + (BOOL)conformsToOPTLYDatafileManagerProtocol:(Class)instanceClass {
3232

3333
@implementation OPTLYDatafileManagerNoOp
3434

35-
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
35+
- (void)downloadDatafile:(nonnull NSString *)projectId
36+
completionHandler:(nullable void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completion {
3637
completion(nil, nil, nil);
3738
return;
3839
}

OptimizelySDKCore/OptimizelySDKCore/Optimizely.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#import "OPTLYBuilder.h"
1919

2020
@class OPTLYProjectConfig, OPTLYVariation;
21-
@protocol OPTLYBucketer, OPTLYErrorHandler, OPTLYEventBuilder, OPTLYEventDispatcher, OPTLYLogger;
21+
@protocol OPTLYBucketer, OPTLYDatafileManager, OPTLYErrorHandler, OPTLYEventBuilder, OPTLYEventDispatcher, OPTLYLogger;
2222

2323
// ---- Live Variable Getter Errors ----
2424

@@ -220,8 +220,9 @@ typedef NS_ENUM(NSInteger, OPTLYLiveVariableError) {
220220
*/
221221
@interface Optimizely : NSObject <Optimizely>
222222

223-
@property (nonatomic, strong, readonly, nullable) OPTLYProjectConfig *config;
224223
@property (nonatomic, strong, readonly, nullable) id<OPTLYBucketer> bucketer;
224+
@property (nonatomic, strong, readonly, nullable) OPTLYProjectConfig *config;
225+
@property (nonatomic, strong, readonly, nullable) id<OPTLYDatafileManager> datafileManager;
225226
@property (nonatomic, strong, readonly, nullable) id<OPTLYErrorHandler> errorHandler;
226227
@property (nonatomic, strong, readonly, nullable) id<OPTLYEventBuilder> eventBuilder;
227228
@property (nonatomic, strong, readonly, nullable) id<OPTLYEventDispatcher> eventDispatcher;

OptimizelySDKCore/OptimizelySDKCore/Optimizely.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ - (instancetype)initWithBuilder:(OPTLYBuilder *)builder {
5151
if (builder != nil) {
5252
self = [super init];
5353
if (self != nil) {
54-
_config = builder.config;
5554
_bucketer = builder.bucketer;
56-
_errorHandler = builder.errorHandler;
55+
_config = builder.config;
56+
_datafileManager = builder.datafileManager;
5757
_eventBuilder = builder.eventBuilder;
5858
_eventDispatcher = builder.eventDispatcher;
59+
_errorHandler = builder.errorHandler;
5960
_logger = builder.logger;
6061
_userProfile = builder.userProfile;
6162
}

OptimizelySDKCore/OptimizelySDKCore/OptimizelySDKCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "Optimizely.h"
1818
#import "OPTLYBucketer.h"
1919
#import "OPTLYBuilder.h"
20+
#import "OPTLYDatafileManager.h"
2021
#import "OPTLYErrorHandler.h"
2122
#import "OPTLYErrorHandlerMessages.h"
2223
#import "OPTLYEventBuilder.h"

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYBuilderTest.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
***************************************************************************/
1616

1717
#import <XCTest/XCTest.h>
18-
#import "OPTLYTestHelper.h"
19-
2018
#import "Optimizely.h"
19+
#import "OPTLYDatafileManager.h"
2120
#import "OPTLYErrorHandler.h"
2221
#import "OPTLYEventDispatcher.h"
2322
#import "OPTLYLogger.h"
23+
#import "OPTLYTestHelper.h"
2424

2525
// static data from datafile
2626
static NSString * const kDataModelDatafileName = @"datafile_6372300739";
@@ -45,6 +45,7 @@ - (void)testBuilderBuildsDefaults {
4545
XCTAssertNotNil(optimizely);
4646
XCTAssertNotNil(optimizely.bucketer);
4747
XCTAssertNotNil(optimizely.config);
48+
XCTAssertNotNil(optimizely.datafileManager);
4849
XCTAssertNotNil(optimizely.errorHandler);
4950
XCTAssertNotNil(optimizely.eventBuilder);
5051
XCTAssertNotNil(optimizely.eventDispatcher);
@@ -108,6 +109,21 @@ - (void)testBuilderCanAssignLogger {
108109
XCTAssertEqual(logger, customOptimizely.logger, @"Should be the same object with custom builder");
109110
}
110111

112+
- (void)testBuilderCanAssignDatafileManager {
113+
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDataModelDatafileName];
114+
115+
id<OPTLYDatafileManager> datafileManager = [OPTLYDatafileManagerNoOp new];
116+
117+
Optimizely *customOptimizely = [Optimizely initWithBuilderBlock:^(OPTLYBuilder *builder) {
118+
builder.datafile = datafile;
119+
builder.datafileManager = datafileManager;
120+
}];
121+
122+
XCTAssertNotNil(customOptimizely);
123+
XCTAssertNotNil(customOptimizely.datafileManager);
124+
XCTAssertEqualObjects(datafileManager, customOptimizely.datafileManager, @"Should be same object with custom Builder");
125+
}
126+
111127
- (void)testInitializationWithoutBuilder {
112128
Optimizely *optimizely = [Optimizely initWithBuilderBlock:nil];
113129
XCTAssertNil(optimizely);

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
***************************************************************************/
1616

1717
#import <Foundation/Foundation.h>
18-
#import <OptimizelySDKShared/OPTLYDatafileManager.h>
19-
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
20-
#import <OptimizelySDKShared/OPTLYHTTPRequestManager.h>
21-
#import <OptimizelySDKCore/OPTLYLogger.h>
18+
#import <OptimizelySDKCore/OPTLYDatafileManager.h>
2219
#import "OPTLYDatafileManagerBuilder.h"
2320

24-
@protocol OPTLYErrorHandler, OPTLYLogger;
21+
@protocol OPTLYDatafileManager, OPTLYErrorHandler, OPTLYLogger;
2522

2623
@interface OPTLYDatafileManager : NSObject<OPTLYDatafileManager>
2724

0 commit comments

Comments
 (0)