Skip to content

Commit 5fe95eb

Browse files
authored
additions for handling lprequest through request sender (#199)
1 parent c06243f commit 5fe95eb

File tree

12 files changed

+517
-76
lines changed

12 files changed

+517
-76
lines changed

Leanplum-SDK/Classes/Features/Actions/LPActionManager.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ - (void)leanplum_application:(UIApplication *)application didRegisterForRemoteNo
8989

9090
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
9191
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
92-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_SET_DEVICE_ATTRIBUTES
92+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_SET_DEVICE_ATTRIBUTES
9393
params:@{LP_PARAM_DEVICE_PUSH_TOKEN: formattedToken}];
94-
[[LPRequestSender sharedInstance] sendRequest:req];
94+
[[LPRequestSender sharedInstance] sendRequest:request];
9595
}
9696
LP_END_TRY
9797

@@ -342,8 +342,8 @@ - (void)sendUserNotificationSettingsIfChanged:(UIUserNotificationSettings *)noti
342342
LP_END_USER_CODE
343343
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
344344
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
345-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_SET_DEVICE_ATTRIBUTES params:params];
346-
[[LPRequestSender sharedInstance] sendRequest:req];
345+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_SET_DEVICE_ATTRIBUTES params:params];
346+
[[LPRequestSender sharedInstance] sendRequest:request];
347347
LP_BEGIN_USER_CODE
348348
}];
349349
}
@@ -369,13 +369,13 @@ - (void)requireMessageContent:(NSString *)messageId
369369
} else {
370370
// Try downloading the messages again if it doesn't exist.
371371
// Maybe the message was created while the app was running.
372-
id<LPRequesting> req = [LeanplumRequest
372+
id<LPRequesting> request = [LeanplumRequest
373373
post:LP_METHOD_GET_VARS
374374
params:@{
375375
LP_PARAM_INCLUDE_DEFAULTS: @(NO),
376376
LP_PARAM_INCLUDE_MESSAGE_ID: messageId
377377
}];
378-
[req onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
378+
[request onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
379379
LP_TRY
380380
NSDictionary *values = response[LP_KEY_VARS];
381381
NSDictionary *messages = response[LP_KEY_MESSAGES];
@@ -413,7 +413,7 @@ - (void)requireMessageContent:(NSString *)messageId
413413
}
414414
LP_END_TRY
415415
}];
416-
[[LPRequestSender sharedInstance] sendIfConnectedRequest:req];
416+
[[LPRequestSender sharedInstance] sendIfConnected:request];
417417
}
418418
LP_BEGIN_USER_CODE
419419
}];

Leanplum-SDK/Classes/Features/Inbox/LPInbox.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ - (void)read
191191
NSDictionary *params = @{LP_PARAM_INBOX_MESSAGE_ID: [self messageId]};
192192
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
193193
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
194-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_MARK_INBOX_MESSAGE_AS_READ
194+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_MARK_INBOX_MESSAGE_AS_READ
195195
params:params];
196-
[[LPRequestSender sharedInstance] sendRequest:req];
196+
[[LPRequestSender sharedInstance] sendRequest:request];
197197
LP_END_TRY
198198
}
199199

@@ -372,9 +372,9 @@ - (void)removeMessageForId:(NSString *)messageId
372372
NSDictionary *params = @{LP_PARAM_INBOX_MESSAGE_ID:messageId};
373373
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
374374
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
375-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_DELETE_INBOX_MESSAGE
375+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_DELETE_INBOX_MESSAGE
376376
params:params];
377-
[[LPRequestSender sharedInstance] sendRequest:req];
377+
[[LPRequestSender sharedInstance] sendRequest:request];
378378
LP_END_TRY
379379
}
380380

