forked from Qard/node-hipchat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
62 lines (55 loc) · 1.43 KB
/
example.js
File metadata and controls
62 lines (55 loc) · 1.43 KB
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
var fs = require('fs');
var apiKey = 'api-key-goes-here';
try {
apiKey = fs.readFileSync('api_key', 'ascii').replace(/^\s+|\s+$/g, '');
console.log('Read api_key from disc:', apiKey);
}
catch (err) {
console.log('Failed to read api_key. Requests will probably fail.');
}
var chain = new (require('chainer'));
var hipchat = require('./index');
var hip = new hipchat(apiKey);
var rooms = hip.Rooms;
var users = hip.Users;
// Get a list of rooms.
chain.add(function(){
rooms.list(function(err, res){
if (err) throw new Error(err.message);
console.log('Rooms: ', res);
chain.next(res.rooms[0].room_id);
});
});
// Get detailed room info.
chain.add(function(id){
rooms.show(id, function(err, res){
if (err) throw new Error(err.message);
console.log('Room #'+id+': ', res);
chain.next(id);
});
});
// View history of a room.
chain.add(function(id){
rooms.history(id, function(err, res){
if (err) throw new Error(err.message);
console.log('Recent messages: ', res);
chain.next(id);
});
});
// Get a list of users.
chain.add(function(){
users.list(function(err, res){
if (err) throw new Error(err.message);
console.log('Users: ', res);
chain.next(res.users[0].user_id);
});
});
// Get detailed user info.
chain.add(function(id){
users.show(id, function(err, res){
if (err) throw new Error(err.message);
console.log('User #'+id+': ', res);
chain.next(id);
});
});
chain.run();