Manos Chorianopoulos

Add getMapDataAsync request

......@@ -116,6 +116,7 @@
- (BOOL)sdkInitialised;
- (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;
- (void)getMapDataAsync:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void) sendEvent: (NSString *) eventName priority: (BOOL) priority;
- (void)updateRefreshTokenMA:(NSString*)access_token :(NSString*)refresh_token;
- (NSString*)getAccessTokenM;
......
......@@ -1846,6 +1846,18 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void)getMapDataAsync:(NSString*)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure {
[[Warply sharedService] getMapDataWithSuccessBlock:language :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void) sendEvent: (NSString *) eventName priority: (BOOL) priority {
NSString *event_Name = eventName;
NSNumber *time_submitted = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970]];
......
......@@ -427,6 +427,8 @@ WL_VERSION_INTERFACE()
- (void)getSingleCampaignWithSuccessBlock:(NSString *)sessionUuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getMapDataWithSuccessBlock:(NSString *)language :(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.
......
......@@ -4084,6 +4084,29 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}
///////////////////////////////////////////////////////////////////////////////
- (BOOL)getContextWithPathMap:(NSString *)path
language:(NSString *)language
successBlock:(void (^)(id contextResponse))successBlock
failureBlock:(void (^)(NSError *error))failureBlock
{
if ([self isRegistrationValid] == NO) {
[_pendingOperationsQueue setSuspended:YES];
[self registration];
}
NSInvocation *invocation = [self contextRequestInvocationWithTypeMap:WLContextRequestTypeGet
data:nil path:path language:language
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
......@@ -6212,6 +6235,30 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
return invocation;
}
- (NSInvocation *)contextRequestInvocationWithTypeMap:(WLContextRequestType)type
data:(NSData *)context
path:(NSString *)path
language:(NSString *)language
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(runContextRequestWithTypeMap:data:path:language:successBlock:failureBlock:)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sgn];
[invocation setTarget:self];
[invocation setSelector:@selector(runContextRequestWithTypeMap:data:path:language:successBlock:failureBlock:)];
[invocation setArgument:&type atIndex:2];
[invocation setArgument:&context atIndex:3];
[invocation setArgument:&path atIndex:4];
[invocation setArgument:&language 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
......@@ -6724,6 +6771,164 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
}
}
- (void)runContextRequestWithTypeMap:(WLContextRequestType)requestType
data:(NSData*)context
path:(NSString *)path
language:(NSString *)language
successBlock:(void (^)(id contextResponse))successBlock
failureBlock:(void (^)(NSError *error))failureBlock
{
NSString *environment = @"";
if ([_appUUID isEqualToString:@"0086a2088301440792091b9f814c2267"]) {
environment = @"prod";
} else {
environment = @"dev";
}
//Create REQUEST
NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@/partners/cosmote/%@/map_data?language=%@", _baseURL, environment, language]; // 'https://engage-stage.warp.ly/partners/cosmote/prod/map_data?language=el'
WLLOG(@"[WARP Trace] HTTP URL: %@", urlString);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
[request setTimeoutInterval:30.0];
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:@"result"];
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];
[_httpClient.requestSerializer setTimeoutInterval:30];
//Set HTTP Headers
time_t timestamp = (time_t) [[NSDate date] timeIntervalSince1970];
NSString *loyaltyDate = @"";
NSString *loyaltySignature = @"";
NSString *bundleId = @"";
@try {
loyaltyDate = [NSString stringWithFormat:@"%lu", timestamp];
loyaltySignature = [[NSString stringWithFormat:@"%@%lu", _apiKey, timestamp] SHA256Sum];
bundleId = [NSString stringWithFormat:@"ios:%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]];
}
@catch (NSException *exception) {
NSLog(@"HTTPHeaders error: %@", exception.reason);
if (failureBlock) {
NSError *error = nil;
failureBlock(error);
}
}
@finally {
// NSLog(@"Finally condition");
}
[_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:loyaltyDate forHTTPHeaderField:@"loyalty-date"];
[_httpClient.requestSerializer setValue:loyaltySignature 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:bundleId 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
......@@ -7670,6 +7875,23 @@ static void distanceFunc(sqlite3_context *context, int argc, sqlite3_value **arg
}
///////////////////////////////////////////////////////////////////////////////
- (void)getMapDataWithSuccessBlock:(NSString *)language :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[self getContextWithPathMap:nil language:language successBlock:^(NSDictionary *contextResponse) {
if (success){
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
NSLog(@"Error at get Map Data %@", error );
}];
}
///////////////////////////////////////////////////////////////////////////////
- (void)networkReachabilityReporting
{
__weak Warply *myself = self;
......
......@@ -2154,58 +2154,64 @@ public class swiftApi {
public class UnifiedCampaignModel: Codable {
private var couponset_uuid: String?
private var id: String?
private var title: String?
private var position: Int?
private var affiliatedId: String?
private var affiliatedId: Int?
private var shortDescription: String?
private var longDescription: String?
private var isHot: Bool?
private var logoImagePath: String?
private var bigLogoImagePath: String?
private var days: Int?
private var days: Array<String>?
private var dayText: String?
private var imagePath: String?
private var bigImagePath: String?
private var markerImagePath: String?
private var details: String?
private var store_id: String?
private var locations: Array<UnifiedCampaignLocation>?
public init() {
self.couponset_uuid = ""
self.id = ""
self.title = ""
self.position = 0
self.affiliatedId = ""
self.affiliatedId = 0
self.shortDescription = ""
self.longDescription = ""
self.isHot = false
self.logoImagePath = ""
self.bigLogoImagePath = ""
self.days = 0
self.days = []
self.dayText = ""
self.imagePath = ""
self.bigImagePath = ""
self.markerImagePath = ""
self.details = ""
self.store_id = ""
self.locations = []
}
public init(dictionary: [String: Any]) {
self.couponset_uuid = dictionary["COUPONSET_UUID"] as? String? ?? ""
self.id = dictionary["id"] as? String? ?? ""
self.title = dictionary["title"] as? String? ?? ""
self.position = dictionary["position"] as? Int? ?? 0
self.affiliatedId = dictionary["affiliatedId"] as? String? ?? ""
self.affiliatedId = dictionary["affiliatedId"] as? Int? ?? 0
self.shortDescription = dictionary["shortDescription"] as? String? ?? ""
self.longDescription = dictionary["longDescription"] as? String? ?? ""
self.isHot = dictionary["isHot"] as? Bool? ?? false
self.logoImagePath = dictionary["logoImagePath"] as? String? ?? ""
self.bigLogoImagePath = dictionary["bigLogoImagePath"] as? String? ?? ""
self.days = dictionary["days"] as? Int? ?? 0
self.days = dictionary["days"] as? Array<String>? ?? []
self.dayText = dictionary["dayText"] as? String? ?? ""
self.imagePath = dictionary["imagePath"] as? String? ?? ""
self.bigImagePath = dictionary["bigImagePath"] as? String? ?? ""
self.markerImagePath = dictionary["markerImagePath"] as? String? ?? ""
self.details = dictionary["details"] as? String? ?? ""
self.store_id = dictionary["store_id"] as? String? ?? ""
if let locationsData = dictionary["locations"] as? [[String : Any]?] {
var locationsArray:Array<UnifiedCampaignLocation> = []
......@@ -2221,6 +2227,15 @@ public class swiftApi {
}
}
public var _couponset_uuid: String {
get { // getter
return self.couponset_uuid ?? ""
}
set(newValue) { //setter
self.couponset_uuid = newValue
}
}
public var _id: String {
get { // getter
return self.id ?? ""
......@@ -2248,9 +2263,9 @@ public class swiftApi {
}
}
public var _affiliatedId: String {
public var _affiliatedId: Int {
get { // getter
return self.affiliatedId ?? ""
return self.affiliatedId ?? 0
}
set(newValue) { //setter
self.affiliatedId = newValue
......@@ -2302,9 +2317,9 @@ public class swiftApi {
}
}
public var _days: Int {
public var _days: Array<String> {
get { // getter
return self.days ?? 0
return self.days ?? []
}
set(newValue) { //setter
self.days = newValue
......@@ -2356,6 +2371,15 @@ public class swiftApi {
}
}
public var _store_id: String {
get { // getter
return self.store_id ?? ""
}
set(newValue) { //setter
self.store_id = newValue
}
}
public var _locations: Array<UnifiedCampaignLocation> {
get { // getter
return self.locations ?? []
......@@ -2376,7 +2400,7 @@ public class swiftApi {
private var telephone: String?
private var latitude: Double?
private var longitude: Double?
private var afiliateId: String?
private var afiliateId: Int?
private var url: String?
private var logoImage: String?
private var pinLogoImage: String?
......@@ -2390,7 +2414,7 @@ public class swiftApi {
self.telephone = ""
self.latitude = 0.0
self.longitude = 0.0
self.afiliateId = ""
self.afiliateId = 0
self.url = ""
self.logoImage = ""
self.pinLogoImage = ""
......@@ -2405,7 +2429,7 @@ public class swiftApi {
self.telephone = dictionary["telephone"] as? String? ?? ""
self.latitude = dictionary["latitude"] as? Double? ?? 0.0
self.longitude = dictionary["longitude"] as? Double? ?? 0.0
self.afiliateId = dictionary["afiliateId"] as? String? ?? ""
self.afiliateId = dictionary["afiliateId"] as? Int? ?? 0
self.url = dictionary["url"] as? String? ?? ""
self.logoImage = dictionary["logoImage"] as? String? ?? ""
self.pinLogoImage = dictionary["pinLogoImage"] as? String? ?? ""
......@@ -2483,9 +2507,9 @@ public class swiftApi {
}
}
public var _afiliateId: String {
public var _afiliateId: Int {
get { // getter
return self.afiliateId ?? ""
return self.afiliateId ?? 0
}
set(newValue) { //setter
self.afiliateId = newValue
......@@ -8160,7 +8184,83 @@ public class swiftApi {
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
getAvailableCouponsCallback(nil)
// getAvailableCouponsCallback(nil)
if let error = error as? NSError {
// if (error.code == 401) {
// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel()
// sessionEvent._sessionExpired = true
// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent)
// }
failureCallback(error.code)
} else {
failureCallback(-1)
}
}
}
public func getMapDataAsync(language: String, _ successCallback: @escaping (_ mapData: Array<UnifiedCampaignModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.getMapDataAsync(language, getMapDataAsyncCallback, failureBlock: getMapDataFailureCallback)
func getMapDataAsyncCallback(_ responseData: [AnyHashable: Any]?) -> Void {
var campaignsArray:Array<UnifiedCampaignModel> = []
if let responseDataDictionary = responseData as? [String: AnyObject] {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_map_data"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
if let responseDataOffers = responseDataDictionary["offers"] as? [[String : Any]?] {
for item in responseDataOffers {
if let itemDictionary = item {
let tempCampaign = UnifiedCampaignModel(dictionary: itemDictionary)
campaignsArray.append(tempCampaign)
}
}
successCallback(campaignsArray)
} else {
successCallback(nil)
}
} else {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_map_data"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
successCallback(nil)
}
}
func getMapDataFailureCallback(_ error: Error?) -> Void {
print("getMapData error: ")
print(error)
print("====================")
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_error_map_data"
dynatraceEvent._parameters = nil
SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
// successCallback(nil)
if let error = error as? NSError {
// if (error.code == 401) {
// let sessionEvent = swiftApi.LoyaltySDKSessionExpiredEventModel()
// sessionEvent._sessionExpired = true
// SwiftEventBus.post("sdk_session_expired", sender: sessionEvent)
// }
failureCallback(error.code)
} else {
failureCallback(-1)
}
}
}
......