Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1003 bytes
|
Line | |
---|
1 | var Parser = require('../jsonparse');
|
---|
2 | var Http = require('http');
|
---|
3 | require('./colors');
|
---|
4 | var p = new Parser();
|
---|
5 | var cred = require('./credentials');
|
---|
6 | var client = Http.createClient(80, "stream.twitter.com");
|
---|
7 | var request = client.request("GET", "/1/statuses/sample.json", {
|
---|
8 | "Host": "stream.twitter.com",
|
---|
9 | "Authorization": (new Buffer(cred.username + ":" + cred.password)).toString("base64")
|
---|
10 | });
|
---|
11 | request.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 | });
|
---|
21 | request.end();
|
---|
22 | var text = "", name = "";
|
---|
23 | p.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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.