Twitter Streaming API client - supports OAuth
Ruby
Pull request Compare This branch is 7 commits ahead, 22 commits behind voloko:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
fixtures/twitter
lib
spec
.gemtest
.gitignore
.rspec
Gemfile
README.markdown
Rakefile
VERSION
twitter-stream.gemspec

README.markdown

twitter-stream

Ruby gem for Twitter's Streaming API.

Uses EventMachine for connection handling.

Adheres to Twitter's Reconnection Guidelines.

Install

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

Usage

Basic Authencation

require 'rubygems'
require 'twitter/json_stream'
require 'json'

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

  stream.each_item do |item|
    # Do someting with unparsed JSON item.
    puts JSON.parse(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

end

OAuth

stream = Twitter::JSONStream.connect(
  :path => '/1/statuses/sample.json',
  :oauth   => {
    :consumer_key => 'YOUR_CONSUMER_KEY',
    :consumer_secret => 'YOUR_CONSUMER_SECRET',
    :access_key => 'YOUR_ACCESS_TOKEN',
    :access_secret => 'YOUR_ACCESS_TOKEN_SECRET'
  }
)

Examples

ruby examples/reader.rb