-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateAPI.js
53 lines (51 loc) · 1.17 KB
/
updateAPI.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
var request = require('request');
var fs = require('fs');
/**
* Gets api.js from a remote PABX.
* @param host The hostname of the PABX, including the protocol. (e.g. https://pabx/)
* @param [callback]
*/
function getAPI(host, callback) {
request.get(host + '/api/api.js', function (err, res, body) {
if (err) {
//console.error('Failed to get api.js!');
//console.error('Request error:', err);
if(typeof callback == 'function') {
callback(err);
}
return;
}
try {
fs.writeFileSync(__dirname + '/api.js', body);
//console.log('Successfully written api.js');
if(typeof callback == 'function') {
callback(null);
}
}
catch (e) {
//console.error('Failed to write api.js!');
//console.error('FS error:', e);
if(typeof callback == 'function') {
callback(e);
}
}
});
}
if(module.parent) {
module.exports = getAPI;
}
else {
var host = process.argv[2];
if(!host) {
console.log('Usage: updateAPI.js HOST');
process.exit(1);
}
console.log('Getting api.js from ' + host);
getAPI(host, function(err){
if(err) {
console.error('Error occurred loading api.js!');
return;
}
console.log('Successfully written api.js');
});
}