Showing
5 changed files
with
150 additions
and
0 deletions
... | @@ -80,6 +80,7 @@ | ... | @@ -80,6 +80,7 @@ |
80 | - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | 80 | - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; |
81 | - (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 81 | - (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
82 | - (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 82 | - (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
83 | +- (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
83 | 84 | ||
84 | @end | 85 | @end |
85 | #endif /* MyApi_h */ | 86 | #endif /* MyApi_h */ | ... | ... |
... | @@ -1321,4 +1321,18 @@ CMPedometer *pedometer; | ... | @@ -1321,4 +1321,18 @@ CMPedometer *pedometer; |
1321 | failure(error); | 1321 | failure(error); |
1322 | }]; | 1322 | }]; |
1323 | } | 1323 | } |
1324 | + | ||
1325 | +- (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
1326 | +{ | ||
1327 | + [[Warply sharedService] consumerIntegrationWithSuccessBlock:nonTelco :acceptedConsent :msisdnList :guid :^(NSDictionary *response) { | ||
1328 | + if (success) { | ||
1329 | + success(response); | ||
1330 | + } | ||
1331 | + } failureBlock:^(NSError *error) { | ||
1332 | + if (failure) { | ||
1333 | + failure(error); | ||
1334 | + } | ||
1335 | + }]; | ||
1336 | +} | ||
1337 | + | ||
1324 | @end | 1338 | @end | ... | ... |
... | @@ -328,6 +328,8 @@ WL_VERSION_INTERFACE() | ... | @@ -328,6 +328,8 @@ WL_VERSION_INTERFACE() |
328 | andNickname:(NSString*)nickname andGender:(NSString*)gender andBirthday:(NSString*)birthday andNameDay:(NSString*)nameday andTaxID:(NSString*)taxID andProfileMetadata:(NSDictionary*)profileMetadata optin:(NSNumber*) optin newsLetter:(NSNumber*)newsletter | 328 | andNickname:(NSString*)nickname andGender:(NSString*)gender andBirthday:(NSString*)birthday andNameDay:(NSString*)nameday andTaxID:(NSString*)taxID andProfileMetadata:(NSDictionary*)profileMetadata optin:(NSNumber*) optin newsLetter:(NSNumber*)newsletter |
329 | andSMS:(NSNumber*)sms andSegmentation:(NSNumber*)segmentation andSMSSegmentation:(NSNumber*)smsSegmentation :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 329 | andSMS:(NSNumber*)sms andSegmentation:(NSNumber*)segmentation andSMSSegmentation:(NSNumber*)smsSegmentation :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
330 | 330 | ||
331 | +- (void)consumerIntegrationWithSuccessBlock:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
332 | + | ||
331 | - (void)changeProfileImageWithSuccessBlock:(NSString*)image andUserId:(NSString*)userId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 333 | - (void)changeProfileImageWithSuccessBlock:(NSString*)image andUserId:(NSString*)userId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
332 | 334 | ||
333 | 335 | ... | ... |
... | @@ -994,6 +994,78 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -994,6 +994,78 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
994 | }]; | 994 | }]; |
995 | } | 995 | } |
996 | 996 | ||
997 | +- (void)consumerIntegrationWithSuccessBlock:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
998 | +{ | ||
999 | + NSMutableDictionary* data = [[NSMutableDictionary alloc] init]; | ||
1000 | + | ||
1001 | + if (nonTelco && ![nonTelco isEqual:@NO]) { | ||
1002 | + [data setValue:nonTelco forKey:@"nonTelco"]; | ||
1003 | + } else { | ||
1004 | + [data setValue:0 forKey:@"nonTelco"]; | ||
1005 | + } | ||
1006 | + | ||
1007 | + if (acceptedConsent && ![acceptedConsent isEqual:@NO]) { | ||
1008 | + [data setValue:acceptedConsent forKey:@"acceptedConsent"]; | ||
1009 | + } else { | ||
1010 | + [data setValue:0 forKey:@"acceptedConsent"]; | ||
1011 | + } | ||
1012 | + | ||
1013 | + if (msisdnList && (msisdnList != nil) && ([msisdnList count] != 0)) { | ||
1014 | + [data setValue:msisdnList forKey:@"msisdnList"]; | ||
1015 | + } else { | ||
1016 | + [data setValue:nil forKey:@"msisdnList"]; | ||
1017 | + } | ||
1018 | + | ||
1019 | + if (guid && ![guid isEqual:@""]) { | ||
1020 | + [data setValue:guid forKey:@"guid"]; | ||
1021 | + } else { | ||
1022 | + [data setValue:@"" forKey:@"guid"]; | ||
1023 | + } | ||
1024 | + | ||
1025 | + NSMutableDictionary* consumerData = [[NSMutableDictionary alloc] init]; | ||
1026 | + [consumerData setValue:@"integration" forKey:@"action"]; | ||
1027 | + | ||
1028 | + if(data && ![data isEqual:@{}]) { | ||
1029 | + [consumerData setValue:data forKey:@"data"]; | ||
1030 | + } | ||
1031 | + | ||
1032 | + NSMutableDictionary *postDictionary = [[NSMutableDictionary alloc] init]; | ||
1033 | + [postDictionary setValue:consumerData forKey:@"consumer_data"]; | ||
1034 | + | ||
1035 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
1036 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
1037 | + if (success) { | ||
1038 | + success(contextResponse); | ||
1039 | + } | ||
1040 | + } failureBlock:^(NSError *error) { | ||
1041 | + if (failure) { | ||
1042 | + NSDictionary* dict = [NSDictionary alloc]; | ||
1043 | + dict = [error userInfo]; | ||
1044 | + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; | ||
1045 | + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { | ||
1046 | + [self refreshToken:^(NSDictionary *response) { | ||
1047 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
1048 | + if (success) { | ||
1049 | + success(contextResponse); | ||
1050 | + } | ||
1051 | + } failureBlock:^(NSError *error) { | ||
1052 | + if (failure) { | ||
1053 | + failure(error); | ||
1054 | + } | ||
1055 | + }]; | ||
1056 | + } failureBlock:^(NSError *error) { | ||
1057 | + if (failure) { | ||
1058 | + [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
1059 | + failure(error); | ||
1060 | + } | ||
1061 | + NSLog(@"Error at token %@", error ); | ||
1062 | + }]; | ||
1063 | + } | ||
1064 | + NSLog(@"Error at consumer Integration %@", error ); | ||
1065 | + } | ||
1066 | + }]; | ||
1067 | +} | ||
1068 | + | ||
997 | - (void)changeProfileImageWithSuccessBlock:(NSString*)image andUserId:(NSString*)userId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1069 | - (void)changeProfileImageWithSuccessBlock:(NSString*)image andUserId:(NSString*)userId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
998 | { | 1070 | { |
999 | NSDictionary *postDictionary = @{@"action": @"upload", @"user_id": userId, @"imageOnBase64": image }; | 1071 | NSDictionary *postDictionary = @{@"action": @"upload", @"user_id": userId, @"imageOnBase64": image }; | ... | ... |
... | @@ -1492,5 +1492,66 @@ public class swiftApi { | ... | @@ -1492,5 +1492,66 @@ public class swiftApi { |
1492 | } | 1492 | } |
1493 | } | 1493 | } |
1494 | } | 1494 | } |
1495 | + | ||
1496 | + | ||
1497 | + public class GenericResponseModel { | ||
1498 | + private var result: Int? | ||
1499 | + private var status: Int? | ||
1500 | + private var msg: String? | ||
1501 | + | ||
1502 | + | ||
1503 | + init(dictionary: [String: Any]) { | ||
1504 | + self.result = dictionary["result"] as? Int? ?? -1 | ||
1505 | + self.status = dictionary["status"] as? Int? ?? -1 | ||
1506 | + self.msg = dictionary["msg"] as? String? ?? "" | ||
1507 | + } | ||
1508 | + | ||
1509 | + public var getResult: Int { | ||
1510 | + get { // getter | ||
1511 | + return self.result ?? -1 | ||
1512 | + } | ||
1513 | + } | ||
1514 | + | ||
1515 | + public var getStatus: Int { | ||
1516 | + get { // getter | ||
1517 | + return self.status ?? -1 | ||
1518 | + } | ||
1519 | + } | ||
1520 | + | ||
1521 | + public var getMsg: String { | ||
1522 | + get { // getter | ||
1523 | + return self.msg ?? "" | ||
1524 | + } | ||
1525 | + } | ||
1526 | + } | ||
1527 | + | ||
1528 | + | ||
1529 | + public func consumerIntegrationAsync(nonTelco: Bool, acceptedConsent: Bool, msisdnList: Array<String>, guid: String, _ consumerIntegrationCallback: @escaping (_ responseData: GenericResponseModel?) -> Void) -> Void { | ||
1530 | + | ||
1531 | + let instanceOfMyApi = MyApi() | ||
1532 | + instanceOfMyApi.consumerIntegrationAsync(nonTelco as NSNumber, acceptedConsent as NSNumber, msisdnList, guid, requestCallback, failureBlock: requestFailureCallback) | ||
1533 | + | ||
1534 | + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
1535 | + | ||
1536 | + if let responseDataDictionary = responseData as? [String: Any] { | ||
1537 | + | ||
1538 | + let tempResponse = GenericResponseModel(dictionary: responseDataDictionary) | ||
1539 | + | ||
1540 | + consumerIntegrationCallback(tempResponse); | ||
1541 | + | ||
1542 | + } else { | ||
1543 | + consumerIntegrationCallback(nil) | ||
1544 | + } | ||
1545 | + | ||
1546 | + } | ||
1547 | + | ||
1548 | + func requestFailureCallback(_ error: Error?) -> Void { | ||
1549 | + print("consumerIntegration error: ") | ||
1550 | + print(error) | ||
1551 | + print("====================") | ||
1552 | + consumerIntegrationCallback(nil) | ||
1553 | + } | ||
1554 | + | ||
1555 | + } | ||
1495 | 1556 | ||
1496 | } | 1557 | } | ... | ... |
-
Please register or login to post a comment