By Peter Cooper / September 25, 2009
A couple of weeks ago, popular micro-blogging service Twitter unveiled a beta “streaming API.” Twitter’s nature means they get hammered with polling requests so they’ve begun to experiment with the concept of streaming relevant data within a single HTTP request (in a Comet style). TweetStream (or GitHub repo) is a new Ruby library by Michael Bleigh to handle interacting with Twitter streams from Ruby.
TweetStream is available as a gem from both GitHub and Gemcutter (which, incidentally, got a fresh design today) and installation instructions are given in Michael’s blog post about TweetStream. Once you’re all installed, though, reading the live stream becomes as simple as:
require ‘tweetstream’
TweetStream::Client.new(TWITTER_USERNAME, TWITTER_PASSWORD).sample do |status|
puts “[#{status.user.screen_name}] #{status.text}”
end
Beyond basic functions, though, TweetStream also include daemonization features that allow you to create scripts that run in the background “out of the box.” You could add these features yourself with the daemons library, sure, but having this at hand to quickly throw together Twitter scripts is pretty cool. Read More