Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2012 19:13
Show Gist options
  • Save anonymous/2466257 to your computer and use it in GitHub Desktop.
Save anonymous/2466257 to your computer and use it in GitHub Desktop.
var events = require('events');
var util = require('util');
var http = require('http');
var options = {
hostname : 'api.twitter.com',
port : 80,
method : 'get',
path : '/1/statuses/public_timeline.json?count=3&include_entities=true'
}
// The Thing That Emits Event
Eventer = function(){
events.EventEmitter.call(this);
this.kapow = function(){
var data = "BATMAN"
this.emit('blamo', data);
}
this.bam = function(){
this.emit("boom");
}
this.GetTweetList = function(){
var tweets = "";
var req = http.request(options, function(response){
var body = "";
response.on('data',function(data){
body += data;
});
response.on('end', function(){
tweets = JSON.parse(body);
this.emit("tweets", tweets);
util.puts('!!!!!!!!!! got some data !!!!!!!!!! \n');
});
});
req.end();
}
};
util.inherits(Eventer, events.EventEmitter);
// The thing that listens to, and handles, those events
Listener = function(){
this.blamoHandler = function(data){
console.log("** blamo event handled");
console.log(data);
},
this.boomHandler = function(data){
console.log("** boom event handled");
}
this.GetTweetListHandler = function(data){
console.log("** tweets event handled");
util.put(data);
util.puts('!!!!!!!!!! got some data in listener !!!!!!!!!! \n');
}
};
// The thing that drives the two.
var eventer = new Eventer();
var listener = new Listener(eventer);
eventer.on('blamo', listener.blamoHandler);
eventer.on('boom', listener.boomHandler);
eventer.on('tweets', listener.GetTweetListHandler);
//eventer.kapow();
//eventer.bam();
//setInterval(eventer.GetTweetList, 2000);
eventer.GetTweetList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment