-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
85 lines (73 loc) · 2.19 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const axios = require('axios');
class MortalSoftClient {
constructor(baseUrl, token) {
this.baseUrl = baseUrl;
this.token = token;
}
async listGames(queryParams = {}) {
const url = `${this.baseUrl}/api/${this.token}/listGames`;
const queryString = Object.keys(queryParams).map((key) => `${key}=${queryParams[key]}`).join('&');
const fullUrl = queryString ? `${url}?${queryString}` : url;
try {
const response = await axios.get(fullUrl);
return response.data;
} catch (error) {
console.error('Error fetching games:', error.message);
return null;
}
}
async getBalance(identifier) {
const url = `${this.baseUrl}/api/${this.token}/getBalance`;
const data = {
identifier: identifier
};
try {
const response = await axios.post(url, data);
return response.data;
} catch (error) {
console.error('Error fetching user balance:', error.message);
return null;
}
}
async changeBalance(identifier, amount) {
const url = `${this.baseUrl}/api/${this.token}/changeBalance`;
const data = {
identifier: identifier,
amount: amount
};
try {
const response = await axios.post(url, data);
return response.data;
} catch (error) {
console.error('Error changing user balance:', error.message);
return null;
}
}
async createSession(identifier) {
const url = `${this.baseUrl}/api/${this.token}/createSession`;
const data = {
identifier: identifier
};
try {
const response = await axios.post(url, data);
return response.data;
} catch (error) {
console.error('Error creating user session:', error.message);
return null;
}
}
async closeSession(identifier) {
const url = `${this.baseUrl}/api/${this.token}/closeSession`;
const data = {
identifier: identifier
};
try {
const response = await axios.post(url, data);
return response.data;
} catch (error) {
console.error('Error closing user sessions:', error.message);
return null;
}
}
}
module.exports = MortalSoftClient;