-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
37 lines (29 loc) · 1.02 KB
/
github.js
File metadata and controls
37 lines (29 loc) · 1.02 KB
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
'use strict';
class Github {
constructor() {
const clientId = 'a9779b35180351d0adb5';
const clientSecret = 'f82b287d4cefb99d56908e5c9a929c09ff9312cc';
this.authUrlEnd = `client_id=${clientId}&client_secret=${clientSecret}`;
this.baseURL = 'https://api.github.com';
}
async searchUsers(input, options) {
const { per_page, page } = options;
const pagination = `per_page=${per_page}&page=${page}`;
const usersUrl = `${
this.baseURL
}/search/users?q=${input}&${pagination}&${this.authUrlEnd}`;
const users = await fetch(usersUrl);
const data = await users.json();
return {
users: data.items,
total: data.total_count,
status: users.status,
errorMessage: data.message || '',
};
}
async getUser(username) {
const userUrl = `${this.baseURL}/users/${username}?${this.authUrlEnd}`;
const user = await fetch(userUrl);
return user.json();
}
}