Skip to content

Instantly share code, notes, and snippets.

@andrewsardone
Created October 14, 2009 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsardone/209720 to your computer and use it in GitHub Desktop.
Save andrewsardone/209720 to your computer and use it in GitHub Desktop.
#!/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