@@ -420,8 +420,8 @@ - (void)downloadMessages
420420
LP_TRY
421421
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
422422
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
423-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_GET_INBOX_MESSAGES params:nil];
424-
[req onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
423+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_GET_INBOX_MESSAGES params:nil];
424+
[request onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
425425
LP_TRY
426426
NSDictionary *messagesDict = response[LP_KEY_INBOX_MESSAGES];
427427
NSUInteger unreadCount = 0;
@@ -470,10 +470,10 @@ - (void)downloadMessages
470470
}
471471
LP_END_TRY
472472
}];
473-
[req onError:^(NSError *error) {
473+
[request onError:^(NSError *error) {
474474
[self triggerInboxSyncedWithStatus:NO];
475475
}];
476-
[[LPRequestSender sharedInstance] sendIfConnectedRequest:req];
476+
[[LPRequestSender sharedInstance] sendIfConnected:request];
477477
LP_END_TRY
478478
}
479479

Leanplum-SDK/Classes/Features/Variables/LPVarCache.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ - (BOOL)sendContentIfChanged:(BOOL)variables actions:(BOOL)actions
660660
args[LP_PARAM_FILE_ATTRIBUTES] = [LPJSON stringFromJSON:limitedFileAttributes];
661661
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
662662
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
663-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_SET_VARS
663+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_SET_VARS
664664
params:args];
665-
[[LPRequestSender sharedInstance] sendRequest:req];
665+
[[LPRequestSender sharedInstance] sendRequest:request];
666666
return YES;
667667
} @catch (NSException *e) {
668668
[Leanplum throwError:@"Cannot serialize variable values. "

Leanplum-SDK/Classes/Internal/Constants.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ void leanplumInternalError(NSException *e)
319319
@try {
320320
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
321321
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
322-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_LOG
322+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_LOG
323323
params:@{
324324
LP_PARAM_TYPE: LP_VALUE_SDK_ERROR,
325325
LP_PARAM_MESSAGE: [e description],
326326
@"stackTrace": [[e callStackSymbols] description] ?: @"",
327327
LP_PARAM_VERSION_NAME: versionName
328328
}];
329-
[[LPRequestSender sharedInstance] sendRequest:req];
329+
[[LPRequestSender sharedInstance] sendRequest:request];
330330
} @catch (NSException *e) {
331331
// This empty try/catch is needed to prevent crash <-> loop.
332332
}

Leanplum-SDK/Classes/Internal/Leanplum.m

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,8 @@ + (void)startWithUserId:(NSString *)userId
864864
// Issue start API call.
865865
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
866866
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
867-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_START params:params];
868-
[req onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
867+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_START params:params];
868+
[request onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
869869
LP_TRY
870870
state.hasStarted = YES;
871871
state.startSuccessful = YES;
@@ -945,12 +945,12 @@ + (void)startWithUserId:(NSString *)userId
945945
if (arc4random() % 1000 == 0) {
946946
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
947947
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
948-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_LOG
948+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_LOG
949949
params:@{
950950
LP_PARAM_TYPE: LP_VALUE_SDK_START_LATENCY,
951951
@"startLatency": [@(latency) description]
952952
}];
953-
[[LPRequestSender sharedInstance] sendRequest:req];
953+
[[LPRequestSender sharedInstance] sendRequest:request];
954954
}
955955
}
956956

@@ -968,7 +968,7 @@ + (void)startWithUserId:(NSString *)userId
968968
}
969969
LP_END_TRY
970970
}];
971-
[req onError:^(NSError *err) {
971+
[request onError:^(NSError *err) {
972972
LP_TRY
973973
state.hasStarted = YES;
974974
state.startSuccessful = NO;
@@ -979,7 +979,7 @@ + (void)startWithUserId:(NSString *)userId
979979

980980
[self triggerStartResponse:NO];
981981
}];
982-
[[LPRequestSender sharedInstance] sendIfConnectedRequest:req];
982+
[[LPRequestSender sharedInstance] sendIfConnected:request];
983983
[self triggerStartIssued];
984984

985985
// Pause.
@@ -1044,8 +1044,8 @@ + (void)startWithUserId:(NSString *)userId
10441044
objectForKey:@"UIApplicationExitsOnSuspend"] boolValue];
10451045
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
10461046
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
1047-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_STOP params:nil];
1048-
[[LPRequestSender sharedInstance] sendIfConnectedSync:exitOnSuspend request:req];
1047+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_STOP params:nil];
1048+
[[LPRequestSender sharedInstance] sendIfConnected:request sync:exitOnSuspend];
10491049
LP_END_TRY
10501050
}];
10511051

@@ -1056,8 +1056,8 @@ + (void)startWithUserId:(NSString *)userId
10561056
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
10571057
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
10581058
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
1059-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_HEARTBEAT params:nil];
1060-
[[LPRequestSender sharedInstance] sendIfDelayedRequest:req];
1059+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_HEARTBEAT params:nil];
1060+
[[LPRequestSender sharedInstance] sendIfDelayed:request];
10611061

