Skip to content

Commit c70d7e7

Browse files
authored
refactoring network layer (#390)
* refactoring network layer LeanplumRequest (old request) removed LPRequesting removed LPRequestFactory, LPRequest, LPRequestSender LPNetworkConstants created * fix unit tests * fixing unit tests * add missing code in sendEventually * fix unit test for test_sendAllCounts * fixing test_start_with_user_id and add reset for responseCallback * move logic for removing empty keys in createArgsDictionaryForRequest method * refactor LPRequestFactory change to use class methods fix unit tests * replace @"data" param with constant
1 parent 5d91620 commit c70d7e7

File tree

61 files changed

+922
-1971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+922
-1971
lines changed

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
07E5C8AD1F052B7800A4B092 /* LPEventDataManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C86D1F052B7800A4B092 /* LPEventDataManagerTest.m */; };
1616
07E5C8AE1F052B7800A4B092 /* ExceptionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C86E1F052B7800A4B092 /* ExceptionsTest.m */; };
1717
07E5C8AF1F052B7800A4B092 /* LeanplumReachability+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C8721F052B7800A4B092 /* LeanplumReachability+Category.m */; };
18-
07E5C8B01F052B7800A4B092 /* LeanplumRequest+Categories.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C8741F052B7800A4B092 /* LeanplumRequest+Categories.m */; };
18+
07E5C8B01F052B7800A4B092 /* LPRequestSender+Categories.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C8741F052B7800A4B092 /* LPRequestSender+Categories.m */; };
1919
07E5C8B11F052B7800A4B092 /* LPNetworkEngine+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C8771F052B7800A4B092 /* LPNetworkEngine+Category.m */; };
2020
07E5C8B21F052B7800A4B092 /* LPNetworkOperation+Category.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C8791F052B7800A4B092 /* LPNetworkOperation+Category.m */; };
2121
07E5C8B31F052B7800A4B092 /* LPFileManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 07E5C87B1F052B7800A4B092 /* LPFileManagerTest.m */; };
@@ -103,6 +103,8 @@
103103
9E53F6DF2474363D0097955F /* LPNotificationsManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E53F6DE2474363D0097955F /* LPNotificationsManagerTest.m */; };
104104
9E53F6E1247438440097955F /* LPPushNotificationsManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E53F6E0247438440097955F /* LPPushNotificationsManagerTest.m */; };
105105
9E53F6E32474387B0097955F /* LPPushNotificationsHandlerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E53F6E22474387B0097955F /* LPPushNotificationsHandlerTest.m */; };
106+
9EE5FFA524D08E6700153AF8 /* LPRequest+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EE5FFA424D08E6700153AF8 /* LPRequest+Extension.m */; };
107+
9EE5FFA824D0C2B700153AF8 /* LPRequestFactory+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EE5FFA724D0C2B700153AF8 /* LPRequestFactory+Extension.m */; };
106108
9EF00D3A2448DE3E0094CA89 /* LPOpenUrlMessageTemplateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9EF00D392448DE3E0094CA89 /* LPOpenUrlMessageTemplateTest.m */; };
107109
A824579A2411CB600044B1EB /* LPWebInterstitialMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A82457982411CB600044B1EB /* LPWebInterstitialMessageSnapshotTest.m */; };
108110
A824579B2411CB600044B1EB /* LPRichInterstitialMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A82457992411CB600044B1EB /* LPRichInterstitialMessageSnapshotTest.m */; };
@@ -112,7 +114,6 @@
112114
A86C8D04240844C7003F5E4E /* LPCenterPopupMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CFC240844C7003F5E4E /* LPCenterPopupMessageSnapshotTest.m */; };
113115
A86C8D06240844C7003F5E4E /* LPInterstitialMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CFD240844C7003F5E4E /* LPInterstitialMessageSnapshotTest.m */; };
114116
A86C8D08240844C7003F5E4E /* LPAlertMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CFE240844C7003F5E4E /* LPAlertMessageSnapshotTest.m */; };
115-
A8CB8A36227276A400E1001D /* LeanplumRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */; };
116117
A8EEA1AB20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
117118
A8EEA1AC20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
118119
A8F4479E2449769000F6978A /* LPNetworkOperationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8F4479D2449769000F6978A /* LPNetworkOperationTest.m */; };
@@ -143,8 +144,8 @@
143144
07E5C8701F052B7800A4B092 /* Leanplum+Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Leanplum+Extensions.h"; sourceTree = "<group>"; };
144145
07E5C8711F052B7800A4B092 /* LeanplumReachability+Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LeanplumReachability+Category.h"; sourceTree = "<group>"; };
145146
07E5C8721F052B7800A4B092 /* LeanplumReachability+Category.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LeanplumReachability+Category.m"; sourceTree = "<group>"; };
146-
07E5C8731F052B7800A4B092 /* LeanplumRequest+Categories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LeanplumRequest+Categories.h"; sourceTree = "<group>"; };
147-
07E5C8741F052B7800A4B092 /* LeanplumRequest+Categories.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LeanplumRequest+Categories.m"; sourceTree = "<group>"; };
147+
07E5C8731F052B7800A4B092 /* LPRequestSender+Categories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LPRequestSender+Categories.h"; sourceTree = "<group>"; };
148+
07E5C8741F052B7800A4B092 /* LPRequestSender+Categories.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LPRequestSender+Categories.m"; sourceTree = "<group>"; };
148149
07E5C8761F052B7800A4B092 /* LPNetworkEngine+Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LPNetworkEngine+Category.h"; sourceTree = "<group>"; };
149150
07E5C8771F052B7800A4B092 /* LPNetworkEngine+Category.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LPNetworkEngine+Category.m"; sourceTree = "<group>"; };
150151
07E5C8781F052B7800A4B092 /* LPNetworkOperation+Category.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LPNetworkOperation+Category.h"; sourceTree = "<group>"; };
@@ -220,6 +221,10 @@
220221
9E53F6DE2474363D0097955F /* LPNotificationsManagerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPNotificationsManagerTest.m; sourceTree = "<group>"; };
221222
9E53F6E0247438440097955F /* LPPushNotificationsManagerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPPushNotificationsManagerTest.m; sourceTree = "<group>"; };
222223
9E53F6E22474387B0097955F /* LPPushNotificationsHandlerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPPushNotificationsHandlerTest.m; sourceTree = "<group>"; };
224+
9EE5FFA324D08E6700153AF8 /* LPRequest+Extension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LPRequest+Extension.h"; sourceTree = "<group>"; };
225+
9EE5FFA424D08E6700153AF8 /* LPRequest+Extension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "LPRequest+Extension.m"; sourceTree = "<group>"; };
226+
9EE5FFA624D0C2B600153AF8 /* LPRequestFactory+Extension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LPRequestFactory+Extension.h"; sourceTree = "<group>"; };
227+
9EE5FFA724D0C2B700153AF8 /* LPRequestFactory+Extension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "LPRequestFactory+Extension.m"; sourceTree = "<group>"; };
223228
9EF00D392448DE3E0094CA89 /* LPOpenUrlMessageTemplateTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPOpenUrlMessageTemplateTest.m; sourceTree = "<group>"; };
224229
9EF00D3B2448EEF30094CA89 /* LPOpenUrlMessageTemplate+Extenstion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LPOpenUrlMessageTemplate+Extenstion.h"; sourceTree = "<group>"; };
225230
A54ACCFCB36AE8C874708A7F /* libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -231,7 +236,6 @@
231236
A86C8CFC240844C7003F5E4E /* LPCenterPopupMessageSnapshotTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPCenterPopupMessageSnapshotTest.m; sourceTree = "<group>"; };
232237
A86C8CFD240844C7003F5E4E /* LPInterstitialMessageSnapshotTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPInterstitialMessageSnapshotTest.m; sourceTree = "<group>"; };
233238
A86C8CFE240844C7003F5E4E /* LPAlertMessageSnapshotTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPAlertMessageSnapshotTest.m; sourceTree = "<group>"; };
234-
A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LeanplumRequestTest.m; sourceTree = "<group>"; };
235239
A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = start_with_variant_debug_info_response.json; sourceTree = "<group>"; };
236240
A8F4479D2449769000F6978A /* LPNetworkOperationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPNetworkOperationTest.m; sourceTree = "<group>"; };
237241
B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = TiedPrioritiesDifferentDelay.json; sourceTree = "<group>"; };
@@ -294,7 +298,6 @@
294298
65E53E962148786C00A05040 /* LPCountAggregatorTest.m */,
295299
653192A021517D4F00D7DDDC /* LPFeatureFlagManagerTest.m */,
296300
07E5C87B1F052B7800A4B092 /* LPFileManagerTest.m */,
297-
A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */,
298301
07E5C87E1F052B7800A4B092 /* LeanplumTest.m */,
299302
07E5C87F1F052B7800A4B092 /* LPJSONTest.m */,
300303
07E5C8801F052B7800A4B092 /* MessagesTest.m */,
@@ -315,8 +318,12 @@
315318
07E5C8701F052B7800A4B092 /* Leanplum+Extensions.h */,
316319
07E5C8711F052B7800A4B092 /* LeanplumReachability+Category.h */,
317320
07E5C8721F052B7800A4B092 /* LeanplumReachability+Category.m */,
318-
07E5C8731F052B7800A4B092 /* LeanplumRequest+Categories.h */,
319-
07E5C8741F052B7800A4B092 /* LeanplumRequest+Categories.m */,
321+
9EE5FFA324D08E6700153AF8 /* LPRequest+Extension.h */,
322+
9EE5FFA424D08E6700153AF8 /* LPRequest+Extension.m */,
323+
9EE5FFA624D0C2B600153AF8 /* LPRequestFactory+Extension.h */,
324+
9EE5FFA724D0C2B700153AF8 /* LPRequestFactory+Extension.m */,
325+
07E5C8731F052B7800A4B092 /* LPRequestSender+Categories.h */,
326+
07E5C8741F052B7800A4B092 /* LPRequestSender+Categories.m */,
320327
07E5C8761F052B7800A4B092 /* LPNetworkEngine+Category.h */,
321328
07E5C8771F052B7800A4B092 /* LPNetworkEngine+Category.m */,
322329
07E5C8781F052B7800A4B092 /* LPNetworkOperation+Category.h */,
@@ -810,12 +817,12 @@
810817
A86C8D06240844C7003F5E4E /* LPInterstitialMessageSnapshotTest.m in Sources */,
811818
65D4AB49224CA963009BA5F3 /* LPActionContextTest.m in Sources */,
812819
07E5C8B31F052B7800A4B092 /* LPFileManagerTest.m in Sources */,
813-
A8CB8A36227276A400E1001D /* LeanplumRequestTest.m in Sources */,
814820
A86C8D08240844C7003F5E4E /* LPAlertMessageSnapshotTest.m in Sources */,
815821
07E5C8B81F052B7800A4B092 /* MessagesTest.m in Sources */,
816822
A86C8D00240844C7003F5E4E /* LPPushAskToAskMessageSnapshotTest.m in Sources */,
817823
07E5C8BD1F052B7800A4B092 /* LeanplumHelper.m in Sources */,
818824
07E5C8B21F052B7800A4B092 /* LPNetworkOperation+Category.m in Sources */,
825+
9EE5FFA824D0C2B700153AF8 /* LPRequestFactory+Extension.m in Sources */,
819826
65E53E982148786C00A05040 /* LPCountAggregatorTest.m in Sources */,
820827
A8F4479E2449769000F6978A /* LPNetworkOperationTest.m in Sources */,
821828
A86C8D02240844C7003F5E4E /* LPConfirmMessageSnapshotTest.m in Sources */,
@@ -841,8 +848,9 @@
841848
9E53F6E32474387B0097955F /* LPPushNotificationsHandlerTest.m in Sources */,
842849
07E5C8AF1F052B7800A4B092 /* LeanplumReachability+Category.m in Sources */,
843850
9CB691E11F1601BA002D83D8 /* LPEventCallbackManagerTest.m in Sources */,
851+
9EE5FFA524D08E6700153AF8 /* LPRequest+Extension.m in Sources */,
844852
07E5C8BE1F052B7800A4B092 /* LPUtilsTest.m in Sources */,
845-
07E5C8B01F052B7800A4B092 /* LeanplumRequest+Categories.m in Sources */,
853+
07E5C8B01F052B7800A4B092 /* LPRequestSender+Categories.m in Sources */,
846854
);
847855
runOnlyForDeploymentPostprocessing = 0;
848856
};

