Skip to content

Instantly share code, notes, and snippets.

@stevegraham
Created July 17, 2010 00:04
Show Gist options
  • Save stevegraham/479087 to your computer and use it in GitHub Desktop.
Save stevegraham/479087 to your computer and use it in GitHub Desktop.
%w(rubygems eventmachine em-http-request yajl).each { |lib| require lib }
module Twitter
def on_tweet() lambda { |obj| puts obj['text'] }; end
extend self
end
EM::run do
req = EM::HttpRequest.new('http://stream.twitter.com/1/statuses/sample.json').get :head => { 'authorization' => ['eventmachine', 'eventm4chine'] }
parser = Yajl::Parser.new.tap { |p| p.on_parse_complete = Twitter.on_tweet }
req.stream { |chunk| parser << chunk }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment