Skip to content

Commit 98f3e04

Browse files
First pass at datafile download by checking the 'If-Modified-Since' in the HTTP header.
1 parent c2ad01c commit 98f3e04

File tree

3 files changed

+14
-45
lines changed

3 files changed

+14
-45
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYHTTPRequestManager.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ - (void)GETIfModifiedSince:(nonnull NSString *)lastModifiedDate
102102

103103
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
104104
NSURLSessionDataTask *dataTask = [ephemeralSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
105+
<<<<<<< HEAD
106+
=======
107+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
108+
109+
int responseCode = (int)[httpResponse statusCode];
110+
OPTLYLogInfo(@"All headers: %@", [httpResponse allHeaderFields]);
111+
OPTLYLogInfo(@"Status code:: %d", responseCode);
112+
113+
>>>>>>> First pass at datafile download by checking the 'If-Modified-Since' in the HTTP header.
105114
if (completion) {
106115
completion(data, response, error);
107116
}

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
7777
}
7878

7979
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
80-
<<<<<<< HEAD
80+
8181
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloading, projectId];
8282
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
8383

8484
NSString *lastSavedModifiedDate = [self getLastModifiedDate:projectId];
8585
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifiedDate, lastSavedModifiedDate];
8686
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
87-
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.
87+
9188
[self.networkService downloadProjectConfig:self.projectId
9289
lastModified:lastSavedModifiedDate
9390
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
94-
<<<<<<< HEAD
91+
9592
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
9693
NSInteger statusCode = [httpResponse statusCode];
9794
NSString *logMessage = @"";
@@ -118,37 +115,14 @@ - (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPReque
118115
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedError, projectId, error];
119116
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
120117
}
121-
122-
123-
118+
124119
// call the completion handler
125120
if (completion != nil) {
126121
completion(data, response, error);
127122
}
128123
}];
129124
}
130125

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-
152126
- (void)downloadDatafile {
153127
[self downloadDatafile:self.projectId completionHandler:nil];
154128
}

OptimizelySDKShared/OptimizelySDKShared/OptimizelySDKShared.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,17 @@
1616

1717
#import <OptimizelySDKCore/OptimizelySDKCore.h>
1818
#import "OPTLYClient.h"
19-
<<<<<<< HEAD
2019
#import "OPTLYClientBuilder.h"
21-
#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.
2420
#if TARGET_OS_IOS
2521
#import "OPTLYDatabase.h"
2622
#import "OPTLYDatabaseEntity.h"
2723
#endif
28-
<<<<<<< HEAD
29-
#import "OPTLYFileManager.h"
30-
#import "OPTLYHTTPRequestManager.h"
31-
#import "OPTLYManager.h"
32-
#import "OPTLYManagerBuilder.h"
33-
#import "OPTLYNetworkService.h"
34-
35-
36-
37-
=======
3824
#import "OPTLYDataStore.h"
3925
#import "OPTLYFileManager.h"
4026
#import "OPTLYHTTPRequestManager.h"
4127
#import "OPTLYManager.h"
28+
#import "OPTLYManagerBuilder.h"
4229
#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.
4430

4531
//! Project version number for OptimizelySDKShared.
4632
FOUNDATION_EXPORT double OptimizelySDKSharedVersionNumber;

0 commit comments

Comments
 (0)