Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Created November 28, 2010 16:02
Show Gist options
  • Select an option

  • Save tomas-stefano/719046 to your computer and use it in GitHub Desktop.

Select an option

Save tomas-stefano/719046 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'eventmachine'
require 'em-http'
require 'json'
EM.run do
username = "username"
password = "secret"
term = "ruby"
buffer = ""
http = EM::HttpRequest.new("http://stream.twitter.com/1/statuses/filter.json").post({
:head => { "Authorization" => [username, password]},
:query => { "track" => term }
})
http.callback do
unless http.response_header.status == 200
puts "Call failed with response code #{http.response_header.status}"
end
end
http.stream do |chunk|
buffer += chunk
while line = buffer.slice!(/.+\r\n/)
tweet = JSON.parse(line)
puts
puts tweet['text']
puts
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment