Skip to content

Commit c2ad01c

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 baeb208 commit c2ad01c

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
EA8FD0E21DE9798E00D950AD /* OPTLYNetworkService.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0DA1DE9798E00D950AD /* OPTLYNetworkService.m */; };
233233
EA8FD0EA1DE97DD700D950AD /* OPTLYHTTPRequestManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0E71DE97DC000D950AD /* OPTLYHTTPRequestManagerTest.m */; };
234234
EA8FD0EB1DE97DD900D950AD /* OPTLYHTTPRequestManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0E71DE97DC000D950AD /* OPTLYHTTPRequestManagerTest.m */; };
235+
EA8FD0FC1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
236+
EA8FD0FD1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
237+
EA8FD0FE1DEB12A400D950AD /* OPTLYDatafileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */; };
238+
EA8FD0FF1DEB12A400D950AD /* OPTLYDatafileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */; };
235239
/* End PBXBuildFile section */
236240

237241
/* Begin PBXContainerItemProxy section */
@@ -390,6 +394,8 @@
390394
EA8FD0D91DE9798E00D950AD /* OPTLYNetworkService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYNetworkService.h; sourceTree = "<group>"; };
391395
EA8FD0DA1DE9798E00D950AD /* OPTLYNetworkService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYNetworkService.m; sourceTree = "<group>"; };
392396
EA8FD0E71DE97DC000D950AD /* OPTLYHTTPRequestManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYHTTPRequestManagerTest.m; sourceTree = "<group>"; };
397+
EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYDatafileManager.h; sourceTree = "<group>"; };
398+
EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYDatafileManager.m; sourceTree = "<group>"; };
393399
F5B1C4BBC7682A657C92ABD3 /* Pods_OptimizelySDKCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OptimizelySDKCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
394400
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>"; };
395401
/* End PBXFileReference section */
@@ -720,6 +726,13 @@
720726
EA8FD0DA1DE9798E00D950AD /* OPTLYNetworkService.m */,
721727
);
722728
name = Network;
729+
EA8FD0F91DEB120C00D950AD /* Datafile Manager */ = {
730+
isa = PBXGroup;
731+
children = (
732+
EA8FD0FA1DEB12A400D950AD /* OPTLYDatafileManager.h */,
733+
EA8FD0FB1DEB12A400D950AD /* OPTLYDatafileManager.m */,
734+
);
735+
name = "Datafile Manager";
723736
sourceTree = "<group>";
724737
};
725738
/* End PBXGroup section */
@@ -750,6 +763,7 @@
750763
EA8FD0FC1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */,
751764
EA8FD0DB1DE9798E00D950AD /* OPTLYHTTPRequestManager.h in Headers */,
752765
EA8FD0DF1DE9798E00D950AD /* OPTLYNetworkService.h in Headers */,
766+
EA8FD0FC1DEB12A400D950AD /* OPTLYDatafileManager.h in Headers */,
753767
EA2FAB791DC6F5F400B1D81B /* OPTLYMacros.h in Headers */,
754768
EA2FAAF41DC6F57200B1D81B /* OPTLYEventTicket.h in Headers */,
755769
EA2FAB121DC6F57200B1D81B /* OPTLYTrafficAllocation.h in Headers */,

OptimizelySDKCore/OptimizelySDKCore/OPTLYDatafileManager.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ - (void)downloadDatafile:(nonnull NSString *)projectId
3737
if (completion) {
3838
completion(nil, nil, nil);
3939
}
40-
return;
4140
}
4241

4342
@end

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <Foundation/Foundation.h>
1818
#import <OptimizelySDKCore/OPTLYDatafileManager.h>
19-
#import <OptimizelySDKCore/OPTLYDatafileManagerBuilder.h>
19+
#import "OPTLYDatafileManagerBuilder.h"
2020

2121
@protocol OPTLYDatafileManager, OPTLYErrorHandler, OPTLYLogger;
2222

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616

17+
<<<<<<< HEAD
1718
<<<<<<< HEAD
1819
#import <UIKit/UIKit.h>
1920
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
@@ -24,11 +25,18 @@
2425
#import "OPTLYDatafileManager.h"
2526
=======
2627
#import "OPTLYDatafileManager.h"
28+
=======
29+
#import <UIKit/UIKit.h>
30+
#import <OptimizelySDKCore/OPTLYLog.h>
31+
>>>>>>> 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.
2732
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
28-
#import <OptimizelySDKCore/OPTLYLogger.h>
29-
#import <OptimizelySDKCore/OPTLYNetworkService.h>
3033
#import <OptimizelySDKShared/OPTLYDataStore.h>
34+
<<<<<<< HEAD
3135
>>>>>>> Moved the network manager code to the Core. This is needed for basic event dispatch and datafile download.
36+
=======
37+
#import <OptimizelySDKShared/OPTLYNetworkService.h>
38+
#import "OPTLYDatafileManager.h"
39+
>>>>>>> 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.
3240

