-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
30 lines (26 loc) · 952 Bytes
/
github.js
File metadata and controls
30 lines (26 loc) · 952 Bytes
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
class Github {
constructor() {
this.clientID = "000d2ec987b1421d2718";
this.clientSecret = "035cd7ab2792373a38398134fe622f8115a4c33c";
this.repos_count = 7;
this.repos_sort = "created: asc";
// from yourgithub oauth application
}
// fetch github api(that is username plus repos)
async getUser(user) {
const profileResponse = await fetch(
`https://api.github.com/users/${user}?client_id=${this.clientID}&client_secret=${this.clientSecret}`
);
// fetches github user name
// note that the client ID and secret where used to generate users
const repoResponse = await fetch(
`https://api.github.com/users/${user}/repos?per_page=${this.repos_count}&sort=${this.client_secret}client_id=${this.clientID}&client_secret=${this.clientSecret}`
);
const profile = await profileResponse.json();
const repos = await repoResponse.json();
return {
profile,
repos
};
}
}