From 84f483c1775b620010b0ab72b65dab27960907f9 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Sun, 28 Nov 2010 16:25:24 -0700 Subject: [PATCH 1/2] Added: (NSURL *)urlAPIMethodWithGET:(NSString *) arguments:(NSDictinary *) - Useful for blocking connections in threads, returns URL of API call (cherry picked from commit e8eecc4b86244e31d3591c06a02920e98fc532b1) --- Source/ObjectiveFlickr.h | 3 +++ Source/ObjectiveFlickr.m | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/Source/ObjectiveFlickr.h b/Source/ObjectiveFlickr.h index bd63e2a..97ab7a1 100644 --- a/Source/ObjectiveFlickr.h +++ b/Source/ObjectiveFlickr.h @@ -149,6 +149,9 @@ typedef id OFFlickrAPIRequestDelegateType; - (BOOL)callAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary *)inArguments; - (BOOL)callAPIMethodWithPOST:(NSString *)inMethodName arguments:(NSDictionary *)inArguments; +// methods to call from threads / blocking connections +- (NSURL *)urlAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary *)inArguments; + // image upload—we use NSInputStream here because we want to have flexibity; with this you can upload either a file or NSData from NSImage - (BOOL)uploadImageStream:(NSInputStream *)inImageStream suggestedFilename:(NSString *)inFilename MIMEType:(NSString *)inType arguments:(NSDictionary *)inArguments; diff --git a/Source/ObjectiveFlickr.m b/Source/ObjectiveFlickr.m index ca0ed7a..63630c9 100644 --- a/Source/ObjectiveFlickr.m +++ b/Source/ObjectiveFlickr.m @@ -357,6 +357,17 @@ - (BOOL)callAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary *) return [HTTPRequest performMethod:LFHTTPRequestGETMethod onURL:[NSURL URLWithString:URLString] withData:nil]; } +- (NSURL *)urlAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary *)inArguments +{ + // combine the parameters + NSMutableDictionary *newArgs = inArguments ? [NSMutableDictionary dictionaryWithDictionary:inArguments] : [NSMutableDictionary dictionary]; + [newArgs setObject:inMethodName forKey:@"method"]; + NSString *query = [context signedQueryFromArguments:newArgs]; + NSString *URLString = [NSString stringWithFormat:@"%@?%@", [context RESTAPIEndpoint], query]; + + return [NSURL URLWithString:URLString]; +} + - (BOOL)callAPIMethodWithPOST:(NSString *)inMethodName arguments:(NSDictionary *)inArguments { if ([HTTPRequest isRunning]) { From 11cc01c07b68f8fcb9f643365db5a9315f632619 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Sun, 28 Nov 2010 16:29:11 -0700 Subject: [PATCH 2/2] Added: (NSDictionary *)dictionaryFromRequestData:(NSData *) - Allows you to fetch data dictionary after calling urlAPIMethodWithGET: (cherry picked from commit f5a03b5ebc3fe0e7534b98539fa4fcb662a65c14) --- Source/ObjectiveFlickr.h | 1 + Source/ObjectiveFlickr.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Source/ObjectiveFlickr.h b/Source/ObjectiveFlickr.h index 97ab7a1..7e39555 100644 --- a/Source/ObjectiveFlickr.h +++ b/Source/ObjectiveFlickr.h @@ -151,6 +151,7 @@ typedef id OFFlickrAPIRequestDelegateType; // methods to call from threads / blocking connections - (NSURL *)urlAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary *)inArguments; +- (NSDictionary *)dictionaryFromRequestData:(NSData *)requestData; // image upload—we use NSInputStream here because we want to have flexibity; with this you can upload either a file or NSData from NSImage - (BOOL)uploadImageStream:(NSInputStream *)inImageStream suggestedFilename:(NSString *)inFilename MIMEType:(NSString *)inType arguments:(NSDictionary *)inArguments; diff --git a/Source/ObjectiveFlickr.m b/Source/ObjectiveFlickr.m index 63630c9..ecbf458 100644 --- a/Source/ObjectiveFlickr.m +++ b/Source/ObjectiveFlickr.m @@ -368,6 +368,10 @@ - (NSURL *)urlAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary return [NSURL URLWithString:URLString]; } +- (NSDictionary *)dictionaryFromRequestData:(NSData *)requestData { + return [OFXMLMapper dictionaryMappedFromXMLData:requestData]; +} + - (BOOL)callAPIMethodWithPOST:(NSString *)inMethodName arguments:(NSDictionary *)inArguments { if ([HTTPRequest isRunning]) {