3341
NSTimeInterval const kDefaultDatafileFetchInterval = 0;
3442

@@ -69,16 +77,21 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
6977
}
7078

7179
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
80+
<<<<<<< HEAD
7281
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloading, projectId];
7382
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
7483

7584
NSString *lastSavedModifiedDate = [self getLastModifiedDate:projectId];
7685
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifiedDate, lastSavedModifiedDate];
7786
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
7887

88+
=======
89+
OPTLYLogInfo(@"Downloading datafile: %@", projectId);
90+
>>>>>>> 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.
7991
[self.networkService downloadProjectConfig:self.projectId
8092
lastModified:lastSavedModifiedDate
8193
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
94+
<<<<<<< HEAD
8295
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
8396
NSInteger statusCode = [httpResponse statusCode];
8497
NSString *logMessage = @"";
@@ -115,6 +128,27 @@ - (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPReque
115128
}];
116129
}
117130

131+
- (void)downloadDatafile {
132+
[self downloadDatafile:self.projectId completionHandler:nil];
133+
=======
134+
if (error != nil) {
135+
[self.errorHandler handleError:error];
136+
}
137+
else if ([(NSHTTPURLResponse *)response statusCode] == 200) { // got datafile OK
138+
[self saveDatafile:data];
139+
OPTLYLogInfo(@"Datafile for project ID %@ downloaded. Saving datafile.");
140+
}
141+
else {
142+
// TODO: Josh W. handle bad response
143+
}
144+
// call the completion handler
145+
if (completion != nil) {
146+
completion(data, response, error);
147+
}
148+
}];
149+
>>>>>>> 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.
150+
}
151+
118152
- (void)downloadDatafile {
119153
[self downloadDatafile:self.projectId completionHandler:nil];
120154
}
@@ -159,7 +193,6 @@ - (nullable NSString *)getLastModifiedDate:(nonnull NSString *)projectId {
159193
return lastModifiedDate;
160194
}
161195

162-
163196
#pragma mark - Application Lifecycle Handlers
164197
- (void)setupApplicationNotificationHandlers {
165198
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

OptimizelySDKDatafileManager/OptimizelySDKDatafileManagerTests/OPTLYDatafileManagerTest.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
static NSString *const kProjectId = @"6372300739";
2525
static NSString *const kDatamodelDatafileName = @"datafile_6372300739";
2626
static NSTimeInterval kDatafileDownloadInteval = 5;
27+
<<<<<<< HEAD
2728
static NSString *const kLastModifiedDate = @"Mon, 28 Nov 2016 06:10:59 GMT";
2829

2930
@interface OPTLYDatafileManager(test)
3031
@property (nonatomic, strong) NSTimer *datafileDownloadTimer;
3132
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion;
33+
=======
34+
35+
@interface OPTLYDatafileManager(test)
36+
@property (nonatomic, strong) NSTimer *datafileDownloadTimer;
37+
>>>>>>> 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.
3238
- (void)saveDatafile:(NSData *)datafile;
3339
- (nullable NSString *)getLastModifiedDate:(nonnull NSString *)projectId;
3440
@end
@@ -226,6 +232,4 @@ - (void)stubResponse:(int)statusCode {
226232
@"Last-Modified":kLastModifiedDate}];
227233
}];
228234
}
229-
230-
231235
@end

OptimizelySDKShared/OptimizelySDKShared/OptimizelySDKShared.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
#import <OptimizelySDKCore/OptimizelySDKCore.h>
1818
#import "OPTLYClient.h"
19+
<<<<<<< HEAD
1920
#import "OPTLYClientBuilder.h"
2021
#import "OPTLYDataStore.h"
22+
=======
23+
>>>>>>> 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.
2124
#if TARGET_OS_IOS
2225
#import "OPTLYDatabase.h"
2326
#import "OPTLYDatabaseEntity.h"
2427
#endif
28+
<<<<<<< HEAD
2529
#import "OPTLYFileManager.h"
2630
#import "OPTLYHTTPRequestManager.h"
2731
#import "OPTLYManager.h"
@@ -30,6 +34,13 @@
3034

3135

3236

37+
=======
38+
#import "OPTLYDataStore.h"
39+
#import "OPTLYFileManager.h"
40+
#import "OPTLYHTTPRequestManager.h"
41+
#import "OPTLYManager.h"
42+
#import "OPTLYNetworkService.h"
43+
>>>>>>> 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.
3344

3445
//! Project version number for OptimizelySDKShared.
3546
FOUNDATION_EXPORT double OptimizelySDKSharedVersionNumber;

0 commit comments

Comments
 (0)