Manos Chorianopoulos

add consumerIntegrationAsync request

......@@ -80,6 +80,7 @@
- (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
@end
#endif /* MyApi_h */
......
......@@ -1321,4 +1321,18 @@ CMPedometer *pedometer;
failure(error);
}];
}
- (void)consumerIntegrationAsync:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] consumerIntegrationWithSuccessBlock:nonTelco :acceptedConsent :msisdnList :guid :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end
......
......@@ -328,6 +328,8 @@ WL_VERSION_INTERFACE()
andNickname:(NSString*)nickname andGender:(NSString*)gender andBirthday:(NSString*)birthday andNameDay:(NSString*)nameday andTaxID:(NSString*)taxID andProfileMetadata:(NSDictionary*)profileMetadata optin:(NSNumber*) optin newsLetter:(NSNumber*)newsletter
andSMS:(NSNumber*)sms andSegmentation:(NSNumber*)segmentation andSMSSegmentation:(NSNumber*)smsSegmentation :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)consumerIntegrationWithSuccessBlock:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)changeProfileImageWithSuccessBlock:(NSString*)image andUserId:(NSString*)userId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -994,6 +994,78 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
- (void)consumerIntegrationWithSuccessBlock:(NSNumber*)nonTelco :(NSNumber*)acceptedConsent :(NSArray*)msisdnList :(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSMutableDictionary* data = [[NSMutableDictionary alloc] init];
if (nonTelco && ![nonTelco isEqual:@NO]) {
[data setValue:nonTelco forKey:@"nonTelco"];
} else {
[data setValue:0 forKey:@"nonTelco"];
}
if (acceptedConsent && ![acceptedConsent isEqual:@NO]) {
[data setValue:acceptedConsent forKey:@"acceptedConsent"];
} else {
[data setValue:0 forKey:@"acceptedConsent"];
}
if (msisdnList && (msisdnList != nil) && ([msisdnList count] != 0)) {
[data setValue:msisdnList forKey:@"msisdnList"];
} else {
[data setValue:nil forKey:@"msisdnList"];
}
if (guid && ![guid isEqual:@""]) {
[data setValue:guid forKey:@"guid"];
} else {
[data setValue:@"" forKey:@"guid"];
}
NSMutableDictionary* consumerData = [[NSMutableDictionary alloc] init];
[consumerData setValue:@"integration" forKey:@"action"];
if(data && ![data isEqual:@{}]) {
[consumerData setValue:data forKey:@"data"];
}
NSMutableDictionary *postDictionary = [[NSMutableDictionary alloc] init];
[postDictionary setValue:consumerData forKey:@"consumer_data"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
} failureBlock:^(NSError *error) {
if (failure) {
NSDictionary* dict = [NSDictionary alloc];
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
[self refreshToken:^(NSDictionary *response) {
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
}];
}
NSLog(@"Error at consumer Integration %@", error );
}
}];
}
- (void)changeProfileImageWithSuccessBlock:(NSString*)image andUserId:(NSString*)userId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"action": @"upload", @"user_id": userId, @"imageOnBase64": image };
......
......@@ -1492,5 +1492,66 @@ public class swiftApi {
}
}
}
public class GenericResponseModel {
private var result: Int?
private var status: Int?
private var msg: String?
init(dictionary: [String: Any]) {
self.result = dictionary["result"] as? Int? ?? -1
self.status = dictionary["status"] as? Int? ?? -1
self.msg = dictionary["msg"] as? String? ?? ""
}
public var getResult: Int {
get { // getter
return self.result ?? -1
}
}
public var getStatus: Int {
get { // getter
return self.status ?? -1
}
}
public var getMsg: String {
get { // getter
return self.msg ?? ""
}
}
}
public func consumerIntegrationAsync(nonTelco: Bool, acceptedConsent: Bool, msisdnList: Array<String>, guid: String, _ consumerIntegrationCallback: @escaping (_ responseData: GenericResponseModel?) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.consumerIntegrationAsync(nonTelco as NSNumber, acceptedConsent as NSNumber, msisdnList, guid, requestCallback, failureBlock: requestFailureCallback)
func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
if let responseDataDictionary = responseData as? [String: Any] {
let tempResponse = GenericResponseModel(dictionary: responseDataDictionary)
consumerIntegrationCallback(tempResponse);
} else {
consumerIntegrationCallback(nil)
}
}
func requestFailureCallback(_ error: Error?) -> Void {
print("consumerIntegration error: ")
print(error)
print("====================")
consumerIntegrationCallback(nil)
}
}
}
......