/
twitter.js
38 lines (28 loc) · 908 Bytes
/
twitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var http = require("http");
events = require("events");
function TwitterFeed () {}
TwitterFeed.prototype = new events.EventEmitter();
TwitterFeed.prototype.fetchData = function (tag, count) {
var self = this,
urlPath;
if (!tag) {
throw new Error("Expected argument missing");
}
if (!count) {
count = 5;
}
urlPath = "/search.json?q=" + escape(tag) + "&result_type=mixed&count=" + count;
http.get({"host": "search.twitter.com", "port" : 80,
"path": urlPath}, function(res) {
var buf = "";
res.on("data", function (chunk) {
buf += chunk;
});
res.on("end", function () {
self.emit("twit-data", eval("(" + buf + ")"));
});
}).on("error", function (e) {
self.emit("twit-error", e.message);
});
};
exports.TwitterFeed = TwitterFeed;