La Vita è Bella

2007-03-11

My first ever Obj-C hack: Google Reader Notifier

UPDATED: Troels Bay have use another way to do it, please wait for his official build :P

Google Reader Notifier by Troels Bay is a great open source application that provide a desktop notifier for Google Reader, the online feed reader, and also a feed subscriber. As I'm using Camino as my browser, which didn't have a build-in RSS support, I need it even more to subscribe feeds to Google Reader with one click. (not just "notifier" :D )

But when subscribe with preview, if there's a "?" in the URL, the problem is that Google Reader will ignore the part after "?". So that for example my photos on Flickr, "http://api.flickr.com/services/feeds/photos_public.gne?id=76236359@N00&format=rss_200" , will be recognised by Google as "http://api.flickr.com/services/feeds/photos_public.gne".

So I wrote this patch to escape URL before submit to Google.

 1 --- Google Reader copy/GRController.m   2007-03-11 18:45:56.000000000 +0800
 2 +++ Google Reader/GRController.m        2007-03-11 18:49:46.000000000 +0800
 3 @@ -1610,7 +1610,15 @@
 4  
 5         if ([[prefs valueForKey:@"dontVerifySubscription"] boolValue] != YES) {
 6  
 7 -               [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[[NSString stringWithFormat:@"%@://www.google.com/reader/preview/*/feed/", [self getURLPrefix]] stringByAppendingString:url]]];                    
 8 +               NSMutableString * escapedUrl = [NSMutableString stringWithCapacity: ([url length]*3)];   // for the worst case the length will growth to 3 times
 9 +               [escapedUrl setString:url];
10 +               [escapedUrl replaceOccurrencesOfString:@"?" withString:@"%3F" options:0 range:NSMakeRange(0, [escapedUrl length])];
11 +               [escapedUrl replaceOccurrencesOfString:@"&" withString:@"%26" options:0 range:NSMakeRange(0, [escapedUrl length])];
12 +               [escapedUrl replaceOccurrencesOfString:@":" withString:@"%3A" options:0 range:NSMakeRange(0, [escapedUrl length])];
13 +               [escapedUrl replaceOccurrencesOfString:@"/" withString:@"%2F" options:0 range:NSMakeRange(0, [escapedUrl length])];
14 +               [escapedUrl replaceOccurrencesOfString:@"=" withString:@"%3D" options:0 range:NSMakeRange(0, [escapedUrl length])];
15 +
16 +               [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[[NSString stringWithFormat:@"%@://www.google.com/reader/preview/*/feed/", [self getURLPrefix]] stringByAppendingString:escapedUrl]]];                      
17                         
18         } else {
19  

21:13:23 by fishy - Permanent Link

May the Force be with you. RAmen