diff --git a/clients/ios-objc/photobackup/LAAppDelegate.m b/clients/ios-objc/photobackup/LAAppDelegate.m index 625ec82e3..5957405ad 100644 --- a/clients/ios-objc/photobackup/LAAppDelegate.m +++ b/clients/ios-objc/photobackup/LAAppDelegate.m @@ -8,6 +8,7 @@ #import "LAAppDelegate.h" #import "LACamliFile.h" +#import "LAViewController.h" #import @implementation LAAppDelegate @@ -27,7 +28,9 @@ NSAssert(credentials[@"camlistore_password"], @"no camlistore password specified"); self.client = [[LACamliClient alloc] initWithServer:[NSURL URLWithString:credentials[@"camlistore_url"]] username:credentials[@"camlistore_username"] andPassword:credentials[@"camlistore_password"]]; - + + [(LAViewController *)self.window.rootViewController setClient:self.client]; + self.library = [[ALAssetsLibrary alloc] init]; return YES; diff --git a/clients/ios-objc/photobackup/LACamliClient/LACamliClient.h b/clients/ios-objc/photobackup/LACamliClient/LACamliClient.h index c20d1d8ef..a18dbe294 100644 --- a/clients/ios-objc/photobackup/LACamliClient/LACamliClient.h +++ b/clients/ios-objc/photobackup/LACamliClient/LACamliClient.h @@ -28,9 +28,10 @@ @property BOOL authorizing; - (id)initWithServer:(NSURL *)server username:(NSString *)username andPassword:(NSString *)password; - - (void)discoveryWithUsername:(NSString *)user andPassword:(NSString *)pass; +- (void)getRecentItemsWithCompletion:(void (^)(NSArray *objects))completion; + - (BOOL)fileAlreadyUploaded:(LACamliFile *)file; - (void)addFile:(LACamliFile *)file withCompletion:(void (^)())completion; diff --git a/clients/ios-objc/photobackup/LACamliClient/LACamliClient.m b/clients/ios-objc/photobackup/LACamliClient/LACamliClient.m index 55fb9f6fb..11785230e 100644 --- a/clients/ios-objc/photobackup/LACamliClient/LACamliClient.m +++ b/clients/ios-objc/photobackup/LACamliClient/LACamliClient.m @@ -44,6 +44,48 @@ return self; } +#pragma mark - discovery + +// if we don't have blobroot with which to make these requests, we need to find it first +- (void)discoveryWithUsername:(NSString *)user andPassword:(NSString *)pass +{ + self.authorizing = YES; + + NSURLSessionConfiguration *discoverConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; + discoverConfig.HTTPAdditionalHeaders = @{@"Accept": @"text/x-camli-configuration", @"Authorization": [NSString stringWithFormat:@"Basic %@",[self encodedAuth]]}; + NSURLSession *discoverSession = [NSURLSession sessionWithConfiguration:discoverConfig delegate:self delegateQueue:nil]; + + NSURL *discoveryURL = [self.serverURL URLByAppendingPathComponent:@"ui/"]; + + NSURLSessionDataTask *data = [discoverSession dataTaskWithURL:discoveryURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + self.authorizing = NO; + + if (error) { + LALog(@"error discovery: %@",error); + } else { + + NSHTTPURLResponse *res = (NSHTTPURLResponse *)response; + + if (res.statusCode != 200) { + LALog(@"error with discovery: %@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); + } else { + NSError *parseError; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError]; + + self.blobRoot = json[@"blobRoot"]; + self.isAuthorized = YES; + [self.uploadQueue setSuspended:NO]; + + LALog(@"good discovery"); + } + } + }]; + + [data resume]; +} + +#pragma mark - upload methods + - (BOOL)fileAlreadyUploaded:(LACamliFile *)file { NSParameterAssert(file); @@ -80,49 +122,40 @@ [self.uploadQueue addOperation:op]; } -// if we don't have blobroot with which to make these requests, we need to find it first -- (void)discoveryWithUsername:(NSString *)user andPassword:(NSString *)pass -{ - self.authorizing = YES; - - NSURLSessionConfiguration *discoverConfig = [NSURLSessionConfiguration defaultSessionConfiguration]; - discoverConfig.HTTPAdditionalHeaders = @{@"Accept": @"text/x-camli-configuration", @"Authorization": [NSString stringWithFormat:@"Basic %@",[self encodedAuth]]}; - NSURLSession *discoverSession = [NSURLSession sessionWithConfiguration:discoverConfig delegate:self delegateQueue:nil]; - - NSURL *discoveryURL = [self.serverURL URLByAppendingPathComponent:@"ui/"]; - - NSURLSessionDataTask *data = [discoverSession dataTaskWithURL:discoveryURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - self.authorizing = NO; - - if (error) { - LALog(@"error discovery: %@",error); - } else { - - NSHTTPURLResponse *res = (NSHTTPURLResponse *)response; - - if (res.statusCode != 200) { - LALog(@"error with discovery: %@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); - } else { - NSError *parseError; - NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError]; - - self.blobRoot = json[@"blobRoot"]; - self.isAuthorized = YES; - [self.uploadQueue setSuspended:NO]; - - LALog(@"good discovery"); - } - } - }]; - - [data resume]; -} - - (NSURL *)statUrl { return [[self.serverURL URLByAppendingPathComponent:self.blobRoot] URLByAppendingPathComponent:@"camli/stat"]; } +#pragma mark - getting stuff + +- (void)getRecentItemsWithCompletion:(void (^)(NSArray *objects))completion +{ + NSMutableArray *objects = [NSMutableArray array]; + + NSURL *recentUrl = [[[[self.serverURL URLByAppendingPathComponent:@"my-search"] URLByAppendingPathComponent:@"camli"] URLByAppendingPathComponent:@"search"] URLByAppendingPathComponent:@"query"]; + + LALog(@"reent url: %@",recentUrl); + + NSDictionary *formData = @{@"describe": @{@"thumbnailSize": @"200"}, @"sort": @"1", @"limit": @"50", @"constraint": @{@"logical": @{@"op": @"and", @"a":@{@"camliType":@"permanode"}, @"b":@{@"permanode": @{@"modTime": @{}}}}}}; + + LALog(@"form data: %@",formData); + + NSMutableURLRequest *recentRequest = [NSMutableURLRequest requestWithURL:recentUrl]; + [recentRequest setHTTPMethod:@"POST"]; + [recentRequest setHTTPBody:[NSKeyedArchiver archivedDataWithRootObject:formData]]; + + NSURLSessionDataTask *recentData = [self.session dataTaskWithRequest:recentRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + LALog(@"got some response: %@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); + }]; + + [recentData resume]; + +// completion([NSArray arrayWithArray:objects]); +} + +#pragma mark - utility + - (NSString *)encodedAuth { NSString *auth = [NSString stringWithFormat:@"%@:%@",self.username,self.password]; diff --git a/clients/ios-objc/photobackup/LAViewController.h b/clients/ios-objc/photobackup/LAViewController.h index abe8502a1..8531105e2 100644 --- a/clients/ios-objc/photobackup/LAViewController.h +++ b/clients/ios-objc/photobackup/LAViewController.h @@ -8,6 +8,10 @@ #import +@class LACamliClient; + @interface LAViewController : UIViewController +@property LACamliClient *client; + @end diff --git a/clients/ios-objc/photobackup/LAViewController.m b/clients/ios-objc/photobackup/LAViewController.m index c9505eeb9..80320307f 100644 --- a/clients/ios-objc/photobackup/LAViewController.m +++ b/clients/ios-objc/photobackup/LAViewController.m @@ -7,6 +7,7 @@ // #import "LAViewController.h" +#import "LACamliClient.h" @interface LAViewController () @@ -17,6 +18,10 @@ - (void)viewDidLoad { [super viewDidLoad]; + + [self.client getRecentItemsWithCompletion:^(NSArray *objects) { + LALog(@"got objects: %@",objects); + }]; } #pragma mark - collection methods