Created
March 20, 2010 00:08
-
-
Save kenn/338336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TWEETS = RingBuffer.new(10) | |
STREAMING_URL = 'http://stream.twitter.com/1/statuses/sample.json' | |
def handle_tweet(tweet) | |
return unless tweet['text'] | |
TWEETS.push(tweet) | |
end | |
EM.schedule do | |
http = EM::HttpRequest.new(STREAMING_URL).get :head => { 'Authorization' => [ 'USERNAME', 'PASSWORD' ] } | |
buffer = "" | |
http.stream do |chunk| | |
buffer += chunk | |
while line = buffer.slice!(/.+\r?\n/) | |
handle_tweet JSON.parse(line) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment