Skip to content

Commit 863c6ba

Browse files
authored
[1] Add request factory (#184)
1 parent c36ef99 commit 863c6ba

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <Foundation/Foundation.h>
2+
#import "LPRequesting.h"
3+
#import "LPFeatureFlagManager.h"
4+
5+
@interface LPRequestFactory : NSObject
6+
7+
-(instancetype)initWithFeatureFlagManager:(LPFeatureFlagManager *)featureFlagManager;
8+
9+
- (id<LPRequesting>)createGetForApiMethod:(NSString *)apiMethod params:(NSDictionary *)params;
10+
- (id<LPRequesting>)createPostForApiMethod:(NSString *)apiMethod params:(NSDictionary *)params;
11+
12+
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#import "LPRequestFactory.h"
3+
#import "LeanplumRequest.h"
4+
5+
@interface LPRequestFactory()
6+
7+
@property (nonatomic, strong) LPFeatureFlagManager *featureFlagManager;
8+
9+
@end
10+
11+
@implementation LPRequestFactory
12+
13+
-(instancetype)initWithFeatureFlagManager:(LPFeatureFlagManager *)featureFlagManager
14+
{
15+
self = [super init];
16+
if (self) {
17+
_featureFlagManager = featureFlagManager;
18+
}
19+
return self;
20+
}
21+
22+
- (id<LPRequesting>)createGetForApiMethod:(NSString *)apiMethod params:(NSDictionary *)params {
23+
return [[LeanplumRequest alloc] initWithHttpMethod:@"GET" apiMethod:apiMethod params:params];
24+
}
25+
26+
- (id<LPRequesting>)createPostForApiMethod:(NSString *)apiMethod params:(NSDictionary *)params {
27+
return [[LeanplumRequest alloc] initWithHttpMethod:@"POST" apiMethod:apiMethod params:params];
28+
}
29+
30+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// LPRequesting.h
3+
// Pods
4+
//
5+
// Created by Mayank Sanganeria on 8/23/18.
6+
//
7+
8+
#ifndef LPRequesting_h
9+
#define LPRequesting_h
10+
11+
#import "LPNetworkProtocol.h"
12+
#import "LeanplumInternal.h"
13+
14+
@protocol LPRequesting
15+
16+
@property (nonatomic, strong) NSString *apiMethod;
17+
@property (nonatomic, strong) NSDictionary *params;
18+
@property (atomic) BOOL sent;
19+
@property (nonatomic, copy) LPNetworkResponseBlock responseBlock;
20+
@property (nonatomic, copy) LPNetworkErrorBlock errorBlock;
21+
22+
- (void)onResponse:(LPNetworkResponseBlock)response;
23+
- (void)onError:(LPNetworkErrorBlock)error;
24+
25+
@end
26+
27+
#endif /* LPRequesting_h */

Leanplum-SDK/Classes/Managers/Networking/LeanplumRequest.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
#import <Foundation/Foundation.h>
2626
#import "Leanplum.h"
2727
#import "LPNetworkFactory.h"
28+
#import "LPRequesting.h"
2829

29-
@interface LeanplumRequest : NSObject {
30+
@interface LeanplumRequest : NSObject <LPRequesting> {
3031
@private
3132
NSString *_httpMethod;
3233
NSString *_apiMethod;

0 commit comments

Comments
 (0)