more tests

This commit is contained in:
2016-04-17 20:21:18 +02:00
parent 97992a66cc
commit ead815ab65
7 changed files with 99 additions and 61 deletions
+3 -3
View File
@@ -32,12 +32,12 @@
- (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter
completion:(void (^)(void))handler;
completion:(void (^)(BOOL success))handler;
- (void)uploadToDropbox:(NSArray *)files
presenter:(UIViewController *)presenter
completion:(void (^)(void))handler;
completion:(void (^)(BOOL success))handler;
- (void)contentsOfPath:(NSString *)path
completion:(void (^)(NSArray *data))handler
completion:(void (^)(NSArray *data, BOOL success))handler
presenter:(UIViewController *)presenter;
- (void)createFolderAtPath:(NSString *)path
presenter:(UIViewController *)presenter;
+20 -11
View File
@@ -21,6 +21,11 @@
protocol:@"HTTP"
realm:nil
authenticationMethod:@"OAuth2"];
NSDictionary *credentials =
[[NSURLCredentialStorage sharedCredentialStorage]
credentialsForProtectionSpace:self.kDropboxProtectionSpace];
NSURLCredential *credential = [credentials.objectEnumerator nextObject];
self.token = credential.password;
return self;
}
@@ -156,7 +161,7 @@
* @param completion executed after completion
*/
- (void)contentsOfPath:(NSString *)path
completion:(void (^)(NSArray *data))handler
completion:(void (^)(NSArray *data, BOOL success))handler
presenter:(UIViewController *)presenter
{
@@ -250,9 +255,10 @@
.topViewController];
}
}];
handler(nil, NO);
}
else {
handler(data2);
handler(data2, YES);
}
}
}
@@ -265,6 +271,7 @@
.topViewController];
}];
handler(nil, NO);
}
}];
}
@@ -275,7 +282,7 @@
*/
- (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter
completion:(void (^)(void))handler
completion:(void (^)(BOOL success))handler
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
request.URL = [NSURL
@@ -320,6 +327,7 @@
valueForKey:@"error_summary"] == nil) {
[data writeToFile:[SharedDeclerations savePathForFile:string]
atomically:YES];
handler(YES);
}
else {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
@@ -361,6 +369,7 @@
.topViewController];
}
}];
handler(NO);
}
}
else if (error != nil) {
@@ -370,11 +379,10 @@
presentErrorAlert:error
presenter:presenter.navigationController
.topViewController];
}];
handler(NO);
}
}
handler();
}
/**
@@ -383,7 +391,7 @@
*/
- (void)uploadToDropbox:(NSArray *)files
presenter:(UIViewController *)presenter
completion:(void (^)(void))handler
completion:(void (^)(BOOL success))handler
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
request.URL =
@@ -434,6 +442,7 @@
.topViewController];
}];
handler(NO);
}
if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]
valueForKey:@"error_summary"] != nil) {
@@ -475,9 +484,9 @@
.topViewController];
}
}];
handler(NO);
}
}
handler();
}
@@ -566,7 +575,7 @@
[queue addOperationWithBlock:^{
// Exports (PMDG format)
[self contentsOfPath:nil
completion:^(NSArray *data) {
completion:^(NSArray *data, BOOL success) {
BOOL exports = false;
for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"]
@@ -585,7 +594,7 @@
presenter:presenter];
// NavData (3 files from QW Navigraph data
[self contentsOfPath:nil
completion:^(NSArray *data) {
completion:^(NSArray *data, BOOL success) {
BOOL exports = false;
for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"]
@@ -604,7 +613,7 @@
presenter:presenter.navigationController.topViewController];
// Backups of Saves
[self contentsOfPath:nil
completion:^(NSArray *data) {
completion:^(NSArray *data, BOOL success) {
BOOL exports = false;
for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"]
@@ -623,7 +632,7 @@
presenter:presenter.navigationController.topViewController];
// Old saves (FMC Planner + (or X?))
[self contentsOfPath:nil
completion:^(NSArray *data) {
completion:^(NSArray *data, BOOL success) {
BOOL exports = false;
for (NSDictionary *dict in data) {
if ([[dict valueForKey:@"name"]
+3 -3
View File
@@ -41,7 +41,7 @@
if ([self.title isEqualToString:@"Download"]) {
[dbClient
contentsOfPath:@"SAVES"
completion:^(NSArray *data) {
completion:^(NSArray *data, BOOL success) {
NSMutableArray *temp = [[NSMutableArray alloc] init];
if (data != nil) {
for (NSDictionary *dict in data) {
@@ -184,7 +184,7 @@
[queue addOperationWithBlock:^{
[dbClient downloadFromDropbox:_markList
presenter:self
completion:^{
completion:^(BOOL success) {
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
_sm.dbDownload.enabled = YES;
@@ -204,7 +204,7 @@
[dbClient
uploadToDropbox:_markList
presenter:self
completion:^{
completion:^(BOOL success) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
_sm.dbUpload.enabled = YES;
_sm.dbUpload.alpha = 1.0;
-5
View File
@@ -29,11 +29,6 @@
// Override point for customization after application launch.
_dbClient = [[DropboxV2ObjC alloc] init];
((AppDelegate *)[UIApplication sharedApplication].delegate).main = self;
NSDictionary *credentials =
[[NSURLCredentialStorage sharedCredentialStorage]
credentialsForProtectionSpace:_dbClient.kDropboxProtectionSpace];
NSURLCredential *credential = [credentials.objectEnumerator nextObject];
_dbClient.token = credential.password;
// Reset if user changed it
[_dbClient setupDropboxWithHandler:^{
}
+2 -2
View File
@@ -121,7 +121,7 @@
[queue addOperationWithBlock:^{
[dbClient
contentsOfPath:@"NAVDATA"
completion:^(NSArray *files) {
completion:^(NSArray *files, BOOL success) {
if (files != nil) {
NSMutableArray *dlList = [[NSMutableArray alloc] init];
for (NSDictionary *file in files) {
@@ -132,7 +132,7 @@
[dbClient
downloadFromDropbox:dlList
presenter:self
completion:^{
completion:^(BOOL success) {
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
_main.navDataActive = false;