1var Parser = require('../jsonparse'); 2var Http = require('http'); 3require('./colors'); 4var p = new Parser(); 5var cred = require('./credentials'); 6var client = Http.createClient(80, "stream.twitter.com"); 7var request = client.request("GET", "/1/statuses/sample.json", { 8 "Host": "stream.twitter.com", 9 "Authorization": (new Buffer(cred.username + ":" + cred.password)).toString("base64") 10}); 11request.on('response', function (response) { 12 console.log(response.statusCode); 13 console.dir(response.headers); 14 response.on('data', function (chunk) { 15 p.write(chunk); 16 }); 17 response.on('end', function () { 18 console.log("END"); 19 }); 20}); 21request.end(); 22var text = "", name = ""; 23p.onValue = function (value) { 24 if (this.stack.length === 1 && this.key === 'text') { text = value; } 25 if (this.stack.length === 2 && this.key === 'name' && this.stack[1].key === 'user') { name = value; } 26 if (this.stack.length === 0) { 27 console.log(text.blue + " - " + name.yellow); 28 text = name = ""; 29 } 30}; 31