Created
October 14, 2009 01:44
-
-
Save andrewsardone/209720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env macruby | |
# example using Twitter API | |
framework 'Cocoa' | |
framework 'JSON' | |
url = NSURL.URLWithString "http://twitter.com/statuses/public_timeline.json" | |
request = NSURLRequest.requestWithURL(url) | |
response = NSURLConnection.sendSynchronousRequest(request, returningResponse:nil, error:nil) | |
json_string = NSString.alloc.initWithData(response, encoding:NSUTF8StringEncoding) | |
# SBJSON parser object from JSON.framework | |
parser = SBJSON.alloc.init | |
# parse the JSON response into an NSArray of NSDictionary status objects | |
twitter_statuses = parser.objectWithString(json_string, error:nil) | |
twitter_statuses.each { |s| puts s['text'] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment