-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.js
46 lines (37 loc) · 882 Bytes
/
search.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
39
40
41
42
43
44
45
46
var http = require('http'),
querystring = require('querystring');
module.exports.parseAnswer = function (answer)
{
var answerObj = JSON.parse(answer);
var ret = "";
for(i in answerObj.results)
{
ret = ret + answerObj.results[i].from_user + '\n';
ret = ret + answerObj.results[i].text + '\n';
}
return ret;
};
module.exports.request = function (reqString, callback) {
var options = {
hostname : 'search.twitter.com',
port : 80,
path : '/search.json?q=' + encodeURIComponent(reqString),
headers : {
'Content-Type' : 'node.js-twitter-search'
},
method : 'GET'
};
var answer = "";
var req = http.request(options, function(res) {
res.on('data', function(dat) {
answer = answer + dat;
});
res.on('end', function(){ // emmit-data
callback(answer);
});
});
req.on('error', function(e) {
require('util').puts(e);
});
req.end();
}