Showing
5 changed files
with
237 additions
and
0 deletions
... | @@ -86,6 +86,7 @@ | ... | @@ -86,6 +86,7 @@ |
86 | - (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 86 | - (void)getPacingDetailsAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
87 | - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 87 | - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
88 | - (void)cosmoteRetrieveSharingAsync:(NSString*)sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 88 | - (void)cosmoteRetrieveSharingAsync:(NSString*)sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
89 | +- (void)getCosmoteUserAsync:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
89 | 90 | ||
90 | @end | 91 | @end |
91 | #endif /* MyApi_h */ | 92 | #endif /* MyApi_h */ | ... | ... |
... | @@ -1418,4 +1418,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1418,4 +1418,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
1418 | }]; | 1418 | }]; |
1419 | } | 1419 | } |
1420 | 1420 | ||
1421 | +- (void)getCosmoteUserAsync:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
1422 | +{ | ||
1423 | + [[Warply sharedService] getCosmoteUserWithSuccessBlock:guid :^(NSDictionary *response) { | ||
1424 | + if (success) { | ||
1425 | + success(response); | ||
1426 | + } | ||
1427 | + } failureBlock:^(NSError *error) { | ||
1428 | + if (failure) { | ||
1429 | + failure(error); | ||
1430 | + } | ||
1431 | + }]; | ||
1432 | +} | ||
1433 | + | ||
1421 | @end | 1434 | @end | ... | ... |
... | @@ -352,6 +352,8 @@ WL_VERSION_INTERFACE() | ... | @@ -352,6 +352,8 @@ WL_VERSION_INTERFACE() |
352 | 352 | ||
353 | - (void)verifyTicketWithSuccessBlock:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 353 | - (void)verifyTicketWithSuccessBlock:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
354 | 354 | ||
355 | +- (void)getCosmoteUserWithSuccessBlock:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
356 | + | ||
355 | - (void)addAddressWithSuccessBlock:(NSString*)friendlyName :(NSString*)addressName :(NSString*)addressNumber :(NSString*)postalCode :(NSNumber*)floorNumber :(NSString*)doorbel :(NSString*)region :(NSString*)latitude :(NSString*)longitude :(NSString*)notes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 357 | - (void)addAddressWithSuccessBlock:(NSString*)friendlyName :(NSString*)addressName :(NSString*)addressNumber :(NSString*)postalCode :(NSNumber*)floorNumber :(NSString*)doorbel :(NSString*)region :(NSString*)latitude :(NSString*)longitude :(NSString*)notes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
356 | 358 | ||
357 | - (void)getAddressWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 359 | - (void)getAddressWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
... | @@ -1366,6 +1366,43 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1366,6 +1366,43 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
1366 | }]; | 1366 | }]; |
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | +- (void)getCosmoteUserWithSuccessBlock:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
1370 | +{ | ||
1371 | + // NSString* appUuid = [NSString alloc]; | ||
1372 | + // appUuid = [WLKeychain getStringForKey:@"NBAPPUuid"]; | ||
1373 | + NSDictionary *postDictionary = @{@"user_identifier" : guid}; | ||
1374 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
1375 | + [self sendContextGetCosmoteUser:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
1376 | + NSDictionary* tokens = [NSDictionary alloc]; | ||
1377 | + tokens = [contextResponse objectForKey:@"result"]; | ||
1378 | + NSString* clientId = [NSString alloc]; | ||
1379 | + clientId = [tokens objectForKey:@"client_id"]; | ||
1380 | + NSString* refreshToken = [NSString alloc]; | ||
1381 | + refreshToken = [tokens objectForKey:@"refresh_token"]; | ||
1382 | + NSString* accessToken = [NSString alloc]; | ||
1383 | + accessToken = [tokens objectForKey:@"access_token"]; | ||
1384 | + NSString* clientSecret = [NSString alloc]; | ||
1385 | + clientSecret = [tokens objectForKey:@"client_secret"]; | ||
1386 | + [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
1387 | + [_db executeUpdate:@"CREATE TABLE requestVariables (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, client_id INTEGER, client_secret VARCHAR(255), access_token VARCHAR(255), refresh_token VARCHAR(255))"]; | ||
1388 | + WL_FMDBLogError | ||
1389 | + | ||
1390 | + [_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, access_token, refresh_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, accessToken, refreshToken]; | ||
1391 | + | ||
1392 | + NSDictionary *successResponse = @{@"result": @"success", @"status":@1}; | ||
1393 | + if (success) { | ||
1394 | + success(successResponse); | ||
1395 | + } | ||
1396 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
1397 | + NSLog(@"%@", successResponse ); | ||
1398 | + } failureBlock:^(NSError *error) { | ||
1399 | + if (failure) { | ||
1400 | + failure(error); | ||
1401 | + } | ||
1402 | + NSLog(@"Error at get Cosmote User %@", error ); | ||
1403 | + }]; | ||
1404 | +} | ||
1405 | + | ||
1369 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1406 | - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
1370 | { | 1407 | { |
1371 | NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction",@"communication"]}}; | 1408 | NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction",@"communication"]}}; |
... | @@ -2617,6 +2654,34 @@ return appIsRegisteredWithWarply; | ... | @@ -2617,6 +2654,34 @@ return appIsRegisteredWithWarply; |
2617 | return appIsRegisteredWithWarply; | 2654 | return appIsRegisteredWithWarply; |
2618 | } | 2655 | } |
2619 | 2656 | ||
2657 | +- (BOOL)sendContextGetCosmoteUser:(NSData*)context | ||
2658 | + successBlock:(void (^)(NSDictionary *contextResponse))successBlock | ||
2659 | + failureBlock:(void (^)(NSError *error))failureBlock | ||
2660 | +{ | ||
2661 | +BOOL appIsRegisteredWithWarply = [self isRegistrationValid]; | ||
2662 | + | ||
2663 | +if (WL_FEATURE_IS_DISABLED_WITH_KEY(WL_WARPLY_ENABLED)) | ||
2664 | + return appIsRegisteredWithWarply; | ||
2665 | + | ||
2666 | +if (appIsRegisteredWithWarply == NO) { | ||
2667 | + [_pendingOperationsQueue setSuspended:YES]; | ||
2668 | + [self registration]; | ||
2669 | +} | ||
2670 | +NSString *path = nil; | ||
2671 | + | ||
2672 | +NSInvocation *invocation = [self getCosmoteUserRequestInvocationWithType:WLContextRequestTypePost | ||
2673 | + data:context | ||
2674 | + path:path | ||
2675 | + successBlock:[successBlock copy] | ||
2676 | + failureBlock:[failureBlock copy]]; | ||
2677 | + | ||
2678 | + | ||
2679 | +NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithInvocation:invocation]; | ||
2680 | +[_pendingOperationsQueue addOperation:operation]; | ||
2681 | + | ||
2682 | +return appIsRegisteredWithWarply; | ||
2683 | +} | ||
2684 | + | ||
2620 | #pragma - Events | 2685 | #pragma - Events |
2621 | /////////////////////////////////////////////////////////////////////////////// | 2686 | /////////////////////////////////////////////////////////////////////////////// |
2622 | - (void)addEvent:(WLEvent *)event priority:(BOOL)priority | 2687 | - (void)addEvent:(WLEvent *)event priority:(BOOL)priority |
... | @@ -3007,6 +3072,28 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) | ... | @@ -3007,6 +3072,28 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) |
3007 | return invocation; | 3072 | return invocation; |
3008 | } | 3073 | } |
3009 | 3074 | ||
3075 | +- (NSInvocation *)getCosmoteUserRequestInvocationWithType:(WLContextRequestType)type | ||
3076 | + data:(NSData *)context | ||
3077 | + path:(NSString *)path | ||
3078 | + successBlock:(void (^)(NSDictionary *contextResponse))successBlock | ||
3079 | + failureBlock:(void (^)(NSError *error))failureBlock | ||
3080 | +{ | ||
3081 | + void (^ successBlockCopy)(void) = [successBlock copy]; | ||
3082 | + void (^ failureBlockCopy)(void) = [failureBlock copy]; | ||
3083 | + | ||
3084 | + NSMethodSignature *sgn = [self methodSignatureForSelector:@selector(getCosmoteUserRequestWithType:data:path:successBlock:failureBlock:)]; | ||
3085 | + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sgn]; | ||
3086 | + [invocation setTarget:self]; | ||
3087 | + [invocation setSelector:@selector(getCosmoteUserRequestWithType:data:path:successBlock:failureBlock:)]; | ||
3088 | + [invocation setArgument:&type atIndex:2]; | ||
3089 | + [invocation setArgument:&context atIndex:3]; | ||
3090 | + [invocation setArgument:&path atIndex:4]; | ||
3091 | + [invocation setArgument:&successBlockCopy atIndex:5]; | ||
3092 | + [invocation setArgument:&failureBlockCopy atIndex:6]; | ||
3093 | + [invocation retainArguments]; | ||
3094 | + return invocation; | ||
3095 | +} | ||
3096 | + | ||
3010 | - (NSInvocation *)resetPasswordRequestInvocationWithType:(WLContextRequestType)type | 3097 | - (NSInvocation *)resetPasswordRequestInvocationWithType:(WLContextRequestType)type |
3011 | data:(NSData *)context | 3098 | data:(NSData *)context |
3012 | path:(NSString *)path | 3099 | path:(NSString *)path |
... | @@ -4263,6 +4350,103 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) | ... | @@ -4263,6 +4350,103 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2) |
4263 | } | 4350 | } |
4264 | } | 4351 | } |
4265 | 4352 | ||
4353 | +- (void)getCosmoteUserRequestWithType:(WLContextRequestType)requestType | ||
4354 | + data:(NSData*)context | ||
4355 | + path:(NSString *)path | ||
4356 | + successBlock:(void (^)(id contextResponse))successBlock | ||
4357 | + failureBlock:(void (^)(NSError *error))failureBlock | ||
4358 | +{ | ||
4359 | + //Create REQUEST | ||
4360 | + NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@/partners/oauth/f83dfde1145e4c2da69793abb2f579af/token", _baseURL]; // /partners/cosmote/verify | ||
4361 | + WLLOG(@"[WARP Trace] HTTP URL: %@", urlString); | ||
4362 | + | ||
4363 | + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:100]; | ||
4364 | + | ||
4365 | + NSDictionary *parameters; | ||
4366 | + | ||
4367 | + if (context != nil) { | ||
4368 | + parameters = [NSJSONSerialization JSONObjectWithData:context options:NSJSONReadingAllowFragments error:NULL]; | ||
4369 | + } | ||
4370 | + | ||
4371 | + SuccessResponse successResponse = ^(NSURLSessionDataTask * _Nonnull task, id _Nullable JSON) { | ||
4372 | + if (JSON == nil) { | ||
4373 | + successBlock(@{@"status": @"0"}); | ||
4374 | + } | ||
4375 | + else { | ||
4376 | + | ||
4377 | +// NSData *responseData = [NSJSONSerialization dataWithJSONObject:JSON options:NSJSONWritingPrettyPrinted error:NULL]; | ||
4378 | +// NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; | ||
4379 | + // WLLOG(@"[WARP Trace] HTTP %@ Response:%@", request.HTTPMethod, responseString); | ||
4380 | + WLLOG(@"************ WARP %@ CONTEXT ******************", request.HTTPMethod); | ||
4381 | + WLLOG(@"[WARP Trace] HTTP Web Id: %@", _webId); | ||
4382 | + WLLOG(@"[WARP Trace] HTTP API Key: %@", _apiKey); | ||
4383 | + WLLOG(@"[WARP Trace] HTTP %@ Request URL: %@", request.HTTPMethod, request.URL.absoluteString); | ||
4384 | + NSString *contextString = [[NSString alloc] initWithData:context encoding:NSUTF8StringEncoding]; | ||
4385 | + WLLOG(@"[WARP Trace] HTTP %@ Request Body: %@", request.HTTPMethod, contextString); | ||
4386 | + WLLOG(@"*************************************************"); | ||
4387 | + NSDictionary *contextResponse=JSON; | ||
4388 | + | ||
4389 | + if (successBlock) | ||
4390 | + { | ||
4391 | + if ([path length]!=0) | ||
4392 | + { | ||
4393 | + successBlock([contextResponse valueForKey:path]); | ||
4394 | + return; | ||
4395 | + } | ||
4396 | + successBlock(contextResponse); | ||
4397 | + } | ||
4398 | + | ||
4399 | + } | ||
4400 | + }; | ||
4401 | + | ||
4402 | + FailureResponse faliureResponse = ^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { | ||
4403 | + WLLOG(@"************ WARP %@ CONTEXT ******************", request.HTTPMethod); | ||
4404 | + WLLOG(@"[WARP Trace] HTTP Web Id: %@", _webId); | ||
4405 | + WLLOG(@"[WARP Trace] HTTP API Key: %@", _apiKey); | ||
4406 | + WLLOG(@"[WARP Trace] HTTP %@ Request URL: %@", request.HTTPMethod, request.URL.absoluteString); | ||
4407 | + NSString *contextString = [[NSString alloc] initWithData:context encoding:NSUTF8StringEncoding]; | ||
4408 | + | ||
4409 | + | ||
4410 | + WLLOG(@"[WARP Trace] HTTP %@ Request Body: %@", request.HTTPMethod, contextString); | ||
4411 | + WLLOG(@"[WARP Trace] Error: %@", [error description]); | ||
4412 | + WLLOG(@"*************************************************"); | ||
4413 | + if (failureBlock) | ||
4414 | + failureBlock(error); | ||
4415 | + }; | ||
4416 | +// NSString *accessToken = [NSString alloc]; | ||
4417 | +// if ([_db tableExists:@"requestVariables"] == YES) { | ||
4418 | +// FMResultSet *accessTokenSet = [_db executeQuery:@"SELECT access_token FROM requestVariables WHERE id = 1;"]; | ||
4419 | +// while ([accessTokenSet next]) { | ||
4420 | +// accessToken = [[accessTokenSet resultDictionary][@"access_token"] stringValue]; | ||
4421 | +// } | ||
4422 | +// } | ||
4423 | + _httpClient.responseSerializer = [AFJSONResponseSerializer serializer]; | ||
4424 | + _httpClient.requestSerializer = [AFJSONRequestSerializer serializer]; | ||
4425 | + | ||
4426 | + //Set HTTP Headers | ||
4427 | + time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970]; | ||
4428 | + [_httpClient.requestSerializer setValue:[@"Basic " stringByAppendingString:@"MWlTM0EyNjcxT2Q0a1B5QkIydEs1ZU5uRENhR0NWQjQ6MjI4MjA4ZTliMTQzNGQ2MmIxNGI3ZDAzYjM2ZjUwMzg="] forHTTPHeaderField:@"Authorization"]; | ||
4429 | + [_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"]; | ||
4430 | + [_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"%lu", timestamp] forHTTPHeaderField:@"loyalty-date"]; | ||
4431 | + [_httpClient.requestSerializer setValue:[[NSString stringWithFormat:@"%@%lu", _apiKey, timestamp] SHA256Sum] forHTTPHeaderField:@"loyalty-signature"]; | ||
4432 | + [_httpClient.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; | ||
4433 | + [_httpClient.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; | ||
4434 | + [_httpClient.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"User-Agent"]; | ||
4435 | + [_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"ios:%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]] forHTTPHeaderField:@"loyalty-bundle-id"]; | ||
4436 | + [_httpClient.requestSerializer setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forHTTPHeaderField:@"unique-device-id"]; | ||
4437 | + [_httpClient.requestSerializer setValue:@"apple" forHTTPHeaderField:@"vendor"]; | ||
4438 | + [_httpClient.requestSerializer setValue:@"platform" forHTTPHeaderField:@"ios"]; | ||
4439 | + [_httpClient.requestSerializer setValue:@"os_version" forHTTPHeaderField:[[UIDevice currentDevice] systemVersion]]; | ||
4440 | + if (requestType == WLContextRequestTypePost) { | ||
4441 | +// NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:context options:NSJSONReadingAllowFragments error:NULL]; | ||
4442 | + | ||
4443 | + [_httpClient POST:urlString parameters:parameters progress:nil success:successResponse failure:faliureResponse]; | ||
4444 | + } | ||
4445 | + else { | ||
4446 | + [_httpClient GET:urlString parameters:parameters progress:nil success:successResponse failure:faliureResponse]; | ||
4447 | + } | ||
4448 | +} | ||
4449 | + | ||
4266 | /////////////////////////////////////////////////////////////////////////////// | 4450 | /////////////////////////////////////////////////////////////////////////////// |
4267 | - (void)runContextRequestWithType:(WLContextRequestType)requestType | 4451 | - (void)runContextRequestWithType:(WLContextRequestType)requestType |
4268 | data:(NSData*)context | 4452 | data:(NSData*)context | ... | ... |
... | @@ -2819,4 +2819,41 @@ public class swiftApi { | ... | @@ -2819,4 +2819,41 @@ public class swiftApi { |
2819 | } | 2819 | } |
2820 | } | 2820 | } |
2821 | 2821 | ||
2822 | + | ||
2823 | + public func getCosmoteUserAsync(guid: String, _ getCosmoteUserCallback: @escaping (_ responseData: GenericResponseModel?) -> Void) -> Void { | ||
2824 | + | ||
2825 | + let instanceOfMyApi = MyApi() | ||
2826 | + instanceOfMyApi.getCosmoteUserAsync(guid, requestCallback, failureBlock: requestFailureCallback) | ||
2827 | + | ||
2828 | + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void { | ||
2829 | + | ||
2830 | + if let responseDataDictionary = responseData as? [String: AnyObject] { | ||
2831 | + if (responseDataDictionary["status"] as? Int == 1) { | ||
2832 | + if let responseDataDictionary = responseData as? [String: Any] { | ||
2833 | + | ||
2834 | + let tempResponse = GenericResponseModel(dictionary: responseDataDictionary) | ||
2835 | + getCosmoteUserCallback(tempResponse); | ||
2836 | + | ||
2837 | + } else { | ||
2838 | + getCosmoteUserCallback(nil) | ||
2839 | + } | ||
2840 | + | ||
2841 | + } else { | ||
2842 | + getCosmoteUserCallback(nil) | ||
2843 | + } | ||
2844 | + | ||
2845 | + } else { | ||
2846 | + getCosmoteUserCallback(nil) | ||
2847 | + } | ||
2848 | + | ||
2849 | + } | ||
2850 | + | ||
2851 | + func requestFailureCallback(_ error: Error?) -> Void { | ||
2852 | + print("getCosmoteUser error: ") | ||
2853 | + print(error) | ||
2854 | + print("====================") | ||
2855 | + getCosmoteUserCallback(nil) | ||
2856 | + } | ||
2857 | + } | ||
2858 | + | ||
2822 | } | 2859 | } | ... | ... |
-
Please register or login to post a comment