-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
54 lines (49 loc) · 2.09 KB
/
github.js
File metadata and controls
54 lines (49 loc) · 2.09 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Handle github backend part =======================
class Github {
constructor() {
// this.client_ID = client_ID;
// this.client_SECRET = client_SECRET;
this.repos_count = 10;
this.repos_order = 'created: asc'
}
async getProfile(user) {
// console.log(user);
try {
// Fetching the user data
const fetchedProfile = await fetch(`https://api.github.com/users/${user}`);
const profileData = await fetchedProfile.json();
// console.log(profileData);
// Fetching repos data
const fetchedRepos = await fetch(`https://api.github.com/users/${user}/repos?per_page=${this.repos_count}&sort=${this.repos_order}`);
const reposData = await fetchedRepos.json();
// console.log(reposData);
// Return as an object of necessary (minimized) data from big data of Github
return {
// Whole data pass to catch 'message' property from it for validation
mainData: profileData,
// Profile basic necessary info
profile_pic: profileData.avatar_url,
user_name: profileData.login,
name: profileData.name,
profile_url: profileData.html_url,
followers: profileData.followers,
following: profileData.following,
public_repos: profileData.public_repos,
public_gists: profileData.public_gists,
company: profileData.company,
blog: profileData.blog,
user_location: profileData.location,
email: profileData.email,
hireable: profileData.hireable,
twitter_username: profileData.twitter_username,
profile_type: profileData.type,
created_at: profileData.created_at,
last_updated_at: profileData.last_updated_at,
// Repo related info
repos_data: reposData
}
} catch (err) {
console.log(err.message)
}
}
}