10621062
}
10631063
LP_END_TRY
@@ -1160,15 +1160,15 @@ + (void)pause
11601160
[request onError:^(NSError *error) {
11611161
finishTaskHandler();
11621162
}];
1163-
[[LPRequestSender sharedInstance] sendIfConnectedRequest:request];
1163+
[[LPRequestSender sharedInstance] sendIfConnected:request];
11641164
}
11651165

11661166
+ (void)resume
11671167
{
11681168
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
11691169
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
11701170
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_RESUME_SESSION params:nil];
1171-
[[LPRequestSender sharedInstance] sendIfDelayedRequest:request];
1171+
[[LPRequestSender sharedInstance] sendIfDelayed:request];
11721172
}
11731173

11741174
+ (void)trackCrashes
@@ -1909,8 +1909,8 @@ + (void)trackInternal:(NSString *)event withArgs:(NSDictionary *)args
19091909
{
19101910
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
19111911
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
1912-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_TRACK params:args];
1913-
[[LPRequestSender sharedInstance] sendRequest:req];
1912+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_TRACK params:args];
1913+
[[LPRequestSender sharedInstance] sendRequest:request];
19141914

19151915
// Perform event actions.
19161916
NSString *messageId = args[LP_PARAM_MESSAGE_ID];
@@ -2042,11 +2042,11 @@ + (void)setUserIdInternal:(NSString *)userId withAttributes:(NSDictionary *)attr
20422042

20432043
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
20442044
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2045-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_SET_USER_ATTRIBUTES params:@{
2045+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_SET_USER_ATTRIBUTES params:@{
20462046
LP_PARAM_USER_ATTRIBUTES: attributes ? [LPJSON stringFromJSON:attributes] : @"",
20472047
LP_PARAM_NEW_USER_ID: userId ? userId : @""
20482048
}];
2049-
[[LPRequestSender sharedInstance] sendRequest:req];
2049+
[[LPRequestSender sharedInstance] sendRequest:request];
20502050

20512051
if (userId.length) {
20522052
[[LPAPIConfig sharedConfig] setUserId:userId];
@@ -2118,10 +2118,10 @@ + (void)setTrafficSourceInfoInternal:(NSDictionary *)info
21182118
{
21192119
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
21202120
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2121-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_SET_TRAFFIC_SOURCE_INFO params:@{
2121+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_SET_TRAFFIC_SOURCE_INFO params:@{
21222122
LP_PARAM_TRAFFIC_SOURCE: info
21232123
}];
2124-
[[LPRequestSender sharedInstance] sendRequest:req];
2124+
[[LPRequestSender sharedInstance] sendRequest:request];
21252125
}
21262126

21272127
+ (void)advanceTo:(NSString *)state
@@ -2173,8 +2173,8 @@ + (void)advanceToInternal:(NSString *)state withArgs:(NSDictionary *)args
21732173
{
21742174
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
21752175
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2176-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_ADVANCE params:args];
2177-
[[LPRequestSender sharedInstance] sendRequest:req];
2176+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_ADVANCE params:args];
2177+
[[LPRequestSender sharedInstance] sendRequest:request];
21782178
LPContextualValues *contextualValues = [[LPContextualValues alloc] init];
21792179
contextualValues.parameters = params;
21802180
[self maybePerformActions:@[@"state"]
@@ -2202,8 +2202,8 @@ + (void)pauseStateInternal
22022202
{
22032203
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
22042204
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2205-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_PAUSE_STATE params:@{}];
2206-
[[LPRequestSender sharedInstance] sendRequest:req];
2205+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_PAUSE_STATE params:@{}];
2206+
[[LPRequestSender sharedInstance] sendRequest:request];
22072207
}
22082208

22092209
+ (void)resumeState
@@ -2224,8 +2224,8 @@ + (void)resumeStateInternal
22242224
{
22252225
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
22262226
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2227-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_RESUME_STATE params:@{}];
2228-
[[LPRequestSender sharedInstance] sendRequest:req];
2227+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_RESUME_STATE params:@{}];
2228+
[[LPRequestSender sharedInstance] sendRequest:request];
22292229
}
22302230

