-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.source.js
40 lines (39 loc) · 1.15 KB
/
client.source.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
import axios from 'axios'
export default class LUMASERV{API_NAME}Client {
constructor(baseURL = 'https://api.lumaserv.com') {
this.axios = axios.create({
baseURL,
headers: {
'Content-Type': 'application/json'
},
responseType: 'json',
responseEncoding: 'utf8'
})
this.headers = {};
this.setToken(undefined);
}
setToken(token) {
this.token = token || null;
if(this.token) {
this.headers['Authorization'] = 'Bearer '+this.token;
} else {
delete this.headers['Authorization'];
}
}
request(method,path,queryParams,body) {
return new Promise((resolve, reject) => {
this.axios.request({
method,
params: queryParams,
url: path,
data: body,
headers: this.headers
}).then(response => {
resolve(response.data);
}, error => {
reject({ ...error.response.data, status: error.response.status });
})
});
}
{GENERATED_METHODS}
}