[Flickrkit-svn] r385 - trunk
fraser at speirs.org
fraser at speirs.org
Wed Aug 1 09:25:06 UTC 2007
Author: fspeirs
Date: 2007-08-01 09:25:04 +0000 (Wed, 01 Aug 2007)
New Revision: 385
Modified:
trunk/FKPhoto.m
Log:
Modifies FKPhoto to POST metadata changes with form encoding rather than URL.
Modified: trunk/FKPhoto.m
===================================================================
--- trunk/FKPhoto.m 2007-07-26 14:38:08 UTC (rev 384)
+++ trunk/FKPhoto.m 2007-08-01 09:25:04 UTC (rev 385)
@@ -24,10 +24,6 @@
- (void)processSaveTitleAndDescriptionResponse: (NSData *)data;
- (void)processSaveGeoDataResponse:(NSData *)data;
- (void)processPhotoSizeLinksResponse:(NSData *)data;
-
-- (NSURL *)saveDatesURL;
-- (NSURL *)saveTitleAndDescriptionURL;
-- (NSURL *)saveGeoDataURL;
@end
@implementation FKPhoto
@@ -468,8 +464,48 @@
}
- (void)saveDatesToFlickrSynchronously:(BOOL)syncFlag {
- NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [self saveDatesURL]];
+ NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] initWithCapacity:10];
+
+ if([[self dateTaken] descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S"])
+ [post_dict setObject: [[self dateTaken] descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S"] forKey:@"date_taken"];
+ else
+ NSLog(@"No [[self dateTaken] descriptionWithCalendarFormat] in -[FKPhoto saveDatesToFlickrSynchronously");
+
+ [post_dict setObject: @"0" forKey:@"date_taken_granularity"];
+ [post_dict setObject: @"flickr.photos.setDates" forKey:@"method"];
+
+ if([self photoid])
+ [post_dict setObject: [self photoid] forKey:@"photo_id"];
+ else
+ NSLog(@"No photoid in -[FKPhoto saveDatesToFlickrSynchronously");
+
+ if([owner applicationKey])
+ [post_dict setObject: [owner applicationKey] forKey:@"api_key"];
+ else
+ NSLog(@"No applicationKey in -[FKPhoto saveDatesToFlickrSynchronously");
+
+ if([[self token] token])
+ [post_dict setObject: [[self token] token] forKey: @"auth_token"];
+
+ [post_dict setObject: [FKAPIUtils signatureForParameterDictionary: post_dict sharedSecret: [self applicationSharedSecret]]
+ forKey: @"api_sig"];
+
+ // We URL encode the date *after* signing because the verification is done after URL decode on Flickr.
+ if([[post_dict objectForKey: @"date_taken"] URLEncodedString])
+ [post_dict setObject: [[post_dict objectForKey: @"date_taken"] URLEncodedString] forKey: @"date_taken"];
+
+ // Now Generate the POST body
+ NSString *boundary = [[NSProcessInfo processInfo] globallyUniqueString];
+ NSString *boundaryString = [NSString stringWithFormat: @"multipart/form-data; boundary=%@", boundary];
+
+ NSData* regData = [FKAPIUtils generateFormData:post_dict withMIMEBoundary: boundary];
+
+ NSURL* url = [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/services/rest/", [[self delegate] hostname]]];
+ NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
+
+ [post addValue: boundaryString forHTTPHeaderField: @"Content-Type"];
[post setHTTPMethod: @"POST"];
+ [post setHTTPBody:regData];
if(syncFlag) {
NSError *err;
@@ -497,11 +533,40 @@
}
- (void)saveTitleAndDescriptionToFlickrSynchronously:(BOOL)syncFlag {
- NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [self saveTitleAndDescriptionURL]
- cachePolicy: NSURLRequestReloadIgnoringCacheData
- timeoutInterval: 10];
- [post setHTTPMethod: @"POST"];
+ NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] initWithCapacity:10];
+ if([self title])
+ [post_dict setObject: [self title] forKey:@"title"];
+ else
+ [post_dict setObject: @"" forKey: @"title"];
+
+ if([self descriptionText])
+ [post_dict setObject: [self descriptionText] forKey:@"description"];
+ [post_dict setObject: @"flickr.photos.setMeta" forKey:@"method"];
+ [post_dict setObject: [self photoid] forKey:@"photo_id"];
+
+ if([owner applicationKey])
+ [post_dict setObject: [owner applicationKey] forKey:@"api_key"];
+
+ if([[self token] token])
+ [post_dict setObject: [[self token] token] forKey: @"auth_token"];
+
+ [post_dict setObject: [FKAPIUtils signatureForParameterDictionary: post_dict sharedSecret: [self applicationSharedSecret]]
+ forKey: @"api_sig"];
+
+ // Now Generate the POST body
+ NSString *boundary = [[NSProcessInfo processInfo] globallyUniqueString];
+ NSString *boundaryString = [NSString stringWithFormat: @"multipart/form-data; boundary=%@", boundary];
+
+ NSData* regData = [FKAPIUtils generateFormData:post_dict withMIMEBoundary: boundary];
+
+ NSURL* url = [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/services/rest/", [[self delegate] hostname]]];
+ NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
+
+ [post addValue: boundaryString forHTTPHeaderField: @"Content-Type"];
+ [post setHTTPMethod: @"POST"];
+ [post setHTTPBody:regData];
+
if(syncFlag) {
NSError *err;
NSURLResponse *resp;
@@ -522,10 +587,39 @@
}
- (void)saveGeoDataToFlickrSynchronously:(BOOL)syncFlag {
- NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [self saveGeoDataURL]
- cachePolicy: NSURLRequestReloadIgnoringCacheData
- timeoutInterval: 10];
+ NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] initWithCapacity:10];
+
+ [post_dict setObject: @"flickr.photos.geo.setLocation" forKey:@"method"];
+ [post_dict setObject: [self photoid] forKey:@"photo_id"];
+
+ if([self latitude])
+ [post_dict setObject: [self latitude] forKey: @"lat"];
+
+ if([self longitude])
+ [post_dict setObject: [self longitude] forKey: @"lon"];
+
+ if([owner applicationKey])
+ [post_dict setObject: [owner applicationKey] forKey:@"api_key"];
+
+ if([[self token] token])
+ [post_dict setObject: [[self token] token] forKey: @"auth_token"];
+
+ [post_dict setObject: [FKAPIUtils signatureForParameterDictionary: post_dict sharedSecret: [self applicationSharedSecret]]
+ forKey: @"api_sig"];
+
+
+ // Now Generate the POST body
+ NSString *boundary = [[NSProcessInfo processInfo] globallyUniqueString];
+ NSString *boundaryString = [NSString stringWithFormat: @"multipart/form-data; boundary=%@", boundary];
+
+ NSData* regData = [FKAPIUtils generateFormData:post_dict withMIMEBoundary: boundary];
+
+ NSURL* url = [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/services/rest/", [self hostname]]];
+ NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
+
+ [post addValue: boundaryString forHTTPHeaderField: @"Content-Type"];
[post setHTTPMethod: @"POST"];
+ [post setHTTPBody:regData];
// Debugging
if([FKAPIUtils httpDebugLog])
@@ -943,131 +1037,4 @@
[(<FKPhotoDelegate>)[self delegate] photoDidDownloadPhotoSizeLinks: self];
[tree release];
}
-
-#pragma mark -
-#pragma mark URL Generation Functions
-- (NSURL *)saveDatesURL {
- NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] initWithCapacity:10];
-
- if([[self dateTaken] descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S"])
- [post_dict setObject: [[self dateTaken] descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S"] forKey:@"date_taken"];
- else
- NSLog(@"No [[self dateTaken] descriptionWithCalendarFormat] in -[FKPhoto saveDatesURL");
-
- [post_dict setObject: @"0" forKey:@"date_taken_granularity"];
- [post_dict setObject: @"flickr.photos.setDates" forKey:@"method"];
-
- if([self photoid])
- [post_dict setObject: [self photoid] forKey:@"photo_id"];
- else
- NSLog(@"No photoid in -[FKPhoto saveDatesURL");
-
- if([owner applicationKey])
- [post_dict setObject: [owner applicationKey] forKey:@"api_key"];
- else
- NSLog(@"No applicationKey in -[FKPhoto saveDatesURL");
-
- if([[self token] token])
- [post_dict setObject: [[self token] token] forKey: @"auth_token"];
-
- [post_dict setObject: [FKAPIUtils signatureForParameterDictionary: post_dict sharedSecret: [self applicationSharedSecret]]
- forKey: @"api_sig"];
-
- // We URL encode the date *after* signing because the verification is done after URL decode on Flickr.
- if([[post_dict objectForKey: @"date_taken"] URLEncodedString])
- [post_dict setObject: [[post_dict objectForKey: @"date_taken"] URLEncodedString] forKey: @"date_taken"];
-
- NSMutableString *parameters = [[NSMutableString alloc] init];
- int i;
- for(i=0; i < [[post_dict allKeys] count]; i++) {
- [parameters appendString: [[post_dict allKeys] objectAtIndex: i]];
- [parameters appendString: @"="];
- [parameters appendString: [post_dict objectForKey: [[post_dict allKeys] objectAtIndex: i]]];
- if(i+1<[[post_dict allKeys] count])
- [parameters appendFormat: @"&"];
- }
- return [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/services/rest/?%@", [[self delegate] hostname], parameters]];
-}
-
-/**
- * @method saveTitleAndDescriptionURL
- * @discussion Generates a URL to save the title and description to flickr.
- */
-- (NSURL *)saveTitleAndDescriptionURL {
- NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] initWithCapacity:10];
-
- if([self title])
- [post_dict setObject: [self title] forKey:@"title"];
- else
- [post_dict setObject: @"" forKey: @"title"];
-
- if([self descriptionText])
- [post_dict setObject: [self descriptionText] forKey:@"description"];
- [post_dict setObject: @"flickr.photos.setMeta" forKey:@"method"];
- [post_dict setObject: [self photoid] forKey:@"photo_id"];
-
- if([owner applicationKey])
- [post_dict setObject: [owner applicationKey] forKey:@"api_key"];
-
- if([[self token] token])
- [post_dict setObject: [[self token] token] forKey: @"auth_token"];
-
- [post_dict setObject: [FKAPIUtils signatureForParameterDictionary: post_dict sharedSecret: [self applicationSharedSecret]]
- forKey: @"api_sig"];
-
- NSMutableString *parameters = [[NSMutableString alloc] init];
- int i;
- for(i=0; i < [[post_dict allKeys] count]; i++) {
- NSString *key = [[post_dict allKeys] objectAtIndex: i];
- [parameters appendString: key];
- [parameters appendString: @"="];
- if([key isEqualToString: @"title"] || [key isEqualToString: @"description"])
- [parameters appendString: [[post_dict objectForKey: key] URLEncodedString]];
- else
- [parameters appendString: [post_dict objectForKey: key]];
- if(i+1<[[post_dict allKeys] count])
- [parameters appendFormat: @"&"];
- }
-
- return [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/services/rest/?%@", [[self delegate] hostname], parameters]];
-}
-
-/**
- * @method saveGeoDataURL
- * @discussion Generates a URL to save lat/lon to flickr.
- */
-- (NSURL *)saveGeoDataURL {
- NSMutableDictionary* post_dict = [[NSMutableDictionary alloc] initWithCapacity:10];
-
- [post_dict setObject: @"flickr.photos.geo.setLocation" forKey:@"method"];
- [post_dict setObject: [self photoid] forKey:@"photo_id"];
-
- if([self latitude])
- [post_dict setObject: [self latitude] forKey: @"lat"];
-
- if([self longitude])
- [post_dict setObject: [self longitude] forKey: @"lon"];
-
- if([owner applicationKey])
- [post_dict setObject: [owner applicationKey] forKey:@"api_key"];
-
- if([[self token] token])
- [post_dict setObject: [[self token] token] forKey: @"auth_token"];
-
- [post_dict setObject: [FKAPIUtils signatureForParameterDictionary: post_dict sharedSecret: [self applicationSharedSecret]]
- forKey: @"api_sig"];
-
- NSMutableString *parameters = [[NSMutableString alloc] init];
- int i;
- for(i=0; i < [[post_dict allKeys] count]; i++) {
- NSString *key = [[post_dict allKeys] objectAtIndex: i];
- [parameters appendString: key];
- [parameters appendString: @"="];
- [parameters appendString: [post_dict objectForKey: key]];
- if(i+1<[[post_dict allKeys] count])
- [parameters appendFormat: @"&"];
- }
-
- return [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/services/rest/?%@", [[self delegate] hostname], parameters]];
-}
@end
\ No newline at end of file
More information about the Flickrkit-svn
mailing list