Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

TweetStream: Use the Twitter Streaming API from Ruby

By Peter Cooper / September 25, 2009

twitter-stream.png 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', TWITTER_PASSWORD).sample do |status|
  puts "[#{status.user.screen_name}] #{status.text}"

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.

Other related stuff: If you're more interested in using Twitter from Ruby generally, check out John Nunemaker's Twitter library. If you want to build a Twitter bot in Ruby, check out Twibot. And, lastly, if you just want to follow some Rubyists on Twitter, check out Satish Talim's list of 50+ Rubyists to Follow on Twitter.

[ad] lapsusss.png Time Tracking without Timers: Lapsus runs in the background and knows what project you're working on. Find out how long that last project took without the hassle of updating a timer. Watch the screencast or sign up for the Beta.

Other Posts to Enjoy

Twitter Mentions