Skip to content

Commit 5dac265

Browse files
Cleaned up logs.
1 parent 98f3e04 commit 5dac265

File tree

2 files changed

+39
-63
lines changed

2 files changed

+39
-63
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYHTTPRequestManager.m

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ - (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.
114105
if (completion) {
115106
completion(data, response, error);
116107
}

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,15 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616

17-
<<<<<<< HEAD
18-
<<<<<<< HEAD
1917
#import <UIKit/UIKit.h>
2018
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
2119
#import <OptimizelySDKCore/OPTLYLog.h>
2220
#import <OptimizelySDKCore/OPTLYLogger.h>
2321
#import <OptimizelySDKShared/OPTLYDataStore.h>
2422
#import <OptimizelySDKShared/OPTLYNetworkService.h>
2523
#import "OPTLYDatafileManager.h"
26-
=======
27-
#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.
32-
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
33-
#import <OptimizelySDKShared/OPTLYDataStore.h>
34-
<<<<<<< HEAD
35-
>>>>>>> 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.
4024

41-
NSTimeInterval const kDefaultDatafileFetchInterval = 0;
25+
NSTimeInterval const kDefaultDatafileFetchInterval_s = 120;
4226

4327
@interface OPTLYDatafileManager ()
4428
@property (nonatomic, strong) OPTLYDataStore *dataStore;
@@ -56,7 +40,7 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
5640
if (builder != nil) {
5741
self = [super init];
5842
if (self != nil) {
59-
_datafileFetchInterval = kDefaultDatafileFetchInterval;
43+
_datafileFetchInterval = kDefaultDatafileFetchInterval_s;
6044
_datafileFetchInterval = builder.datafileFetchInterval;
6145
_projectId = builder.projectId;
6246
_errorHandler = builder.errorHandler;
@@ -77,50 +61,50 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
7761
}
7862

7963
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
80-
8164
NSString *logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloading, projectId];
8265
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
8366

8467
NSString *lastSavedModifiedDate = [self getLastModifiedDate:projectId];
8568
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifiedDate, lastSavedModifiedDate];
8669
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
87-
70+
8871
[self.networkService downloadProjectConfig:self.projectId
8972
lastModified:lastSavedModifiedDate
9073
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
91-
92-
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
93-
NSInteger statusCode = [httpResponse statusCode];
94-
NSString *logMessage = @"";
95-
if (error != nil) {
96-
[self.errorHandler handleError:error];
97-
}
98-
else if (statusCode == 200) { // got datafile OK
99-
[self saveDatafile:data];
100-
101-
// save the last modified date
102-
NSDictionary *dictionary = [httpResponse allHeaderFields];
103-
NSString *lastModifiedDate = [dictionary valueForKey:@"Last-Modified"];
104-
[self saveLastModifiedDate:lastModifiedDate project:projectId];
105-
106-
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloaded, projectId, lastModifiedDate];
107-
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
108-
}
109-
else if (statusCode == 304) {
110-
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedNoChanges, projectId];
111-
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
112-
}
113-
else {
114-
// TODO: Josh W. handle bad response
115-
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedError, projectId, error];
116-
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
117-
}
118-
119-
// call the completion handler
120-
if (completion != nil) {
121-
completion(data, response, error);
122-
}
123-
}];
74+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
75+
NSInteger statusCode = [httpResponse statusCode];
76+
NSString *logMessage = @"";
77+
if (error != nil) {
78+
[self.errorHandler handleError:error];
79+
}
80+
else if (statusCode == 200) { // got datafile OK
81+
[self saveDatafile:data];
82+
83+
// save the last modified date
84+
NSDictionary *dictionary = [httpResponse allHeaderFields];
85+
NSString *lastModifiedDate = [dictionary valueForKey:@"Last-Modified"];
86+
[self saveLastModifiedDate:lastModifiedDate project:projectId];
87+
88+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileDownloaded, projectId, lastModifiedDate];
89+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelInfo];
90+
}
91+
else if (statusCode == 304) {
92+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedNoChanges, projectId];
93+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
94+
}
95+
else {
96+
// TODO: Josh W. handle bad response
97+
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerDatafileNotDownloadedError, projectId, error];
98+
[self.logger logMessage:logMessage withLevel:OptimizelyLogLevelDebug];
99+
}
100+
101+
102+
103+
// call the completion handler
104+
if (completion != nil) {
105+
completion(data, response, error);
106+
}
107+
}];
124108
}
125109

126110
- (void)downloadDatafile {
@@ -155,7 +139,7 @@ - (void)saveLastModifiedDate:(nonnull NSString *)lastModifiedDate
155139
- (nullable NSString *)getLastModifiedDate:(nonnull NSString *)projectId {
156140
NSDictionary *userData = [self.dataStore getUserDataForType:OPTLYDataStoreDataTypeDatafile];
157141
NSString *lastModifiedDate = [userData objectForKey:projectId];
158-
142+
159143
NSString *logMessage = @"";
160144
if ([lastModifiedDate length]) {
161145
logMessage = [NSString stringWithFormat:OPTLYLoggerMessagesDatafileManagerLastModifedDate, lastModifiedDate, projectId];
@@ -167,6 +151,7 @@ - (nullable NSString *)getLastModifiedDate:(nonnull NSString *)projectId {
167151
return lastModifiedDate;
168152
}
169153

154+
170155
#pragma mark - Application Lifecycle Handlers
171156
- (void)setupApplicationNotificationHandlers {
172157
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

0 commit comments

Comments
 (0)