-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.js
100 lines (93 loc) · 3.49 KB
/
github.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
class Github {
constructor() {
this.searchUrl = `https://api.github.com/search/`
this.userUrl = `https://api.github.com/users/`
}
filter(items) {
let arr = []
items.forEach(element => {
arr.push({
user: {
login: element.login,
html_url: element.html_url,
avatar_url: element.avatar_url,
url: element.url
},
repository: {
created_at: element.created_at,
description: element.description,
forks_count: element.forks_count,
full_name: element.full_name,
homepage: element.homepage,
html_url: element.html_url,
language: element.language,
name: element.name,
open_issues_count: element.open_issues_count,
owner: element.owner,
stargazers_count: element.stargazers_count,
pushed_at: element.pushed_at,
watchers_count: element.watchers_count
},
issue: {
comments: element.comments,
created_at: element.created_at,
html_url: element.html_url,
number: element.number,
repository_url: element.repository_url,
state: element.state,
title: element.title,
user: element.user
},
})
})
return arr
}
async getSearchData(type, input) {
let response = await fetch(this.searchUrl + `${type}?q=${input}`)
let json = await response.json()
console.log(this.searchUrl + `${type}?q=${input}`)
return {
transmitted: {
url: this.searchUrl + `${type}?q=${input}`,
type: type,
input: input
},
total_count: json.total_count,
items: this.filter(json.items)
}
}
async getPageData(transmitted, page) {
let response = await fetch(transmitted.url + `&page=${page}`)
let json = await response.json()
console.log("getPageData() ", transmitted.url + `&page=${page}`)
return {
transmitted: transmitted,
total_count: json.total_count,
items: this.filter(json.items)
}
}
async getUserData(username) {
let response = await fetch(this.userUrl + username)
let json = await response.json()
console.log("getUserData() ", this.userUrl + username)
return json
}
async getUserRepo(url, page) {
let response = await fetch(url + "?sort=pushed" + `&page=${page}`)
let json = await response.json()
console.log("getUserRepo() ", url + "?sort=pushed" + `&page=${page}`);
return json
}
async getFollowData(url, page) {
let response = await fetch(url + `?page=${page}`)
let json = await response.json()
console.log("getFollowData() ", url + `?page=${page}`)
return this.filter(json)
}
async getRateLimit() {
let response = await fetch(`https://api.github.com/rate_limit`)
let json = await response.json()
console.log("getRateLimit()")
return json
}
}