From 2502f9352e0f77f8d01a5f8057b5b72681aae191 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Sun, 28 Nov 2010 16:14:28 -0700 Subject: [PATCH] Added (NSURL *)buddyIconSourceURLFromDictionary:(NSDictionary *)inDictionary - Returns the URL of a user's buddy/profile icon or default if none exists (cherry picked from commit d206c73e3a9994166ea92ea185e5192bcce06970) --- Source/ObjectiveFlickr.h | 1 + Source/ObjectiveFlickr.m | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Source/ObjectiveFlickr.h b/Source/ObjectiveFlickr.h index bd63e2a..a87f9de 100644 --- a/Source/ObjectiveFlickr.h +++ b/Source/ObjectiveFlickr.h @@ -58,6 +58,7 @@ extern NSString *const OFFlickrDeletePermission; // URL provisioning - (NSURL *)photoSourceURLFromDictionary:(NSDictionary *)inDictionary size:(NSString *)inSizeModifier; +- (NSURL *)buddyIconSourceURLFromDictionary:(NSDictionary *)inDictionary; - (NSURL *)photoWebPageURLFromDictionary:(NSDictionary *)inDictionary; - (NSURL *)loginURLFromFrobDictionary:(NSDictionary *)inFrob requestedPermission:(NSString *)inPermission; diff --git a/Source/ObjectiveFlickr.m b/Source/ObjectiveFlickr.m index ca0ed7a..92d7d44 100644 --- a/Source/ObjectiveFlickr.m +++ b/Source/ObjectiveFlickr.m @@ -134,6 +134,32 @@ - (NSURL *)photoSourceURLFromDictionary:(NSDictionary *)inDictionary size:(NSStr return [NSURL URLWithString:URLString]; } +- (NSURL *)buddyIconSourceURLFromDictionary:(NSDictionary *)inDictionary +{ + // http://farm{iconfarm}.static.flickr.com/{iconserver}/buddyicons/{nsid}.jpg + // http://www.flickr.com/images/buddyicon.jpg + + NSString *server = [inDictionary objectForKey:@"iconserver"]; + NSString *nsid = [inDictionary objectForKey:@"nsid"]; + + if (![server length] || [server intValue] <= 0 || ![nsid length]) { + return [NSURL URLWithString:@"http://www.flickr.com/images/buddyicon.jpg"]; + } + + NSMutableString *URLString = [NSMutableString stringWithString:@"http://"]; + + NSString *farm = [inDictionary objectForKey:@"iconfarm"]; + if ([farm length]) { + [URLString appendFormat:@"farm%@.", farm]; + } + + [URLString appendFormat:@"static.flickr.com/%@/buddyicons/%@.jpg", + server, nsid]; + + return [NSURL URLWithString:URLString]; +} + + - (NSURL *)photoWebPageURLFromDictionary:(NSDictionary *)inDictionary { return [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%@", photoWebPageSource, [inDictionary objectForKey:@"owner"], [inDictionary objectForKey:@"id"]]];