public
Description: Twitter realtime API client
Homepage:
Clone URL: git://github.com/voloko/twitter-stream.git
lifo (author)
Wed Dec 02 18:23:07 -0800 2009
voloko (committer)
Thu Dec 03 09:21:01 -0800 2009
name age message
file .gitignore Sun Oct 11 05:48:16 -0700 2009 gitignore [voloko]
file README.markdown Sun Oct 11 06:04:10 -0700 2009 readme update, call on_error if @code != 200 [voloko]
file Rakefile Wed Oct 14 01:42:28 -0700 2009 rspec depenedency [voloko]
file VERSION Tue Dec 01 09:14:15 -0800 2009 Version bump to 0.1.4 [voloko]
directory examples/ Sun Oct 11 05:35:24 -0700 2009 retires parameter and on_max_reconnects example [voloko]
directory fixtures/ Fri Oct 09 02:54:44 -0700 2009 Initial commit [voloko]
directory lib/ Wed Dec 02 18:23:07 -0800 2009 Add SSL support [lifo]
directory spec/ Sun Oct 11 05:22:53 -0700 2009 cleanup, :user_agent option, on_max_reconnects ... [voloko]
file twitter-stream.gemspec Wed Oct 14 01:42:28 -0700 2009 rspec depenedency [voloko]
README.markdown

twitter-stream

Simple Ruby client library for twitter streaming API. Uses EventMachine for connection handling. Adheres to twitter's reconnection guidline.

JSON format only.

Install

sudo gem install twitter-stream -s http://gemcutter.org

Usage

require 'rubygems'
require 'twitter/json_stream'

EventMachine::run {
  stream = Twitter::JSONStream.connect(
    :path    => '/1/statuses/filter.json?track=football',
    :auth    => 'LOGIN:PASSWORD'
  )

  stream.each_item do |item|
    # Do someting with unparsed JSON item.
  end

  stream.on_error do |message|
    # No need to worry here. It might be an issue with Twitter. 
    # Log message for future reference. JSONStream will try to reconnect after a timeout.
  end

  stream.on_max_reconnects do |timeout, retries|
    # Something is wrong on your side. Send yourself an email.
  end
}

Examples

Open examples/reader.rb. Replace LOGIN:PASSWORD with your real twitter login and password. And

ruby examples/reader.rb