Example/Tests/Classes/ExceptionsTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#import <OHHTTPStubs/HTTPStubs.h>
2929
#import <OHHTTPStubs/HTTPStubsPathHelpers.h>
3030
#import "LeanplumHelper.h"
31-
#import "LeanplumRequest+Categories.h"
31+
#import "LPRequestSender+Categories.h"
3232
#import "LPNetworkEngine+Category.h"
3333
#import "Leanplum+Extensions.h"
3434
#import "LeanplumReachability+Category.h"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// LPRequest+Extension.h
3+
// Leanplum-SDK_Tests
4+
//
5+
// Created by Dejan Krstevski on 28.07.20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
9+
#import <Leanplum/LPRequest.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface LPRequest (Extension)
14+
+ (void)validate_onResponse:(LPNetworkResponseBlock)response;
15+
+ (void)swizzle_methods;
16+
+ (void)reset;
17+
@end
18+
19+
NS_ASSUME_NONNULL_END
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// LPRequest+Extension.m
3+
// Leanplum-SDK_Tests
4+
//
5+
// Created by Dejan . Krstevski on 28.07.20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
9+
#import "LPRequest+Extension.h"
10+
11+
@implementation LPRequest (Extension)
12+
static LPNetworkResponseBlock responseCallback;
13+
14+
+ (void)swizzle_methods
15+
{
16+
NSError *error;
17+
bool success = [LPSwizzle swizzleMethod:@selector(onResponse:)
18+
withMethod:@selector(swizzle_onResponse:)
19+
error:&error
20+
class:[LPRequest class]];
21+
22+
if (!success || error) {
23+
NSLog(@"Failed swizzling methods for LPRequest: %@", error);
24+
}
25+
}
26+
27+
- (void)swizzle_onResponse:(LPNetworkResponseBlock) response_
28+
{
29+
[self swizzle_onResponse:^(id<LPNetworkOperationProtocol> operation, id json) {
30+
if (responseCallback) {
31+
responseCallback(operation, json);
32+
responseCallback = nil;
33+
}
34+
response_(operation, json);
35+
}];
36+
}
37+
38+
+ (void)validate_onResponse:(LPNetworkResponseBlock)callback
39+
{
40+
responseCallback = callback;
41+
}
42+
43+
+ (void)reset
44+
{
45+
responseCallback = nil;
46+
}
47+
48+
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// LPRequestFactory+Extension.h
3+
// Leanplum-SDK_Tests
4+
//
5+
// Created by Dejan . Krstevski on 28.07.20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
9+
#import <Leanplum/LPRequestFactory.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface LPRequestFactory (Extension)
14+
+ (void)swizzle_methods;
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// LPRequestFactory+Extension.m
3+
// Leanplum-SDK_Tests
4+
//
5+
// Created by Dejan . Krstevski on 28.07.20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
9+
#import "LPRequestFactory+Extension.h"
10+
#import "LPRequestSender+Categories.h"
11+
12+
@implementation LPRequestFactory (Extension)
13+
14+
+ (void)swizzle_methods
15+
{
16+
NSError *error;
17+
bool success = [LPSwizzle swizzleClassMethod:@selector(createGetForApiMethod:params:)
18+
withClassMethod:@selector(swizzle_createGetForApiMethod:params:)
19+
error:&error
20+
class:[LPRequestFactory class]];
21+
success &= [LPSwizzle swizzleClassMethod:@selector(createPostForApiMethod:params:)
22+
withClassMethod:@selector(swizzle_createPostForApiMethod:params:)
23+
error:&error
24+
class:[LPRequestFactory class]];
25+
if (!success || error) {
26+
NSLog(@"Failed swizzling methods for LPRequestFactory: %@", error);
27+
}
28+
}
29+
30+
+ (LPRequest *)swizzle_createGetForApiMethod:(NSString *) apiMethod_ params:(NSDictionary *) params_
31+
{
32+
if ([LPRequestSender sharedInstance].requestCallback != nil)
33+
{
34+
BOOL success = [LPRequestSender sharedInstance].requestCallback(@"get", apiMethod_, params_);
35+
if (success) {
36+
[LPRequestSender sharedInstance].requestCallback = nil;
37+
}
38+
}
39+
return [self swizzle_createGetForApiMethod:apiMethod_ params:params_];
40+
}
41+
42+
+ (LPRequest *)swizzle_createPostForApiMethod:(NSString *) apiMethod_ params:(NSDictionary *) params_
43+
{
44+
if ([LPRequestSender sharedInstance].requestCallback != nil)
45+
{
46+
BOOL success = [LPRequestSender sharedInstance].requestCallback(@"post", apiMethod_, params_);
47+
if (success) {
48+
[LPRequestSender sharedInstance].requestCallback = nil;
49+
}
50+
}
51+
return [self swizzle_createPostForApiMethod:apiMethod_ params:params_];
52+
}
53+
54+
@end

