-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (44 loc) · 1.11 KB
/
index.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
const axios = require('axios').default;
class HistoryApi {
constructor(apiToken) {
this.apiToken = apiToken;
this.baseUrl = "https://api.namedc.org";
}
checkToken() {
if (!this.apiToken) {
throw new Error('API token is missing');
}
}
search(userId) {
this.checkToken();
return axios({
method: 'GET',
headers: {
"Authorization": `Bearer ${this.apiToken}`
},
url: `${this.baseUrl}/search`,
params: {
query: userId
}
}).then(res => res.data)
.catch(err => {
console.error(err);
throw err;
});
}
getAccountInfo() {
this.checkToken();
return axios({
method: 'GET',
headers: {
"Authorization": `Bearer ${this.apiToken}`
},
url: `${this.baseUrl}/account`
}).then(res => res.data)
.catch(err => {
console.error(err);
throw err;
});
}
}
module.exports = HistoryApi;