Skip to content

Commit f227e5a

Browse files
committed
change request datafile to download datafile with completion handler
1 parent f7d21c9 commit f227e5a

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
@protocol OPTLYDatafileManager <NSObject>
2525

2626
/**
27-
* Request the datafile for the project ID
27+
* Download the datafile for the project ID
2828
* @param projectId The project ID of the datafile to request.
2929
* @param completion Completion handler.
3030
*/
31-
- (void)requestDatafile:(nonnull NSString *)projectId
32-
completionHandler:(nullable OPTLYHTTPRequestManagerResponse)completion;
31+
- (void)downloadDatafile:(nonnull NSString *)projectId
32+
completionHandler:(nullable OPTLYHTTPRequestManagerResponse)completion;
3333

3434
@end
3535

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
4646
_dataStore = [OPTLYDataStore new];
4747

4848
// download datafile when we start the datafile manager
49-
[self downloadDatafile];
49+
[self downloadDatafile:self.projectId completionHandler:nil];
5050

5151
// Only fetch the datafile if the polling interval is greater than 0
5252
if (self.datafileFetchInterval > 0) {
@@ -60,24 +60,23 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
6060
}
6161
}
6262

63-
- (void)downloadDatafile {
64-
[self requestDatafile:self.projectId
65-
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
66-
if (error != nil) {
67-
// TODO: Josh W. handle errors
68-
}
69-
else if ([(NSHTTPURLResponse *)response statusCode] == 200) { // got datafile OK
70-
[self saveDatafile:data];
71-
}
72-
else {
73-
// TODO: Josh W. handle bad response
74-
}
75-
}];
76-
}
77-
78-
- (void)requestDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
63+
- (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPRequestManagerResponse)completion {
7964
[self.networkService downloadProjectConfig:self.projectId
80-
completionHandler:completion];
65+
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
66+
if (error != nil) {
67+
// TODO: Josh W. handle errors
68+
}
69+
else if ([(NSHTTPURLResponse *)response statusCode] == 200) { // got datafile OK
70+
[self saveDatafile:data];
71+
}
72+
else {
73+
// TODO: Josh W. handle bad response
74+
}
75+
// call the completion handler
76+
if (completion != nil) {
77+
completion(data, response, error);
78+
}
79+
}];
8180
}
8281

8382
- (void)saveDatafile:(NSData *)datafile {

OptimizelySDKDatafileManager/OptimizelySDKDatafileManagerTests/OPTLYDatafileManagerTest.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ - (void)testRequestDatafileHandlesCompletionEvenWithBadRequest {
107107
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitializeClientAsync"];
108108

109109
// request datafile
110-
[datafileManager requestDatafile:datafileManager.projectId
111-
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
112-
completionWasCalled = true;
113-
XCTAssertEqual([(NSHTTPURLResponse *)response statusCode], 400);
114-
[expectation fulfill];
110+
[datafileManager downloadDatafile:datafileManager.projectId
111+
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
112+
completionWasCalled = true;
113+
XCTAssertEqual([(NSHTTPURLResponse *)response statusCode], 400);
114+
[expectation fulfill];
115115
}];
116116

117117
// wait for async start to finish

0 commit comments

Comments
 (0)