4545#import " Utils.h"
4646#import " LPAppIconManager.h"
4747#import " LPUIEditorWrapper.h"
48+ #import " LPRequestFactory.h"
4849
4950static NSString *leanplum_deviceId = nil ;
5051static NSString *registrationEmail = nil ;
@@ -857,7 +858,9 @@ + (void)startWithUserId:(NSString *)userId
857858 }
858859
859860 // Issue start API call.
860- LeanplumRequest *req = [LeanplumRequest post: LP_METHOD_START params: params];
861+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
862+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
863+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_START params: params];
861864 [req onResponse: ^(id <LPNetworkOperationProtocol> operation, NSDictionary *response) {
862865 LP_TRY
863866 state.hasStarted = YES ;
@@ -936,11 +939,14 @@ + (void)startWithUserId:(NSString *)userId
936939 // Report latency for 0.1% of users.
937940 NSTimeInterval latency = [[NSDate date ] timeIntervalSinceDate: startTime];
938941 if (arc4random () % 1000 == 0 ) {
939- [[LeanplumRequest post: LP_METHOD_LOG
942+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
943+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
944+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_LOG
940945 params: @{
941946 LP_PARAM_TYPE: LP_VALUE_SDK_START_LATENCY,
942947 @" startLatency" : [@(latency) description ]
943- }] send ];
948+ }];
949+ [req send ];
944950 }
945951 }
946952
@@ -1032,8 +1038,10 @@ + (void)startWithUserId:(NSString *)userId
10321038 LP_TRY
10331039 BOOL exitOnSuspend = [[[[NSBundle mainBundle ] infoDictionary ]
10341040 objectForKey: @" UIApplicationExitsOnSuspend" ] boolValue ];
1035- [[LeanplumRequest post: LP_METHOD_STOP params: nil ]
1036- sendIfConnectedSync: exitOnSuspend];
1041+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
1042+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
1043+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_STOP params: nil ];
1044+ [req sendIfConnectedSync: exitOnSuspend];
10371045 LP_END_TRY
10381046 }];
10391047
@@ -1042,7 +1050,10 @@ + (void)startWithUserId:(NSString *)userId
10421050 RETURN_IF_NOOP;
10431051 LP_TRY
10441052 if ([[UIApplication sharedApplication ] applicationState ] == UIApplicationStateActive) {
1045- [[LeanplumRequest post: LP_METHOD_HEARTBEAT params: nil ] sendIfDelayed ];
1053+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
1054+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
1055+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_HEARTBEAT params: nil ];
1056+ [req sendIfDelayed ];
10461057 }
10471058 LP_END_TRY
10481059 } repeats: YES ];
@@ -1135,7 +1146,9 @@ + (void)pause
11351146 backgroundTask = [application beginBackgroundTaskWithExpirationHandler: finishTaskHandler];
11361147
11371148 // Send pause event.
1138- LeanplumRequest *request = [LeanplumRequest post: LP_METHOD_PAUSE_SESSION params: nil ];
1149+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
1150+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
1151+ LeanplumRequest *request = [reqFactory createPostForApiMethod: LP_METHOD_PAUSE_SESSION params: nil ];
11391152 [request onResponse: ^(id <LPNetworkOperationProtocol> operation, id json) {
11401153 finishTaskHandler ();
11411154 }];
@@ -1147,7 +1160,10 @@ + (void)pause
11471160
11481161+ (void )resume
11491162{
1150- [[LeanplumRequest post: LP_METHOD_RESUME_SESSION params: nil ] sendIfDelayed ];
1163+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
1164+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
1165+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_RESUME_SESSION params: nil ];
1166+ [req sendIfDelayed ];
11511167}
11521168
11531169+ (void )trackCrashes
@@ -1886,7 +1902,10 @@ + (void)track:(NSString *)event withValue:(double)value andInfo:(NSString *)info
18861902+ (void )trackInternal : (NSString *)event withArgs : (NSDictionary *)args
18871903 andParameters : (NSDictionary *)params
18881904{
1889- [[LeanplumRequest post: LP_METHOD_TRACK params: args] send ];
1905+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
1906+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
1907+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_TRACK params: args];
1908+ [req send ];
18901909
18911910 // Perform event actions.
18921911 NSString *messageId = args[LP_PARAM_MESSAGE_ID];
@@ -2016,10 +2035,13 @@ + (void)setUserIdInternal:(NSString *)userId withAttributes:(NSDictionary *)attr
20162035 attributes = @{};
20172036 }
20182037
2019- [[LeanplumRequest post: LP_METHOD_SET_USER_ATTRIBUTES params: @{
2038+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2039+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2040+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_SET_USER_ATTRIBUTES params: @{
20202041 LP_PARAM_USER_ATTRIBUTES: attributes ? [LPJSON stringFromJSON: attributes] : @" " ,
20212042 LP_PARAM_NEW_USER_ID: userId ? userId : @" "
2022- }] send ];
2043+ }];
2044+ [req send ];
20232045
20242046 if (userId.length ) {
20252047 [LeanplumRequest setUserId: userId];
@@ -2089,9 +2111,12 @@ + (void)setTrafficSourceInfo:(NSDictionary *)info
20892111
20902112+ (void )setTrafficSourceInfoInternal : (NSDictionary *)info
20912113{
2092- [[LeanplumRequest post: LP_METHOD_SET_TRAFFIC_SOURCE_INFO params: @{
2114+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2115+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2116+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_SET_TRAFFIC_SOURCE_INFO params: @{
20932117 LP_PARAM_TRAFFIC_SOURCE: info
2094- }] send ];
2118+ }];
2119+ [req send ];
20952120}
20962121
20972122+ (void )advanceTo : (NSString *)state
@@ -2141,7 +2166,10 @@ + (void)advanceTo:(NSString *)state withInfo:(NSString *)info andParameters:(NSD
21412166+ (void )advanceToInternal : (NSString *)state withArgs : (NSDictionary *)args
21422167 andParameters : (NSDictionary *)params
21432168{
2144- [[LeanplumRequest post: LP_METHOD_ADVANCE params: args] send ];
2169+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2170+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2171+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_ADVANCE params: args];
2172+ [req send ];
21452173 LPContextualValues *contextualValues = [[LPContextualValues alloc ] init ];
21462174 contextualValues.parameters = params;
21472175 [self maybePerformActions: @[@" state" ]
@@ -2167,7 +2195,10 @@ + (void)pauseState
21672195
21682196+ (void )pauseStateInternal
21692197{
2170- [[LeanplumRequest post: LP_METHOD_PAUSE_STATE params: @{}] send ];
2198+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2199+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2200+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_PAUSE_STATE params: @{}];
2201+ [req send ];
21712202}
21722203
21732204+ (void )resumeState
@@ -2186,7 +2217,10 @@ + (void)resumeState
21862217
21872218+ (void )resumeStateInternal
21882219{
2189- [[LeanplumRequest post: LP_METHOD_RESUME_STATE params: @{}] send ];
2220+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2221+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2222+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_RESUME_STATE params: @{}];
2223+ [req send ];
21902224}
21912225
21922226+ (void )forceContentUpdate
@@ -2212,9 +2246,10 @@ + (void)forceContentUpdate:(LeanplumVariablesChangedBlock)block
22122246 params[LP_PARAM_INCLUDE_VARIANT_DEBUG_INFO] = @(YES );
22132247 }
22142248
2215-
2216- LeanplumRequest* req = [LeanplumRequest
2217- post: LP_METHOD_GET_VARS
2249+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2250+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2251+ LeanplumRequest* req = [reqFactory
2252+ createPostForApiMethod: LP_METHOD_GET_VARS
22182253 params: params];
22192254 [req onResponse: ^(id <LPNetworkOperationProtocol> operation, NSDictionary *response) {
22202255 LP_TRY
@@ -2501,10 +2536,13 @@ + (void)maybeSendLog:(NSString *)message {
25012536 threadDict[LP_IS_LOGGING] = @YES ;
25022537
25032538 @try {
2504- [[LeanplumRequest post: LP_METHOD_LOG params: @{
2539+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2540+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2541+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_LOG params: @{
25052542 LP_PARAM_TYPE: LP_VALUE_SDK_LOG,
25062543 LP_PARAM_MESSAGE: message
2507- }] sendEventually ];
2544+ }];
2545+ [req sendEventually ];
25082546 } @catch (NSException *exception) {
25092547 NSLog (@" Leanplum: Unable to send log: %@ " , exception);
25102548 } @finally {
@@ -2591,7 +2629,9 @@ + (void)setUserLocationAttributeWithLatitude:(double)latitude
25912629 params[LP_KEY_COUNTRY] = country;
25922630 }
25932631
2594- LeanplumRequest *req = [LeanplumRequest post: LP_METHOD_SET_USER_ATTRIBUTES params: params];
2632+ LPRequestFactory *reqFactory = [[LPRequestFactory alloc ]
2633+ initWithFeatureFlagManager: [LPFeatureFlagManager sharedManager ]];
2634+ LeanplumRequest *req = [reqFactory createPostForApiMethod: LP_METHOD_SET_USER_ATTRIBUTES params: params];
25952635 [req onResponse: ^(id <LPNetworkOperationProtocol> operation, id json) {
25962636 if (response) {
25972637 response (YES );
0 commit comments