From 7a65779625fe95f142210a2ae52aff1f916e94d1 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Tue, 31 Aug 2010 19:05:07 -0400 Subject: [PATCH] Finish up Ansel version 2 API support --- .../ApertureToAnselExportPlugin.m | 1 + ApertureToAnselExportPlugin/CHANGES | 1 + ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m | 20 +++- .../TURAnselKit/TURAnselConstants.h | 5 +- .../TURAnselKit/TURAnselConstants.m | 4 +- .../TURAnselKit/TURAnselGallery.m | 133 +++++++++++++-------- 6 files changed, 108 insertions(+), 56 deletions(-) diff --git a/ApertureToAnselExportPlugin/ApertureToAnselExportPlugin.m b/ApertureToAnselExportPlugin/ApertureToAnselExportPlugin.m index 13342844f..600100879 100644 --- a/ApertureToAnselExportPlugin/ApertureToAnselExportPlugin.m +++ b/ApertureToAnselExportPlugin/ApertureToAnselExportPlugin.m @@ -612,6 +612,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn // were returned as empty or null, so we need to check for that. // (Even if caption is nil, caption.length will still be zero, so we // don't need a seperate case for that). + NSLog(@"Image: %@", image); NSString *caption = [image objectForKey:@"caption"]; if (caption == (NSString *)[NSNull null] || [caption length] == 0) { caption = [image objectForKey:@"name"]; diff --git a/ApertureToAnselExportPlugin/CHANGES b/ApertureToAnselExportPlugin/CHANGES index c3b014427..35e637085 100644 --- a/ApertureToAnselExportPlugin/CHANGES +++ b/ApertureToAnselExportPlugin/CHANGES @@ -2,5 +2,6 @@ v1.0-git -------- +[mjr] Update for Ansel version 2.x API support [mjr] Load in 64 bit native mode. [mjr] initial CHANGES file creation diff --git a/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m b/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m index aa18f5860..a03f300c8 100644 --- a/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m +++ b/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m @@ -76,9 +76,17 @@ */ - (NSDictionary *)createNewGallery: (NSDictionary *)params { - NSArray *apiparams = [NSArray arrayWithObjects: @"ansel", params, nil]; - NSArray *order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, kTURAnselAPIParamGaleryParams, nil]; - + NSArray *apiparams; + NSArray *order; + + if ([[self valueForKey: @"version"] intValue] == 2) { + apiparams = [NSArray arrayWithObjects: params, nil]; + order = [NSArray arrayWithObjects: kTURAnselAPIParamGalleryParams, nil]; + } else { + apiparams = [NSArray arrayWithObjects: @"ansel", params, nil]; + order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, kTURAnselAPIParamGalleryParams, nil]; + } + NSDictionary *response = [self callRPCMethod: @"images.createGallery" withParams: apiparams withOrder: order]; @@ -291,12 +299,12 @@ NSArray *params; NSArray *order; - if (2 == [version intValue]) { - params = [[NSArray alloc] initWithObjects: [[NSDictionary alloc] initWithObjectsAndKeys: + if ([[self valueForKey: @"version"] intValue] == 2) { + params = [[NSArray alloc] initWithObjects: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: PERMS_EDIT], @"perm", [self valueForKey:@"username"], @"filter", nil] ,nil]; - order = [[NSArray arrayWithObjects kTURAnselAPIParamSingleParameter, nil]; + order = [NSArray arrayWithObjects: kTURAnselAPIParamSingleParameter, nil]; } else { // Assume it's version 1.x params = [[NSArray alloc] initWithObjects: diff --git a/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.h b/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.h index 7b495cf06..c27f94fd3 100644 --- a/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.h +++ b/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.h @@ -9,7 +9,7 @@ // Constants for the API parameter names. extern NSString * const kTURAnselAPIParamScope; -extern NSString * const kTURAnselAPIParamGaleryParams; +extern NSString * const kTURAnselAPIParamGalleryParams; extern NSString * const kTURAnselAPIParamPerms; extern NSString * const kTURAnselAPIParamParent; extern NSString * const kTURAnselAPIParamAllLevels; @@ -27,6 +27,9 @@ extern NSString * const kTURAnselAPIParamEncoding; // Constants specific to Ansel version 2 API parameters. extern NSString * const kTURAnselAPIParamSingleParameter; +extern NSString * const kTURAnselAPIParamView; +extern NSString * const kTURAnselAPIParamFull; +extern NSString * const kTURAnselAPIParamEncoding; // Constants for the dictionary keys used to describe/create TURAnselGallery extern NSString * const kTURAnselGalleryKeyId; diff --git a/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.m b/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.m index b361ee122..626443609 100644 --- a/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.m +++ b/ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.m @@ -10,7 +10,7 @@ // Constants for the API parameter names. NSString * const kTURAnselAPIParamScope = @"scope"; -NSString * const kTURAnselAPIParamGaleryParams = @"galleryParams"; +NSString * const kTURAnselAPIParamGalleryParams = @"galleryParams"; NSString * const kTURAnselAPIParamPerms = @"perms"; NSString * const kTURAnselAPIParamParent = @"parent"; NSString * const kTURAnselAPIParamAllLevels = @"allLevels"; @@ -27,6 +27,8 @@ NSString * const kTURAnselAPIParamAdditionalData = @"additionalData"; NSString * const kTURAnselAPIParamEncoding = @"encoding"; NSString * const kTURAnselAPIParamSingleParameter = @"params"; +NSString * const kTURAnselAPIParamView = @"view"; +NSString * const kTURAnselAPIParamFull = @"full"; // Ansel gallery attribtues. NSString * const kTURAnselGalleryKeyId = @"share_id"; diff --git a/ApertureToAnselExportPlugin/TURAnselKit/TURAnselGallery.m b/ApertureToAnselExportPlugin/TURAnselKit/TURAnselGallery.m index 4663cf2e4..6bb27d7f7 100644 --- a/ApertureToAnselExportPlugin/TURAnselKit/TURAnselGallery.m +++ b/ApertureToAnselExportPlugin/TURAnselKit/TURAnselGallery.m @@ -73,18 +73,31 @@ if (galleryKeyImageURL) { return galleryKeyImageURL; } else { - NSArray *params = [[NSArray alloc] initWithObjects: - @"ansel", // Scope - [NSNumber numberWithInt: galleryKeyImage], // Image Id - @"thumb", // Thumbnail type - [NSNumber numberWithBool:YES], // Full path - nil]; - - NSArray *order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, - kTURAnselAPIParamImageId, - kTURAnselAPIParamThumbnailStyle, - kTURAnselAPIParamFullPath, nil]; - + NSArray *params; + NSArray *order; + + if ([[anselController valueForKey:@"version"] intValue] == 2) { + // Version 2 API + params = [NSArray arrayWithObjects: + [NSNumber numberWithInt: galleryKeyImage], + [NSDictionary dictionaryWithObjectsAndKeys: @"thumb", kTURAnselAPIParamView, [NSNumber numberWithBool:YES], kTURAnselAPIParamFull, nil], + nil]; + order = [NSArray arrayWithObjects: kTURAnselAPIParamImageId, + kTURAnselAPIParamSingleParameter, + nil]; + } else { + params = [NSArray arrayWithObjects: + @"ansel", // Scope + [NSNumber numberWithInt: galleryKeyImage], // Image Id + @"thumb", // Thumbnail type + [NSNumber numberWithBool:YES], // Full path + nil]; + + order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, + kTURAnselAPIParamImageId, + kTURAnselAPIParamThumbnailStyle, + kTURAnselAPIParamFullPath, nil]; + } NSDictionary *response = [anselController callRPCMethod: @"images.getImageUrl" withParams: params withOrder: order]; @@ -107,26 +120,36 @@ - (NSMutableArray *)listImages { if (![imageList count]) { - NSArray *params = [[NSArray alloc] initWithObjects: - @"ansel", //Scope - [NSNumber numberWithInt: _galleryId], //Gallery Id - [NSNumber numberWithInt: 2], //PERMS_SHOW - @"thumb", // Thumbnail - [NSNumber numberWithBool:YES], // Full path - nil]; - NSArray *order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, - kTURAnselAPIParamGalleryId, - kTURAnselAPIParamPerms, - kTURAnselAPIParamThumbnailStyle, - kTURAnselAPIParamFullPath, nil]; - + NSArray *params; + NSArray *order; + +// if ([[anselController valueForKey:@"version"] intValue] == 2) { +// listImages hasn't been refactored yet in version 2 API +// } else { + params = [NSArray arrayWithObjects: + @"ansel", //Scope + [NSNumber numberWithInt: _galleryId], //Gallery Id + [NSNumber numberWithInt: 2], //PERMS_SHOW + @"thumb", // Thumbnail + [NSNumber numberWithBool:YES], // Full path + nil]; + order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, + kTURAnselAPIParamGalleryId, + kTURAnselAPIParamPerms, + kTURAnselAPIParamThumbnailStyle, + kTURAnselAPIParamFullPath, nil]; +// } NSDictionary *response = [anselController callRPCMethod: @"images.listImages" withParams: params withOrder: order]; if (response) { [imageList autorelease]; - imageList = [[response objectForKey: (id)kWSMethodInvocationResult] retain]; - + if ([[anselController valueForKey:@"version"] intValue] == 2) { + // images.listImages returns a hash in version 2, not an array + imageList = [NSMutableArray arrayWithArray: [[[response objectForKey: (id)kWSMethodInvocationResult] retain] allValues]]; + } else { + imageList = [[response objectForKey: (id)kWSMethodInvocationResult] retain]; + } NSLog(@"listImages: %@", imageList); } } @@ -179,8 +202,21 @@ #pragma mark PrivateAPI - (void)doUpload:(NSDictionary *)imageParameters { - // Need to build the params array now. - NSArray *params = [[NSArray alloc] initWithObjects: + + NSArray *params; + NSArray *order; + + if ([[anselController valueForKey:@"version"] intValue] == 2) { + params = [NSArray arrayWithObjects: [NSNumber numberWithInt: _galleryId], + [imageParameters valueForKey: @"data"], + [NSDictionary dictionaryWithObjectsAndKeys:@"base64", kTURAnselAPIParamEncoding, nil], + nil]; + order = [NSArray arrayWithObjects: kTURAnselAPIParamGalleryId, + kTURAnselAPIParamImageData, + kTURAnselAPIParamSingleParameter, + nil]; + } else { + params = [[NSArray alloc] initWithObjects: @"ansel", // app [NSNumber numberWithInt: _galleryId], // gallery_id [imageParameters valueForKey: @"data"], // image data array @@ -188,26 +224,27 @@ @"", // Additional gallery data to set? @"base64", // Image data encoding nil]; - NSArray *order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, - kTURAnselAPIParamGalleryId, - kTURAnselAPIParamImageData, - kTURAnselAPIParamSetAsDefault, - kTURAnselAPIParamAdditionalData, - kTURAnselAPIParamEncoding, nil]; - - // Send the request up to the controller - NSDictionary *result = [anselController callRPCMethod: @"images.saveImage" - withParams: params - withOrder: order]; - - if (result) { - if ([delegate respondsToSelector:@selector(TURAnselGalleryDidUploadImage:)]) { - [delegate performSelectorOnMainThread: @selector(TURAnselGalleryDidUploadImage:) - withObject: self - waitUntilDone: NO]; - } + order = [NSArray arrayWithObjects: kTURAnselAPIParamScope, + kTURAnselAPIParamGalleryId, + kTURAnselAPIParamImageData, + kTURAnselAPIParamSetAsDefault, + kTURAnselAPIParamAdditionalData, + kTURAnselAPIParamEncoding, nil]; + } + + // Send the request up to the controller + NSDictionary *result = [anselController callRPCMethod: @"images.saveImage" + withParams: params + withOrder: order]; + + if (result) { + if ([delegate respondsToSelector:@selector(TURAnselGalleryDidUploadImage:)]) { + [delegate performSelectorOnMainThread: @selector(TURAnselGalleryDidUploadImage:) + withObject: self + waitUntilDone: NO]; } + } - [params release]; + [params release]; } @end -- 2.11.0