Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cantino/twitter-stream
Twitter realtime API client
https://github.com/cantino/twitter-stream
Last synced: 3 months ago
JSON representation
Twitter realtime API client
- Host: GitHub
- URL: https://github.com/cantino/twitter-stream
- Owner: cantino
- License: mit
- Fork: true (voloko/twitter-stream)
- Created: 2014-02-18T04:31:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-06-30T22:43:47.000Z (over 5 years ago)
- Last Synced: 2024-07-28T15:21:54.896Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 79.1 KB
- Stars: 3
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
# 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.
endstream.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.
endstream.on_max_reconnects do |timeout, retries|
# Something is wrong on your side. Send yourself an email.
endstream.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