Manos Chorianopoulos

fix sdk db error

......@@ -329,6 +329,10 @@ WL_VERSION_INTERFACE()
- (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)changePasswordWithSuccessBlock:(NSString*)oldPassword andNewPassword:(NSString*)newPassword :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getProfileWithSuccessBlock :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
......@@ -574,7 +574,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -820,7 +830,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
- (NSDictionary*)logout
{
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
NSLog(@"**************** WARPLY Logout *****************" );
return successResponse;
......@@ -903,6 +923,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
// TODO: ADD NEW SDK
- (void)refreshToken:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
......@@ -935,13 +956,82 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
[self refreshToken:^(NSDictionary *response) {
[self refreshToken2ndTry:^(NSDictionary *response) {
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
success(successResponse);
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
}];
}
NSLog(@"Error at token %@", error );
}
}];
}
- (void)refreshToken2ndTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
NSString *refreshToken = [NSString alloc];
while ([refreshTokenSet next]) {
refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue];
}
FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"];
NSString *clientId = [NSString alloc];
while ([clientIdSet next]) {
clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue];
}
FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"];
NSString *clientSecret = [NSString alloc];
while ([clientSecretSet next]) {
clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue];
}
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
[self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
if (success) {
[_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
success(successResponse);
}
} 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 refreshToken3rdTry:^(NSDictionary *response) {
// [_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [response objectForKey:@"access_token"], [response objectForKey:@"refresh_token"]];
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
success(successResponse);
} failureBlock:^(NSError *error) {
if (failure) {
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -952,6 +1042,59 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
- (void)refreshToken3rdTry:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
FMResultSet *refreshTokenSet = [_db executeQuery:@"SELECT refresh_token FROM requestVariables WHERE id = 1;"];
NSString *refreshToken = [NSString alloc];
while ([refreshTokenSet next]) {
refreshToken = [[refreshTokenSet resultDictionary][@"refresh_token"] stringValue];
}
FMResultSet *clientIdSet = [_db executeQuery:@"SELECT client_id FROM requestVariables WHERE id = 1;"];
NSString *clientId = [NSString alloc];
while ([clientIdSet next]) {
clientId = [[clientIdSet resultDictionary][@"client_id"] stringValue];
}
FMResultSet *clientSecretSet = [_db executeQuery:@"SELECT client_secret FROM requestVariables WHERE id = 1;"];
NSString *clientSecret = [NSString alloc];
while ([clientSecretSet next]) {
clientSecret = [[clientSecretSet resultDictionary][@"client_secret"] stringValue];
}
NSDictionary *postDictionary3 = @{@"client_id": clientId, @"client_secret": clientSecret, @"refresh_token": refreshToken, @"grant_type":@"refresh_token", };
NSData *jsonData3 = [NSJSONSerialization dataWithJSONObject:postDictionary3 options:0 error:NULL];
[self sendContext5:jsonData3 successBlock:^(NSDictionary *contextResponse) {
if (success) {
[_db executeUpdate:@"UPDATE requestVariables SET access_token = ?, refresh_token = ? WHERE id = 1", [contextResponse objectForKey:@"access_token"], [contextResponse objectForKey:@"refresh_token"]];
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
success(successResponse);
}
} failureBlock:^(NSError *error) {
if (failure) {
NSDictionary* dict = [NSDictionary alloc];
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
if (failure) {
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
}
NSLog(@"Error at token %@", error );
}
}];
}
- (void)changePasswordWithSuccessBlock:(NSString*)oldPassword andNewPassword:(NSString*)newPassword :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"old_password": oldPassword, @"new_password": newPassword, @"channel": @"mobile" };
......@@ -978,7 +1121,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1021,7 +1174,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1082,7 +1245,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1188,7 +1361,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1229,7 +1412,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1270,7 +1463,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1348,7 +1551,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1385,7 +1598,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1422,7 +1645,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1459,7 +1692,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1496,7 +1739,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1507,6 +1760,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
// TODO: ADD NEW SDK
- (void)verifyTicketWithSuccessBlock:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
NSString* appUuid = [NSString alloc];
......@@ -1524,11 +1778,21 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
accessToken = [tokens objectForKey:@"access_token"];
NSString* clientSecret = [NSString alloc];
clientSecret = [tokens objectForKey:@"client_secret"];
[_db executeUpdate:@"DROP TABLE requestVariables"];
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, access_token, refresh_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, accessToken, refreshToken];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
// [_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))"];
// WL_FMDBLogError
//
// [_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, access_token, refresh_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, accessToken, refreshToken];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, refreshToken, accessToken];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", clientId, clientSecret, refreshToken, accessToken];
}
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
if (success) {
......@@ -1561,11 +1825,22 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
accessToken = [tokens objectForKey:@"access_token"];
NSString* clientSecret = [NSString alloc];
clientSecret = [tokens objectForKey:@"client_secret"];
[_db executeUpdate:@"DROP TABLE requestVariables"];
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, access_token, refresh_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, accessToken, refreshToken];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
// [_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))"];
// WL_FMDBLogError
//
// [_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, access_token, refresh_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, accessToken, refreshToken];
// TODO: ADD NEW SDK
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", clientId, clientSecret, refreshToken, accessToken];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", clientId, clientSecret, refreshToken, accessToken];
}
NSDictionary *successResponse = @{@"result": @"success", @"status":@1};
if (success) {
......@@ -1611,7 +1886,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1648,7 +1933,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1685,7 +1980,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1726,7 +2031,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1763,7 +2078,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1800,7 +2125,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1882,7 +2217,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1919,7 +2264,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -1956,7 +2311,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2168,7 +2533,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2228,7 +2603,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2269,7 +2654,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2310,7 +2705,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2351,7 +2756,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2411,7 +2826,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -2448,7 +2873,17 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
failure(error);
}
NSLog(@"Error at token %@", error );
......@@ -5698,6 +6133,18 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
[_db executeUpdate:@"CREATE TABLE pois (id INTEGER PRIMARY KEY NOT NULL UNIQUE, lat NUMERIC, lon NUMERIC, radius NUMERIC)"];
}
// TODO: ADD NEW SDK
// [_db executeUpdate:@"DROP TABLE requestVariables"];
if ([_db tableExists:@"requestVariables"] == NO) {
[_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))"];
WL_FMDBLogError
[_db executeUpdate:@"INSERT INTO requestVariables (id, client_id, client_secret, refresh_token, access_token) VALUES (1, ?, ?, ?, ?)", @0, @"", @"", @""];
} else {
[_db executeUpdate:@"UPDATE requestVariables SET client_id = ? , client_secret = ?, refresh_token = ?, access_token = ? WHERE id = 1", @0, @"", @"", @""];
}
[_db makeFunctionNamed:@"DISTANCE" maximumArguments:4 withBlock:^(sqlite3_context *context, int argc, sqlite3_value **argv) {
distanceFunc(context, argc, argv);
}];
......