Finish up Ansel version 2 API support
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 31 Aug 2010 23:05:07 +0000 (19:05 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 31 Aug 2010 23:06:00 +0000 (19:06 -0400)
ApertureToAnselExportPlugin/ApertureToAnselExportPlugin.m
ApertureToAnselExportPlugin/CHANGES
ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m
ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.h
ApertureToAnselExportPlugin/TURAnselKit/TURAnselConstants.m
ApertureToAnselExportPlugin/TURAnselKit/TURAnselGallery.m

index 1334284..6001008 100644 (file)
@@ -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"];
index c3b0144..35e6370 100644 (file)
@@ -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
index aa18f58..a03f300 100644 (file)
  */
 - (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];
     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:
index 7b495cf..c27f94f 100644 (file)
@@ -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;
index b361ee1..6264436 100644 (file)
@@ -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";
index 4663cf2..6bb27d7 100644 (file)
     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];
 - (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);
         }
     }
 #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
                            @"",                                       // 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