Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdateAPI.js
More file actions
Latest commit
53 lines (51 loc) · 1.17 KB
/
Copy pathupdateAPI.js
File metadata and controls
53 lines (51 loc) · 1.17 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
varrequest=require('request');
varfs=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]
*/
functiongetAPI(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(typeofcallback=='function'){
callback(err);
}
return;
}
try{
fs.writeFileSync(__dirname+'/api.js',body);
//console.log('Successfully written api.js');
if(typeofcallback=='function'){
callback(null);
}
}
catch(e){
//console.error('Failed to write api.js!');
//console.error('FS error:', e);
if(typeofcallback=='function'){
callback(e);
}
}
});
}
if(module.parent){
module.exports=getAPI;
}
else{
varhost=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');
});
}