vkpoint-api
Advanced tools
Comparing version 0.0.2 to 1.0.0
@@ -17,4 +17,113 @@ # Начало работы с VK Point | ||
## Использование Callback API | ||
```js | ||
async function run () { | ||
await vkpoint.updates.start(/* options = {}, */ (data) => { | ||
console.log(data) | ||
}).catch(console.error) | ||
vkpoint.updates.onTransfer((event) => { | ||
console.log(event) | ||
}).catch(console.error) | ||
} | ||
run().catch(console.error) | ||
``` | ||
## Методы API | ||
`Документация появится скоро.` | ||
### Метод 'call' | ||
`call` - вызов любого метода с любыми параметрами, может пригодиться для нововведений в API. | ||
```js | ||
async function run () { | ||
const result = await vkpoint.api.call('method.get', { method: 0, data: 'test' }) | ||
console.log(result) | ||
} | ||
run().catch(console.error) | ||
``` | ||
|Опция |Тип |Необходимость |Описание | | ||
|- |- | |- | | ||
|method|String|true |Название метода, как оно указано в [документации к API](https://vk.com/@vposter-metody-api-vk-point).| | ||
|params|Object|false |Параметры, необходимые для метода. (по умолчанию {}) | | ||
### Метод 'sendPayment' | ||
`sendPayment` - отправка VK Point пользователю. | ||
```js | ||
async function run () { | ||
const result = await vkpoint.api.sendPayment(1, 1) // Отправляем 1 VK Point пользователю с @id1 (Павел Дуров). | ||
console.log(result) | ||
} | ||
run().catch(console.error) | ||
``` | ||
|Опция |Тип |Необходимость |Описание | | ||
|- |- | |- | | ||
|toId |Number|true |ID пользователя, которму необходимо отправить VK Coins.| | ||
|amount|Number|true |Количество VK Point, необходимое для отправки. | | ||
### Метод 'getUserData' | ||
`getUserData` - получение данных о пользователе. | ||
```js | ||
async function run () { | ||
const result = await vkpoint.api.getUserData(1) // Получаем даныне из базы данных VK Point о пользователе с @id1 (Павел Дуров) | ||
console.log(result) | ||
} | ||
run().catch(console.error) | ||
``` | ||
|Опция |Тип |Необходимость |Описание | | ||
|- |- | |- | | ||
|targetId|Number|true |ID пользователя, о котором нужно получить данные.| | ||
### Метод 'getUsersTop' | ||
`getUsersTop` - получение данных о таблице рейтингов пользователей VK Point. | ||
```js | ||
async function run () { | ||
const result = await vkpoint.api.getUsersTop(5, true) // Получаем ТОП-5 ВИП пользователей | ||
console.log(result) | ||
} | ||
run().catch(console.error) | ||
``` | ||
|Опция |Тип |Необходимость |Описание | | ||
|- |- | |- | | ||
|count |Number |false |Количество пользователей (по умолчанию 50) | | ||
|vip |Boolean|false |Возвращает топ VIP пользователей, если true (по умолчанию false)| | ||
### Метод 'generateLink' | ||
`generateLink` - генерация ссылки на перевод. | ||
```js | ||
function run () { | ||
const result = vkpoint.api.generateLink(100, false) // Генерируем ссылку для перевода 100 VK Points без фиксации. | ||
console.log(result) | ||
} | ||
run() | ||
``` | ||
|Опция |Тип |Необходимость |Описание | | ||
|- |- | |- | | ||
|amount |Number |false |Количество VK Point для перевода. (по умолчанию не указано)| | ||
|fixation|Boolean|false |Является ли фиксированной ссылка. (по умолчанию false) | |
85
index.js
@@ -88,5 +88,6 @@ const Koa = require('koa') | ||
* @param {Object} params - VK Point API parameters | ||
* @default param {} | ||
*/ | ||
async call (method, params) { | ||
async call (method, params = {}) { | ||
if (!method) { | ||
@@ -100,12 +101,11 @@ throw new Error('method is undefined!') | ||
params = Object.assign({ access_token: this.token, user_id: this.userId }, params) | ||
params = Object.assign({ access_token: this.token }, params) | ||
await request(`https://vkpoint.vposter.ru/api/method/${method}`, params) | ||
.then(result => { | ||
if (result.error) { | ||
throw new Error(result.error) | ||
} | ||
const result = await request(`https://vkpoint.vposter.ru/api/method/${method}.php?${Object.entries(params).map(e => e.join('=')).join('&')}`) | ||
return result | ||
}) | ||
if (result && result.error) { | ||
throw new Error(result.error) | ||
} | ||
return result | ||
} | ||
@@ -128,21 +128,68 @@ | ||
const params = { | ||
user_id_to: toId, | ||
user_id_to: this.userId, | ||
user_id: toId, | ||
point: amount, | ||
} | ||
await this.call('account.MerchantSend', params) | ||
.then((result) => { | ||
if (result.error) { | ||
throw new Error(result.error) | ||
} | ||
const result = await this.call('account.MerchantSend', params) | ||
return result | ||
}) | ||
if (result && result.error) { | ||
throw new Error(result.error) | ||
} | ||
return result | ||
} | ||
/** | ||
* @param {Number} amount | ||
* @param {Boolean} fixation | ||
* @async | ||
* @param {Number} targetId - target id | ||
*/ | ||
async getUserData (targetId) { | ||
if (typeof targetId !== 'number') { | ||
throw new Error('toId must be a number!') | ||
} | ||
const params = { | ||
user_id: targetId, | ||
} | ||
const result = await this.call('account.getPoint', params) | ||
if (result && result.error) { | ||
throw new Error(result.error) | ||
} | ||
return result | ||
} | ||
/** | ||
* @async | ||
* @param {Number} count - amount of users | ||
* @param {Boolean} vip - is top vip? | ||
* @default count 50 | ||
* @default vip false | ||
*/ | ||
async getUsersTop (count = 50, vip = false) { | ||
if (typeof targetId !== 'number') { | ||
throw new Error('toId must be a number!') | ||
} | ||
const params = { | ||
count: count, | ||
} | ||
let result = vip ? await this.call('users.getTopVip', params) : await this.call('users.getTop', params) | ||
if (result && result.error) { | ||
throw new Error(result.error) | ||
} | ||
return result | ||
} | ||
/** | ||
* @param {Number} amount - VK Points | ||
* @param {Boolean} fixation - is amount fixed | ||
*/ | ||
generateLink (amount = 0, fixation = false) { | ||
@@ -149,0 +196,0 @@ if (typeof amount !== 'number') { |
{ | ||
"name": "vkpoint-api", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "VK Point API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14951
234
1