-
Notifications
You must be signed in to change notification settings - Fork 0
/
getUsers.js
43 lines (36 loc) · 1.07 KB
/
getUsers.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
import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config();
const getUsers = async () => {
let followers = [],
following = [];
await gather('followers');
await gather('following');
async function gather(type, page = 1) {
let res = await axios({
method: 'GET',
url: `https://api.github.com/user/${type}?per_page=100&page=${page}`,
headers: {
Authorization: `Bearer ${process.env.TOKEN}`,
},
});
res = res.data;
// putting data in respective array
if (type == 'followers') followers = [...followers, ...res];
else following = [...following, ...res];
// recursively call till every data is gathered
if (res.length == 0) return;
await gather(type, ++page);
}
// creating object with login
const f1 = {},
f2 = {};
for (let user of followers) {
f1[user.login] = 1;
}
for (let user of following) {
f2[user.login] = 1;
}
return [f1, f2];
};
export default getUsers;