Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created March 1, 2009 10:54
Show Gist options
  • Select an option

  • Save ELLIOTTCABLE/72298 to your computer and use it in GitHub Desktop.

Select an option

Save ELLIOTTCABLE/72298 to your computer and use it in GitHub Desktop.
%w(json em-http).each {|dep| require dep }
require 'talkieme/config'
module TalkieMe
Version = 2
class <<self
def start(config)
EventMachine.run do
update_followers!
EventMachine::add_periodic_timer(900) { update_followers! }
request = EventMachine::HttpRequest.new 'http://search.twitter.com/search.json'
EventMachine::add_periodic_timer(5) do
request = request.get :query => {:q => config[:triggers].join(" OR ")}
request.callback do
response = JSON.parse(request.response)
p response # DEBUG
end
end
end
end
private
def update_followers!
request = EventMachine::HttpRequest.new('http://twitter.com/statuses/followers.json').get
request.callback do
response = JSON.parse(request.response)
p response # DEBUG
end
@followers = JSON.parse(
open(
"http://twitter.com/statuses/followers.json",
:http_basic_authentication => [Config[:username], Config[:password]]
).read
).map {|f| f['screen_name'] }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment