-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathMPIdentityApiRequest.m
80 lines (66 loc) · 2.1 KB
/
MPIdentityApiRequest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// MPIdentityApiRequest.m
//
#import "MPIdentityApiRequest.h"
#import "MPDevice.h"
#import "MPNotificationController.h"
#import "MPIConstants.h"
#import "MPStateMachine.h"
#import "MPIUserDefaults.h"
#import "MPIdentityDTO.h"
@interface MPIdentityApiRequest ()
@property (nonatomic) NSMutableDictionary<NSNumber*, NSObject*> *mutableIdentities;
@end
@implementation MPIdentityApiRequest
- (instancetype)init
{
self = [super init];
if (self) {
_mutableIdentities = [NSMutableDictionary dictionary];
}
return self;
}
- (void)setIdentity:(NSString *)identityString identityType:(MPIdentity)identityType {
if (MPIsNull(identityString)) {
[_mutableIdentities setObject:(NSString *)[NSNull null]
forKey:@(identityType)];
} else if ([identityString length] > 0) {
[_mutableIdentities setObject:identityString
forKey:@(identityType)];
}
}
+ (MPIdentityApiRequest *)requestWithEmptyUser {
return [[self alloc] init];
}
+ (MPIdentityApiRequest *)requestWithUser:(MParticleUser *) user {
MPIdentityApiRequest *request = [[self alloc] init];
[user.identities enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
MPIdentity identityType = [key intValue];
[request setIdentity:obj identityType:identityType];
}];
return request;
}
- (NSString *)email {
NSObject *result = _mutableIdentities[@(MPIdentityEmail)];
if ([result isKindOfClass:[NSString class]]) {
return (NSString *)result;
}
return nil;
}
- (void)setEmail:(NSString *)email {
[self setIdentity:email identityType:MPIdentityEmail];
}
- (NSString *)customerId {
NSObject *result = _mutableIdentities[@(MPIdentityCustomerId)];
if ([result isKindOfClass:[NSString class]]) {
return (NSString *)result;
}
return nil;
}
- (void)setCustomerId:(NSString *)customerId {
[self setIdentity:customerId identityType:MPIdentityCustomerId];
}
- (NSDictionary<NSNumber*, NSObject*> *)identities {
return [_mutableIdentities copy];
}
@end