22312231
+ (void)forceContentUpdate
@@ -2253,10 +2253,10 @@ + (void)forceContentUpdate:(LeanplumVariablesChangedBlock)block
22532253

22542254
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
22552255
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2256-
LeanplumRequest* req = [reqFactory
2256+
id<LPRequesting> request = [reqFactory
22572257
createPostForApiMethod:LP_METHOD_GET_VARS
22582258
params:params];
2259-
[req onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
2259+
[request onResponse:^(id<LPNetworkOperationProtocol> operation, NSDictionary *response) {
22602260
LP_TRY
22612261
NSDictionary *values = response[LP_KEY_VARS];
22622262
NSDictionary *messages = response[LP_KEY_MESSAGES];
@@ -2291,13 +2291,13 @@ + (void)forceContentUpdate:(LeanplumVariablesChangedBlock)block
22912291
block();
22922292
}
22932293
}];
2294-
[req onError:^(NSError *error) {
2294+
[request onError:^(NSError *error) {
22952295
if (block) {
22962296
block();
22972297
}
22982298
[[self inbox] triggerInboxSyncedWithStatus:NO];
22992299
}];
2300-
[[LPRequestSender sharedInstance] sendIfConnectedRequest:req];
2300+
[[LPRequestSender sharedInstance] sendIfConnected:request];
23012301
LP_END_TRY
23022302
}
23032303

@@ -2543,11 +2543,11 @@ + (void)maybeSendLog:(NSString *)message {
25432543
@try {
25442544
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
25452545
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2546-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_LOG params:@{
2546+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_LOG params:@{
25472547
LP_PARAM_TYPE: LP_VALUE_SDK_LOG,
25482548
LP_PARAM_MESSAGE: message
25492549
}];
2550-
[[LPRequestSender sharedInstance] sendEventuallyRequest:req];
2550+
[[LPRequestSender sharedInstance] sendEventually:request];
25512551
} @catch (NSException *exception) {
25522552
NSLog(@"Leanplum: Unable to send log: %@", exception);
25532553
} @finally {
@@ -2636,19 +2636,19 @@ + (void)setUserLocationAttributeWithLatitude:(double)latitude
26362636

26372637
LPRequestFactory *reqFactory = [[LPRequestFactory alloc]
26382638
initWithFeatureFlagManager:[LPFeatureFlagManager sharedManager]];
2639-
id<LPRequesting> req = [reqFactory createPostForApiMethod:LP_METHOD_SET_USER_ATTRIBUTES params:params];
2640-
[req onResponse:^(id<LPNetworkOperationProtocol> operation, id json) {
2639+
id<LPRequesting> request = [reqFactory createPostForApiMethod:LP_METHOD_SET_USER_ATTRIBUTES params:params];
2640+
[request onResponse:^(id<LPNetworkOperationProtocol> operation, id json) {
26412641
if (response) {
26422642
response(YES);
26432643
}
26442644
}];
2645-
[req onError:^(NSError *error) {
2645+
[request onError:^(NSError *error) {
26462646
LPLog(LPError, @"setUserAttributes failed with error: %@", error);
26472647
if (response) {
26482648
response(NO);
26492649
}
26502650
}];
2651-
[[LPRequestSender sharedInstance] sendRequest:req];
2651+
[[LPRequestSender sharedInstance] sendRequest:request];
26522652
LP_END_TRY
26532653
}
26542654

Leanplum-SDK/Classes/Managers/LPAppIconManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ + (void)uploadAppIconsOnDevMode
7474
[request onError:^(NSError *error) {
7575
LPLog(LPError, @"Fail to upload app icons: %@", error.localizedDescription);
7676
}];
77-
[[LPRequestSender sharedInstance] sendDatasNow:requestDatas request:request];
77+
[[LPRequestSender sharedInstance] sendNow:request withDatas:requestDatas];
7878
}
7979

8080
#pragma mark - Private methods

Leanplum-SDK/Classes/Managers/LPRegisterDevice.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ - (void)registerDevice:(NSString *)email
6969
[request onError:^(NSError *error) {
7070
[self showError:[error localizedDescription]];
7171
}];
72-
[[LPRequestSender sharedInstance] sendNowRequest:request];
72+
[[LPRequestSender sharedInstance] sendNow:request];
7373
}
7474

7575
@end

0 commit comments

Comments
 (0)