-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
206 lines (166 loc) · 4.98 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
var apiKey;
//Function START
function client(key) {
apiKey = key;
}
async function requestURL(url) {
const axios = require("axios");
var result = "{}";
await axios
.get(
url
)
.then((response) => {
result = response.data;
})
.catch((err) => {
console.log(err);
});
return result;
}
function generateURL(endpoint, params) {
return endpoint.toString() + "?" + new URLSearchParams(params).toString();
}
function checkApiKey() {
if (apiKey == null) {
console.error("PLEASE ENTER YOUR API KEY!");
return false;
}
return true;
}
//Function END
//Main START
async function getCountries() {
return requestURL(generateURL("https://api.smspool.net/country/retrieve_all", {}));
};
async function getServices(country) {
let params = {};
if(country != null){
params.country = country
}
return requestURL(generateURL("https://api.smspool.net/service/retrieve_all", params));
};
async function getBalance() {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/request/balance", { key: apiKey }));
}
return {};
}
async function getOrderHistory() {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/request/history", { key: apiKey }));
}
return {};
}
async function getActiveOrders() {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/request/active", { key: apiKey }));
}
return {};
}
//Main END
//SMS START
async function getSMSServicePrice(country, service) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/request/price", { key: apiKey, country: country, service: service }));
}
return {};
}
async function purchaseSMS(country, service, pool) {
let params = { key: apiKey, country: country, service: service }
if (pool != null) {
params.pool = pool;
}
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/purchase/sms", params));
}
return {};
}
async function checkSMS(orderId) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/sms/check", { key: apiKey, orderid: orderId }));
}
return {};
}
async function resendSMS(orderId) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/sms/resend", { key: apiKey, orderid: orderId }));
}
return {};
}
async function cancelSMS(orderId) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/sms/cancel", { key: apiKey, orderid: orderId }));
}
return {};
}
async function archiveSMSOrders() {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/request/archive", { key: apiKey }));
}
return {};
}
//SMS END
//RENTALS START
async function getRentals(type) {
let typeParam = type ? 1 : 0; // one-time = 0 | extendable = 1 (default)
return requestURL(generateURL("https://api.smspool.net/rental/retrieve_all", { type: typeParam }));
}
async function purchaseRental(rentalID, days, service_id) {
let params = { key: apiKey, id: rentalID, days: days }
if (service_id != null) {
params.service_id = service_id;
}
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/purchase/rental", params));
}
return {};
}
async function getRentalMessage(rental_code) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/rental/retrieve_messages", { key: apiKey, rental_code: rental_code }));
}
return {};
}
async function getRentalStatus(rental_code) {
if (checkApiKey()) {
return requestURL(generateURL("https://smspool.net/api/rental/retrieve_status.php", { key: apiKey, rental_code: rental_code }));
}
return {};
}
async function refundRental(rental_code) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/rental/refund.php", { key: apiKey, rental_code: rental_code }));
}
return {};
}
async function extendRental(rental_code, days) {
if (checkApiKey()) {
return requestURL(generateURL("https://api.smspool.net/rental/extend.php", { key: apiKey, days: days, rental_code: rental_code }));
}
return {};
}
//RENTALS END
module.exports = {
//main
client: client,
getCountries: getCountries,
getServices: getServices,
getBalance: getBalance,
getOrderHistory: getOrderHistory,
getActiveOrders: getActiveOrders,
//sms
getSMSServicePrice: getSMSServicePrice,
purchaseSMS: purchaseSMS,
checkSMS: checkSMS,
resendSMS: resendSMS,
cancelSMS: cancelSMS,
archiveSMSOrders: archiveSMSOrders,
//rentals
getRentals: getRentals,
purchaseRental: purchaseRental,
getRentalMessage: getRentalMessage,
getRentalStatus: getRentalStatus,
refundRental: refundRental,
extendRental: extendRental
}