Manos Chorianopoulos

getSingleCampaignAsync and new badge functionality

......@@ -172,6 +172,10 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
let vc = storyboard.instantiateViewController(withIdentifier: "ContextualViewController") as! SwiftWarplyFramework.ContextualViewController
vc.ccms = campaigns[indexPath.row]._ccms
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
} else if (campaigns[indexPath.row]._type != nil && campaigns[indexPath.row]._type == "telco") {
let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
......@@ -185,6 +189,10 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
vc.ccms = item
vc.campaign = campaigns[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
}
......@@ -217,6 +225,10 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
}
......@@ -272,6 +284,10 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
} else {
let seasonalEvent = swiftApi.LoyaltyGiftsForYouOfferClickEvent()
seasonalEvent._title = campaigns[indexPath.row]._title ?? ""
......@@ -281,5 +297,18 @@ extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
}
}
}
func getSingleCampaignAsyncRequest(sessionUuid: String) {
swiftApi().getSingleCampaignAsync(sessionUuid: sessionUuid, getSingleCampaignCallback)
}
func getSingleCampaignCallback (_ getSingleCampaignData: swiftApi.VerifyTicketResponseModel?) -> Void {
if (getSingleCampaignData != nil) {
DispatchQueue.main.async {
}
} else {
}
}
}
......
......@@ -114,6 +114,10 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
let vc = storyboard.instantiateViewController(withIdentifier: "ContextualViewController") as! SwiftWarplyFramework.ContextualViewController
vc.ccms = campaigns[indexPath.row]._ccms
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
} else if (campaigns[indexPath.row]._type != nil && campaigns[indexPath.row]._type == "telco") {
let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
......@@ -127,6 +131,10 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
vc.ccms = item
vc.campaign = campaigns[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
}
}
......@@ -158,6 +166,10 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
}
......@@ -218,6 +230,23 @@ extension MFYViewController: UITableViewDelegate, UITableViewDataSource{
vc.campaignUrl = url
vc.params = params
self.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaigns[indexPath.row].session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
}
func getSingleCampaignAsyncRequest(sessionUuid: String) {
swiftApi().getSingleCampaignAsync(sessionUuid: sessionUuid, getSingleCampaignCallback)
}
func getSingleCampaignCallback (_ getSingleCampaignData: swiftApi.VerifyTicketResponseModel?) -> Void {
if (getSingleCampaignData != nil) {
DispatchQueue.main.async {
}
} else {
}
}
......
......@@ -103,6 +103,7 @@
- (void)didReceiveNotification:(NSDictionary *)payload;
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
- (void)editProfileAsync:(NSString*)firstname andLastname:(NSString*)lastname andEmail:(NSString *)email andSalutation:(NSString *)salutation andMsisdn:(NSString *)msisdn 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)getSingleCampaignAsync:(NSString*)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
@end
#endif /* MyApi_h */
......
......@@ -1627,4 +1627,16 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void)getSingleCampaignAsync:(NSString*)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure {
[[Warply sharedService] getSingleCampaignWithSuccessBlock:sessionUuid :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end
......
......@@ -402,6 +402,9 @@ WL_VERSION_INTERFACE()
- (void) validateCouponWithSuccessBlock:(NSString*) coupon :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)loginCosmoteWithSuccessBlock:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getSingleCampaignWithSuccessBlock:(NSString *)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
/*!
@abstract Get the full page add accordint to the display_type of a campaign.
@attributeblock successBlock This block is called when getInbox is sucessful and allOffers is empty or nil and returns an array with the available WLInboxItem items. Otherwise, the allOffers array is filtered.
......
......@@ -2646,6 +2646,29 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}
///////////////////////////////////////////////////////////////////////////////
- (BOOL)getContextWithPathCampaign:(NSString *)path
sessionUuid:(NSString *)sessionUuid
successBlock:(void (^)(id contextResponse))successBlock
failureBlock:(void (^)(NSError *error))failureBlock
{
if ([self isRegistrationValid] == NO) {
[_pendingOperationsQueue setSuspended:YES];
[self registration];
}
NSInvocation *invocation = [self contextRequestInvocationWithTypeCampaign:WLContextRequestTypeGet
data:nil path:path sessionUuid:sessionUuid
successBlock:[successBlock copy]
failureBlock:[failureBlock copy]];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithInvocation:invocation];
[_pendingOperationsQueue addOperation:operation];
return [self isRegistrationValid];
}
///////////////////////////////////////////////////////////////////////////////
- (BOOL)sendContext:(NSData*)context
successBlock:(void (^)(NSDictionary *contextResponse))successBlock
failureBlock:(void (^)(NSError *error))failureBlock
......@@ -4600,6 +4623,30 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
return invocation;
}
- (NSInvocation *)contextRequestInvocationWithTypeCampaign:(WLContextRequestType)type
data:(NSData *)context
path:(NSString *)path
sessionUuid:(NSString *)sessionUuid
successBlock:(void (^)(NSDictionary *contextResponse))successBlock
failureBlock:(void (^)(NSError *error))failureBlock
{
void (^ successBlockCopy)(void) = [successBlock copy];
void (^ failureBlockCopy)(void) = [failureBlock copy];
NSMethodSignature *sgn = [self methodSignatureForSelector:@selector(runContextRequestWithTypeCampaign:data:path:sessionUuid:successBlock:failureBlock:)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sgn];
[invocation setTarget:self];
[invocation setSelector:@selector(runContextRequestWithTypeCampaign:data:path:sessionUuid:successBlock:failureBlock:)];
[invocation setArgument:&type atIndex:2];
[invocation setArgument:&context atIndex:3];
[invocation setArgument:&path atIndex:4];
[invocation setArgument:&sessionUuid atIndex:5];
[invocation setArgument:&successBlockCopy atIndex:6];
[invocation setArgument:&failureBlockCopy atIndex:7];
[invocation retainArguments];
return invocation;
}
- (NSInvocation *)contextRequestInvocationWithType2:(WLContextRequestType)type
data:(NSData *)context
path:(NSString *)path
......@@ -4974,6 +5021,134 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
}
}
- (void)runContextRequestWithTypeCampaign:(WLContextRequestType)requestType
data:(NSData*)context
path:(NSString *)path
sessionUuid:(NSString *)sessionUuid
successBlock:(void (^)(id contextResponse))successBlock
failureBlock:(void (^)(NSError *error))failureBlock
{
//Create REQUEST
NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@/api/session/%@", _baseURL, sessionUuid];
WLLOG(@"[WARP Trace] HTTP URL: %@", urlString);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:100];
NSDictionary *parameters;
if (context != nil) {
parameters = [NSJSONSerialization JSONObjectWithData:context options:NSJSONReadingAllowFragments error:NULL];
}
SuccessResponse successResponse = ^(NSURLSessionDataTask * _Nonnull task, id _Nullable JSON) {
if (JSON == nil) {
successBlock(@{@"status": @"0"});
}
else {
// NSData *responseData = [NSJSONSerialization dataWithJSONObject:JSON options:NSJSONWritingPrettyPrinted error:NULL];
// NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// WLLOG(@"[WARP Trace] HTTP %@ Response:%@", request.HTTPMethod, responseString);
WLLOG(@"************ WARP %@ CONTEXT ******************", request.HTTPMethod);
WLLOG(@"[WARP Trace] HTTP Web Id: %@", _webId);
WLLOG(@"[WARP Trace] HTTP API Key: %@", _apiKey);
WLLOG(@"[WARP Trace] HTTP %@ Request URL: %@", request.HTTPMethod, request.URL.absoluteString);
NSString *contextString = [[NSString alloc] initWithData:context encoding:NSUTF8StringEncoding];
WLLOG(@"[WARP Trace] HTTP %@ Request Body: %@", request.HTTPMethod, contextString);
WLLOG(@"*************************************************");
NSDictionary *contextResponse=[JSON valueForKey:@"context"];
if ([JSON objectForKey:@"status"]) {
int status = [[JSON valueForKey:@"status"] intValue];
if (status != WLResultCodesSuccess)
{
if ((status == WLResultCodesInvalidWebID) || (status == WLResultCodesDeviceRegistrationFailed))
{
self.webId = nil;
self.apiKey = nil;
[_pendingOperationsQueue setSuspended:YES];
}
NSString *errorDescrition = (status <= [WLResultCodesDescriptions count]) && status > 0 ? (WLResultCodesDescriptions[(status-1)]) : ([NSString stringWithFormat:@"Internal WARP Server error %d", status]);
NSDictionary *eDict = @{NSLocalizedDescriptionKey: errorDescrition};
NSError *error = [NSError errorWithDomain:WARP_ERROR_DOMAIN code:status userInfo:eDict];
if (failureBlock)
failureBlock(error);
return;
}
if (successBlock)
{
if ([path length]!=0)
{
successBlock([contextResponse valueForKey:path]);
return;
}
successBlock(contextResponse);
}
}else{
NSError *error = [NSError errorWithDomain:WARP_ERROR_DOMAIN code:1026 userInfo:@{NSLocalizedDescriptionKey: NSLocalizedString(@"Empty response", @"Warply")}];
if (failureBlock)
failureBlock(error);
}
}
};
FailureResponse faliureResponse = ^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
WLLOG(@"************ WARP %@ CONTEXT ******************", request.HTTPMethod);
WLLOG(@"[WARP Trace] HTTP Web Id: %@", _webId);
WLLOG(@"[WARP Trace] HTTP API Key: %@", _apiKey);
WLLOG(@"[WARP Trace] HTTP %@ Request URL: %@", request.HTTPMethod, request.URL.absoluteString);
NSString *contextString = [[NSString alloc] initWithData:context encoding:NSUTF8StringEncoding];
WLLOG(@"[WARP Trace] HTTP %@ Request Body: %@", request.HTTPMethod, contextString);
WLLOG(@"[WARP Trace] Error: %@", [error description]);
WLLOG(@"*************************************************");
if (failureBlock)
failureBlock(error);
};
_httpClient.responseSerializer = [AFJSONResponseSerializer serializer];
_httpClient.requestSerializer = [AFJSONRequestSerializer serializer];
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
[_httpClient.requestSerializer setValue:_webId forHTTPHeaderField:@"loyalty-web-id"];
[_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"%lu", timestamp] forHTTPHeaderField:@"loyalty-date"];
[_httpClient.requestSerializer setValue:[[NSString stringWithFormat:@"%@%lu", _apiKey, timestamp] SHA256Sum] forHTTPHeaderField:@"loyalty-signature"];
[_httpClient.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[_httpClient.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[_httpClient.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"User-Agent"];
[_httpClient.requestSerializer setValue:[NSString stringWithFormat:@"ios:%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]] forHTTPHeaderField:@"loyalty-bundle-id"];
[_httpClient.requestSerializer setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forHTTPHeaderField:@"unique-device-id"];
[_httpClient.requestSerializer setValue:@"apple" forHTTPHeaderField:@"vendor"];
[_httpClient.requestSerializer setValue:@"platform" forHTTPHeaderField:@"ios"];
[_httpClient.requestSerializer setValue:@"os_version" forHTTPHeaderField:[[UIDevice currentDevice] systemVersion]];
[_httpClient.requestSerializer setValue:@"mobile" forHTTPHeaderField:@"channel"];
if (requestType == WLContextRequestTypePost) {
// NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:context options:NSJSONReadingAllowFragments error:NULL];
[_httpClient POST:urlString parameters:parameters progress:nil success:successResponse failure:faliureResponse];
}
else {
[_httpClient GET:urlString parameters:parameters progress:nil success:successResponse failure:faliureResponse];
}
}
- (void)runContextRequestWithTypeCosmote:(WLContextRequestType)requestType
data:(NSData*)context
path:(NSString *)path
......@@ -5714,6 +5889,23 @@ static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **arg
}
///////////////////////////////////////////////////////////////////////////////
- (void)getSingleCampaignWithSuccessBlock:(NSString *)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[self getContextWithPathCampaign:nil sessionUuid:sessionUuid successBlock:^(NSDictionary *contextResponse) {
if (success){
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
NSLog(@"Error at get Single Campaign %@", error );
}];
}
///////////////////////////////////////////////////////////////////////////////
- (void)networkReachabilityReporting
{
__weak Warply *myself = self;
......
......@@ -4921,6 +4921,10 @@ public class swiftApi {
vc.campaign = campaign
controller.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
}
......@@ -4933,6 +4937,22 @@ public class swiftApi {
vc.campaignUrl = swiftApi().constructCampaignUrl(campaign)
vc.params = swiftApi().constructCampaignParams(campaign)
controller.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = campaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
}
func getSingleCampaignAsyncRequest(sessionUuid: String) {
swiftApi().getSingleCampaignAsync(sessionUuid: sessionUuid, getSingleCampaignCallback)
}
func getSingleCampaignCallback (_ getSingleCampaignData: swiftApi.VerifyTicketResponseModel?) -> Void {
if (getSingleCampaignData != nil) {
DispatchQueue.main.async {
}
} else {
}
}
}
......@@ -4962,6 +4982,10 @@ public class swiftApi {
vc.campaignUrl = swiftApi().constructCcmsUrl(loyaltyCampaign, ccms)
vc.params = swiftApi().constructCcmsParams(loyaltyCampaign, ccms)
controller.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = loyaltyCampaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
} else if (isTelco && (loyaltyCampaign.session_uuid == ccms._loyaltyCampaignId)) {
......@@ -4971,11 +4995,27 @@ public class swiftApi {
vc.ccms = ccms
vc.campaign = loyaltyCampaign
controller.navigationController?.pushViewController(vc, animated: true)
if let sessionUuid = loyaltyCampaign.session_uuid {
getSingleCampaignAsyncRequest(sessionUuid: sessionUuid)
}
break;
}
}
}
func getSingleCampaignAsyncRequest(sessionUuid: String) {
swiftApi().getSingleCampaignAsync(sessionUuid: sessionUuid, getSingleCampaignCallback)
}
func getSingleCampaignCallback (_ getSingleCampaignData: swiftApi.VerifyTicketResponseModel?) -> Void {
if (getSingleCampaignData != nil) {
DispatchQueue.main.async {
}
} else {
}
}
}
......@@ -5647,4 +5687,56 @@ public class swiftApi {
}
public func getSingleCampaignAsync(sessionUuid: String, _ getSingleCampaignCallback: @escaping (_ getSingleCampaignData: VerifyTicketResponseModel?) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.getSingleCampaignAsync(sessionUuid, getSingleCampaignAsyncCallback, failureBlock: getSingleCampaignFailureCallback)
func getSingleCampaignAsyncCallback(_ getSingleCampaignData: [AnyHashable: Any]?) -> Void {
swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback)
func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
if (campaignsData != nil) {
DispatchQueue.main.async {
}
} else {
}
}
if let getSingleCampaignDataDictionary = getSingleCampaignData as? [String: Any] {
let tempResponse = VerifyTicketResponseModel(dictionary: getSingleCampaignDataDictionary)
getSingleCampaignCallback(tempResponse);
if (tempResponse.getStatus == 1) {
}
} else {
getSingleCampaignCallback(nil)
}
}
func getSingleCampaignFailureCallback(_ error: Error?) -> Void {
swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback)
func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
if (campaignsData != nil) {
DispatchQueue.main.async {
}
} else {
}
}
print("getSingleCampaign error: ")
print(error)
print("====================")
getSingleCampaignCallback(nil)
}
}
}
......