-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromises_exercise.html
69 lines (57 loc) · 2.52 KB
/
promises_exercise.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/keys.js"></script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
crossorigin="anonymous"></script>
<script>
function getProfileOld(userID) {
// fetch(`https://github.com/${userID}`, {headers: {'Authorization': githubToken}}).then(res => res.json)
// /users/:username/events
//https://cors-anywhere.herokuapp.com/https://github.com/users/${userID}/events`
fetch('https://cors-anywhere.herokuapp.com/https://api.github.com/users/' + userID + '/events/public', {headers: {'Authorization': githubKey}})
.then((response) => {
console.log(response);
return response.json();
})
.then((data) => {
// build html
let pushedEvents = data.filter(event => event["type"] === "PushEvent");
let repoList = pushedEvents.map((item) => item["created_at"]);
let maxDate = repoList.reduce((lastDate, currentDate) => {
return (lastDate > currentDate) ? lastDate : currentDate
}, 0);
console.log(maxDate);
return maxDate;
})
.catch(console.log);
};
function getProfile(userID) {
// fetch(`https://github.com/${userID}`, {headers: {'Authorization': githubToken}}).then(res => res.json)
// /users/:username/events
//https://cors-anywhere.herokuapp.com/https://github.com/users/${userID}/events`
fetch(`https://cors-anywhere.herokuapp.com/https://api.github.com/users/${userID}/events/public`, {headers: {'Authorization': githubKey}})
.then((response) => {
return response.json();
})
.then((data) => {
return data.filter(event => event["type"] === "PushEvent");
})
.then((pushedEvents) => {
console.log(pushedEvents.map((item) => item["created_at"])[0]);
return pushedEvents.map((item) => item["created_at"])[0];
})
.catch(console.log);
};
getProfile('gloriaLVela');
// console.log(getProfile('gloriaLVela'));
</script>
</body>
</html>