File: README.markdown

package info (click to toggle)
ruby-twitter-stream 0.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 152 kB
  • ctags: 45
  • sloc: ruby: 637; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# twitter-stream

Simple Ruby client library for [twitter streaming API](http://apiwiki.twitter.com/Streaming-API-Documentation).
Uses [EventMachine](http://rubyeventmachine.com/) for connection handling. Adheres to twitter's [reconnection guidline](https://dev.twitter.com/docs/streaming-api/concepts#connecting).

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