Twitter realtime API client
Ruby
Latest commit 45ce963 Jan 7, 2015 @rud rud Merge pull request #41 from kimoto/fix-duplicate-key-specified
Fix duplicate key(:path) specified in DEFAULT_OPTIONS
Failed to load latest commit information.
examples retires parameter and on_max_reconnects example Oct 11, 2009
fixtures/twitter fixed merge conflicts from 5388015 Jun 6, 2011
lib/twitter Fix duplicate key(:path) specified Jan 7, 2015
spec added no_data callback when no data received for 90 seconds May 10, 2012
.gemtest opt-in to rubygems-test Apr 6, 2011
.gitignore bump version Apr 11, 2011
.rspec moved rspec options to .rspec Apr 6, 2011
Gemfile added Gemfile Apr 6, 2011
LICENSE
README.markdown Adding a bit of documentation for the .on_no_data callback May 11, 2012
Rakefile add bundler tasks to Rakefile Apr 6, 2011
VERSION version bump to 0.1.14 Jun 22, 2011
twitter-stream.gemspec Update simple_oauth dependency May 27, 2013

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

  stream.on_no_data do
    # Twitter has stopped sending any data on the currently active
    # connection, reconnecting is probably in order
  end
}

Examples

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