-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
70 lines (60 loc) · 1.46 KB
/
test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var Gnip = require('gnip'),
async = require('async');
var stream = new Gnip.Stream({
url : 'https://stream.gnip.com:443/accounts/xxx/publishers/twitter/streams/track/dev.json',
user : 'xxx',
password : 'xxx'
});
stream.on('ready', function() {
console.log('Stream ready!');
});
stream.on('tweet', function(tweet) {
console.log('New tweet: ' + tweet.body);
});
stream.on('error', function(err) {
console.error(err);
});
var rules = new Gnip.Rules({
url : 'https://api.gnip.com:443/accounts/xxx/publishers/twitter/streams/track/dev/rules.json',
user : 'xxx',
password : 'xxx'
});
rules.live.removeAll(function(err) {
if (err) throw err;
rules.clearCache();
rules.update(['nodeJS'], function(err) {
if (err) throw err;
stream.start();
async.series([
async.apply(test, ['ford', 'peugeot']),
async.apply(test, ['peugeot']),
async.apply(test, ['volkswagen', 'audi', {value:'ferrari'}])
], function(err) {
if (err) throw err;
});
});
});
function test(r, cb) {
console.log('Testing rule update...');
rules.update(r, function(err) {
if (err) throw err;
async.series([
function(cb) {
rules.getAll(function(err, rules) {
if (err) throw err;
console.log('Local rules:')
console.log(rules)
cb();
});
},
function(cb) {
rules.live.getAll(function(err, rules) {
if (err) throw err;
console.log('Live rules:')
console.log(rules)
cb();
})
}
], cb);
});
}