-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (39 loc) · 1.39 KB
/
index.js
File metadata and controls
48 lines (39 loc) · 1.39 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
'use strict';
const axios = require('axios');
const apiVersion = 8;
class Minsh {
constructor(appName, datacenter, verbose = false) {
this.appName = appName;
this.datacenter = datacenter;
this.verbose = verbose;
this.endpoint = 'https://api' + apiVersion;
['eu', 'us', 'seoul'].some(f => {
if (this.datacenter === f) {
this.endpoint += '-' + f;
return true;
}
})
this.endpoint += '.min.sh/' + this.appName + '/';
}
async r(method, query, params) {
this.verbose && console.log(method.toUpperCase(), query, params);
try {
let res;
if (method === 'delete') {
res = await axios({method: 'delete', url: this.endpoint + query, data: params});
} else {
res = await axios[method](this.endpoint + query, params);
}
return [null, res.data];
} catch(err) {
return [err.response.status, err.response.data];
}
}
async adminCreateAccount(params) { return this.r('post', 'admin/user', params); }
async createAccount(params) { return this.r('post', 'users', params); }
async createShout(params) { return this.r('post', 'shouts', params); }
async login(params) { return this.r('put', 'users/login', params); }
async logout(params) { return this.r('put', 'users/logout', params); }
async deleteAccount(id, params) { return this.r('delete', 'users/' + id, params); }
}
module.exports = Minsh;