hivpn-representatives
Advanced tools
Comparing version 0.0.5 to 0.0.6
import ApiHiVPN from "./src/api"; | ||
export default ApiHiVPN; | ||
export default ApiHiVPN; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var api_1 = __importDefault(require("./src/api")); | ||
exports.default = api_1.default; | ||
module.exports = api_1.default; | ||
module.exports = require("./lib/index"); |
export default class ApiHiVPN { | ||
token: string; | ||
private token; | ||
constructor(token: string); | ||
getBalance(): Promise<object | any>; | ||
getBalance(showStatus?: boolean): Promise<object | any>; | ||
getProducts(ctArray?: boolean): Promise<object | any>; | ||
@@ -9,5 +9,5 @@ getProduct(ids: string[] | number[], ctArray?: boolean): Promise<object | any>; | ||
getAccount(username: string): Promise<object | any>; | ||
getAccounts(usernames: string[]): Promise<object | any>; | ||
getAccounts(usernames: string[], showErrors?: boolean, ctArray?: boolean): Promise<object | any>; | ||
buyAccount(idProduct: number | 1 | 2 | 3 | 4 | 6, discount?: string, email?: string, mobile?: string, comment?: string, username?: string, password?: string): Promise<object | any>; | ||
accountRenewal(idProduct: number | 1 | 2 | 3 | 4 | 6, discount?: string, username?: string): Promise<object | any>; | ||
accountRenewal(idProduct: number | 1 | 2 | 3 | 4 | 6, username: string, discount?: string): Promise<object | any>; | ||
deleteAccount(username: string): Promise<object | any>; | ||
@@ -14,0 +14,0 @@ editAccount(username: string, password?: string, status?: boolean): Promise<object | any>; |
@@ -49,6 +49,12 @@ "use strict"; | ||
} | ||
ApiHiVPN.prototype.getBalance = function () { | ||
ApiHiVPN.prototype.getBalance = function (showStatus) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.balance))]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.balance))]; | ||
case 1: | ||
result = _a.sent(); | ||
return [2 /*return*/, showStatus ? result : result.data]; | ||
} | ||
}); | ||
@@ -59,6 +65,10 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var data; | ||
var products; | ||
return __generator(this, function (_a) { | ||
data = requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.product)); | ||
return [2 /*return*/, ctArray ? utils_1.default.convertJsonToArray(data) : data]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.product))]; | ||
case 1: | ||
products = _a.sent(); | ||
return [2 /*return*/, ctArray ? utils_1.default.convertJsonToArray(products.data) : products.data]; | ||
} | ||
}); | ||
@@ -99,7 +109,10 @@ }); | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.get_account, "&username=").concat(username))]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.get_account, "&username=").concat(username))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ApiHiVPN.prototype.getAccounts = function (usernames) { | ||
ApiHiVPN.prototype.getAccounts = function (usernames, showErrors, ctArray) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -109,16 +122,26 @@ var result; | ||
return __generator(this, function (_a) { | ||
result = []; | ||
usernames.map(function (username) { return __awaiter(_this, void 0, void 0, function () { | ||
var account; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.get_account, "&username=").concat(username))]; | ||
case 1: | ||
account = _a.sent(); | ||
result.push(account); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
return [2 /*return*/, result]; | ||
switch (_a.label) { | ||
case 0: | ||
result = []; | ||
return [4 /*yield*/, Promise.all(usernames.map(function (username) { return __awaiter(_this, void 0, void 0, function () { | ||
var account; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.get_account, "&username=").concat(username))]; | ||
case 1: | ||
account = _a.sent(); | ||
if (account.status == true) | ||
return [2 /*return*/, result.push(ctArray ? utils_1.default.convertJsonToArray(account) : account.data)]; | ||
else if (showErrors) | ||
return [2 /*return*/, result.push("".concat(username, " not found"))]; | ||
else | ||
return [2 /*return*/]; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }))]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, result]; | ||
} | ||
}); | ||
@@ -134,6 +157,6 @@ }); | ||
}; | ||
ApiHiVPN.prototype.accountRenewal = function (idProduct, discount, username) { | ||
ApiHiVPN.prototype.accountRenewal = function (idProduct, username, discount) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.renew, "&prodid=").concat(idProduct, "&").concat(discount ? "copn=".concat(discount, "&") : "").concat(username ? "username=".concat(username, "&") : ""))]; | ||
return [2 /*return*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.renew, "&prodid=").concat(idProduct, "&username=").concat(username, "&").concat(discount ? "copn=".concat(discount) : ""))]; | ||
}); | ||
@@ -155,3 +178,3 @@ }); | ||
case 0: | ||
if (!(username && password && status)) return [3 /*break*/, 1]; | ||
if (!(password && status)) return [3 /*break*/, 1]; | ||
return [2 /*return*/, requests_1.default.get("".concat(config_json_1.default.full_url).concat(this.token, "&action=").concat(config_json_1.default.actions.edit_account, "&username=").concat(username, "&password=").concat(password, "&status=").concat(status))]; | ||
@@ -158,0 +181,0 @@ case 1: return [4 /*yield*/, this.checkAccount(username)]; |
{ | ||
"name": "hivpn-representatives", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Hi vpn representatives package", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -9,5 +9,2 @@ #  HiVPN Representatives Package NPM | ||
*این بسته هنوز کامل نشده است.* | ||
---------- | ||
به جای استفاده مستقیم از api های سایت نمایندگان می توانید از این پکیچ با قابلیت های بیشتر استفاده کنید. | ||
@@ -58,2 +55,32 @@ | ||
```js | ||
/** | ||
showStatus?: boolean|undefined, | ||
if showStatus is true then return {{ | ||
status: "success", | ||
balance: { | ||
... | ||
} | ||
}} | ||
else return { | ||
balance: { | ||
... | ||
} | ||
} | ||
*/ | ||
/** | ||
ctArray?: boolean|undefined, | ||
if ctArray is true then return { | ||
"3": { | ||
"id": "3", | ||
... | ||
}} | ||
else return [ | ||
{ | ||
"id": "3", | ||
... | ||
} | ||
] | ||
*/ | ||
//yor api key token example: qf2wec9ec5da418abee7ae22 | ||
@@ -63,18 +90,18 @@ | ||
// get balance | ||
const getBalance = await hivpn.getBalance(); | ||
// get balance: | ||
const getBalance = await hivpn.getBalance(); //showStatus?: boolean | ||
//get products | ||
const getProducts = await hivpn.getProducts(); | ||
//get products: | ||
const getProducts = await hivpn.getProducts(); //ctArray?: boolean | ||
//get product by id | ||
const getProductById = await hivpn.getProductById([1, 3, 6]); //or ["1","3","6"] | ||
//get product by id: | ||
const getProductById = await hivpn.getProduct([1, 3, 6] /*or ["1","3","6"]*/); //ctArray?: boolean | ||
//get product by price | ||
const getProductByPrice = await hivpn.getProductByPrice(0, 100); | ||
//get product by price: | ||
const getProductByPrice = await hivpn.getProductByPrice(0, 100); //ctArray?: boolean | ||
// get a account | ||
// get a account: | ||
const getAccount = await hivpn.getAccount("username"); | ||
// get a list of accounts | ||
// get a list of accounts: | ||
const getAccounts = await hivpn.getAccounts([ | ||
@@ -84,5 +111,6 @@ "username1", | ||
"username3", | ||
]); | ||
]); // showErrors?: boolean, | ||
// ctArray?: boolean | ||
// buy a account | ||
// buy a account: | ||
@@ -108,3 +136,3 @@ /** params: | ||
// account renewal | ||
// account renewal: | ||
@@ -119,3 +147,3 @@ /** params: | ||
//edit account | ||
//edit account: | ||
@@ -131,8 +159,12 @@ /** params: | ||
const deleteAccount = await hivpn.deleteAccount("username"); | ||
``` | ||
create package by @mohammadhejazirad | ||
دوستان عزیز شما میتوانید نظرات خود را در مورد بسته نمایندگان HiVPN برای ما بفرستید. | ||
email: hejazi00831@gmail.com | ||
نکته: این بسته زیر نظر شرکت HiVPN ساخته و انتشار داده نشده است و صرفا فقط برای راحتی کار دوستان برنامه نویس بنده منتشر کرده ام. | ||
امیدوارم که این بسته مفید واقع باشد.🌹 | ||
@@ -6,3 +6,3 @@ import RequestTools from "./requests"; | ||
export default class ApiHiVPN { | ||
token: string; | ||
private token: string; | ||
constructor(token: string) { | ||
@@ -12,13 +12,14 @@ this.token = token; | ||
async getBalance(): Promise<object | any> { | ||
return RequestTools.get( | ||
async getBalance(showStatus?: boolean): Promise<object | any> { | ||
const result = await RequestTools.get( | ||
`${config.full_url}${this.token}&action=${config.actions.balance}` | ||
); | ||
return showStatus ? result : result.data; | ||
} | ||
async getProducts(ctArray?: boolean): Promise<object | any> { | ||
const data = RequestTools.get( | ||
const products = await RequestTools.get( | ||
`${config.full_url}${this.token}&action=${config.actions.product}` | ||
); | ||
return ctArray ? Utils.convertJsonToArray(data) : data; | ||
return ctArray ? Utils.convertJsonToArray(products.data) : products.data; | ||
} | ||
@@ -53,3 +54,3 @@ | ||
async getAccount(username: string): Promise<object | any> { | ||
return RequestTools.get( | ||
return await RequestTools.get( | ||
`${config.full_url}${this.token}&action=${config.actions.get_account}&username=${username}` | ||
@@ -59,10 +60,21 @@ ); | ||
async getAccounts(usernames: string[]): Promise<object | any> { | ||
async getAccounts( | ||
usernames: string[], | ||
showErrors?: boolean, | ||
ctArray?: boolean | ||
): Promise<object | any> { | ||
const result: any = []; | ||
usernames.map(async (username) => { | ||
const account = await RequestTools.get( | ||
`${config.full_url}${this.token}&action=${config.actions.get_account}&username=${username}` | ||
); | ||
result.push(account); | ||
}); | ||
await Promise.all( | ||
usernames.map(async (username: string) => { | ||
const account = await RequestTools.get( | ||
`${config.full_url}${this.token}&action=${config.actions.get_account}&username=${username}` | ||
); | ||
if (account.status == true) | ||
return result.push( | ||
ctArray ? Utils.convertJsonToArray(account) : account.data | ||
); | ||
else if (showErrors) return result.push(`${username} not found`); | ||
else return; | ||
}) | ||
); | ||
return result; | ||
@@ -95,4 +107,4 @@ } | ||
idProduct: number | 1 | 2 | 3 | 4 | 6, | ||
discount?: string, | ||
username?: string | ||
username: string, | ||
discount?: string | ||
): Promise<object | any> { | ||
@@ -102,4 +114,4 @@ return RequestTools.get( | ||
config.actions.renew | ||
}&prodid=${idProduct}&${discount ? `copn=${discount}&` : ""}${ | ||
username ? `username=${username}&` : "" | ||
}&prodid=${idProduct}&username=${username}&${ | ||
discount ? `copn=${discount}` : "" | ||
}` | ||
@@ -120,3 +132,3 @@ ); | ||
): Promise<object | any> { | ||
if (username && password && status) { | ||
if (password && status) { | ||
return RequestTools.get( | ||
@@ -123,0 +135,0 @@ `${config.full_url}${this.token}&action=${config.actions.edit_account}&username=${username}&password=${password}&status=${status}` |
30993
571
164