-
Notifications
You must be signed in to change notification settings - Fork 1
/
hipchat_client.js
36 lines (32 loc) · 941 Bytes
/
hipchat_client.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
/*
* hipchat-js
*
* Copyright (c) 2011 Simon Murtha-Smith <simon@murtha-smith.com>
*/
var querystring = require('querystring');
var request = require('request');
var baseUrl = 'https://api.hipchat.com/v1';
var Client = function(auth_token) {
this.apiCall = function (method, path, params, callback) {
callback = callback || function () {};
params.format = 'json';
params.auth_token = auth_token;
request({
method: method,
uri: baseUrl + path + '?' + querystring.stringify(params)
}, function (err, resp, body) {
if(err)
callback(err, body);
else {
try {
callback(null, JSON.parse(body));
} catch(e) {
callback(e, body);
}
}
});
};
};
module.exports = function(auth_token) {
return new Client(auth_token);
}