Example/Tests/Classes/Extensions/LeanplumRequest+Categories.h renamed to Example/Tests/Classes/Extensions/LPRequestSender+Categories.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// LeanplumRequest+Extensions.h
2+
// LPRequestSender+Extensions.h
33
// Leanplum-SDK
44
//
55
// Created by Milos Jakovljevic on 10/17/16.
@@ -23,12 +23,16 @@
2323
// under the License.
2424

2525

26-
#import "LeanplumRequest.h"
26+
#import "LPRequestSender.h"
2727

28-
@interface LeanplumRequest(MethodSwizzling)
28+
@interface LPRequestSender(MethodSwizzling)
29+
30+
@property (assign) BOOL (^requestCallback)(NSString *method, NSString *apiMethod, NSDictionary *params);
31+
32+
- (void)setRequestCallback:(BOOL (^)(NSString *, NSString *, NSDictionary *))requestCallback;
33+
- (BOOL (^)(NSString *, NSString *, NSDictionary *))requestCallback;
2934

3035
+ (void)validate_request:(BOOL (^)(NSString *, NSString *, NSDictionary *))callback;
31-
+ (void)validate_onResponse:(LPNetworkResponseBlock)response;
3236
+ (void)swizzle_methods;
3337
+ (void)reset;
3438

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// LPRequestSender+Extensions.m
3+
// Leanplum-SDK
4+
//
5+
// Created by Milos Jakovljevic on 10/17/16.
6+
// Copyright © 2016 Leanplum. All rights reserved.
7+
//
8+
// Licensed to the Apache Software Foundation (ASF) under one
9+
// or more contributor license agreements. See the NOTICE file
10+
// distributed with this work for additional information
11+
// regarding copyright ownership. The ASF licenses this file
12+
// to you under the Apache License, Version 2.0 (the "License");
13+
// you may not use this file except in compliance with the License.
14+
// You may obtain a copy of the License at
15+
//
16+
// http://www.apache.org/licenses/LICENSE-2.0
17+
//
18+
// Unless required by applicable law or agreed to in writing,
19+
// software distributed under the License is distributed on an
20+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21+
// KIND, either express or implied. See the License for the
22+
// specific language governing permissions and limitations
23+
// under the License.
24+
25+
26+
#import "LPRequestSender+Categories.h"
27+
#import "LPSwizzle.h"
28+
#import <objc/runtime.h>
29+
30+
@implementation LPRequestSender(MethodSwizzling)
31+
@dynamic requestCallback;
32+
33+
- (void)setRequestCallback:(BOOL (^)(NSString *, NSString *, NSDictionary *))requestCallback
34+
{
35+
objc_setAssociatedObject(self, @selector(requestCallback), requestCallback, OBJC_ASSOCIATION_COPY);
36+
}
37+
38+
- (BOOL (^)(NSString *, NSString *, NSDictionary *))requestCallback
39+
{
40+
return objc_getAssociatedObject(self, _cmd);
41+
}
42+
43+
+ (void)swizzle_methods
44+
{
45+
NSError *error;
46+
bool success = [LPSwizzle swizzleMethod:@selector(sendNow:)
47+
withMethod:@selector(swizzle_sendNow:)
48+
error:&error
49+
class:[LPRequestSender class]];
50+
success &= [LPSwizzle swizzleMethod:@selector(sendEventually:sync:)
51+
withMethod:@selector(swizzle_sendEventually:sync:)
52+
error:&error
53+
class:[LPRequestSender class]];
54+
if (!success || error) {
55+
NSLog(@"Failed swizzling methods for LPRequestSender: %@", error);
56+
}
57+
}
58+
59+
- (void)swizzle_sendNow:(LPRequest *)request
60+
{
61+
[self swizzle_sendNow:request];
62+
}
63+
64+
- (void)swizzle_sendEventually:(LPRequest *)request sync:(BOOL)sync
65+
{
66+
[self swizzle_sendEventually:request sync:sync];
67+
}
68+
69+
- (void)swizzle_download
70+
{
71+
72+
}
73+
74+
+ (void)validate_request:(BOOL (^)(NSString *, NSString *, NSDictionary *)) callback
75+
{
76+
[LPRequestSender sharedInstance].requestCallback = callback;
77+
}
78+
79+
+ (void)reset {
80+
[LPRequestSender sharedInstance].requestCallback = nil;
81+
}
82+
83+
@end

0 commit comments

Comments
 (0)