-
Notifications
You must be signed in to change notification settings - Fork 0
/
vk_api.js
42 lines (37 loc) · 1.01 KB
/
vk_api.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
const request = require('request');
const VK_API = 'https://api.vk.com/method/';
const API_VERSION = '5.92';
const FIELDS = 'members_count,start_date,finish_date,city'
class Vk {
constructor(access_token) {
this.access_token = access_token;
}
getGroupById(group_ids) {
return new Promise((resolve, reject) => {
const opts = {
method: 'GET',
uri: VK_API + '/groups.getById',
qs: {
group_ids,
fields: FIELDS,
version: API_VERSION,
access_token: this.access_token
}
}
request.post(opts, (err, response) => {
if (err) return reject(err);
try {
const body = JSON.parse(response.body).response;
// Info about group is the beginning of response array;
const group = body[0] || {};
body.shift();
const events = body;
return resolve({group, events});
} catch (error) {
return resolve([]);
}
});
})
}
}
module.exports = Vk;