-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha-parser.js
40 lines (34 loc) · 1.04 KB
/
a-parser.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
const axios = require('axios');
/**
* A-Parser Client Library
* @constructor
* @param {string} link - full link address, ex: http://127.0.0.1:9091/API
* @param {string} password - login password, if no password leave blank
*/
class AParser {
constructor(link, password = '') {
this.link = link;
this.password = password;
return new Proxy(this, {
get: (obj, prop) => {
if(typeof prop == 'string') {
if(!(prop in obj))
obj[prop] = (data = null) => obj.makeRequest(prop, data);
return obj[prop];
};
}
});
}
makeRequest(action, data = null) {
return new Promise((resolve, reject) => {
axios.post(this.link, {
password: this.password,
action,
data,
})
.then(response => resolve(response.data))
.catch(err => reject(err));
});
}
}
module.exports = AParser;