-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIManager.js
103 lines (91 loc) · 2.55 KB
/
APIManager.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 user {
constructor(firstName, lastName) {
this.first = firstName
this.last = lastName
}
}
class mainUser extends user {
constructor(firstName, lastName, city, state, imgUrl) {
super(firstName, lastName)
this.city = city
this.state = state
this.imgUrl = imgUrl
}
}
class APIManager {
constructor() {
this.data = {}
this.savedUsers = []
}
createUsers(respone) {
const results = respone.results
const firstUser = results[0]
this.data.mainUser = new mainUser(
firstUser.name.first,
firstUser.name.last,
firstUser.location.city,
firstUser.location.state,
firstUser.picture.large)
results.shift()
this.data.usersArray = results.map(u => {
return new user(u.name.first, u.name.last)
});
}
userAPIRequests() {
$.ajax({
method: "GET",
url: 'https://randomuser.me/api/?results=7',
dataType: 'json',
success: (respone) => {
this.createUsers(respone)
},
error: function (xhr, text, error) {
alert(text);
}
})
}
quoteAPIRequests() {
$.ajax({
method: "GET",
url: 'https://api.kanye.rest?format=text',
success: (response) => {
this.data.quote = response
},
error: function (xhr, text, error) {
alert(text);
}
})
}
pokemonAPIRequests() {
let randNum = Math.random() * 893
randNum = Math.round(randNum);
$.ajax({
method: "GET",
url: `https://pokeapi.co/api/v2/pokemon/${randNum}`,
success: (response) => {
this.data.pokemon = { name: response.name, img: response.sprites.front_default }
},
error: function (xhr, text, error) {
alert(text);
}
})
}
aboutMeAPIRequests() {
$.ajax({
method: "GET",
url: 'https://baconipsum.com/api/?type=meat-and-filler¶s=1&format=text',
success: (response) => {
this.data.aboutMe = response
},
error: function (xhr, text, error) {
alert(text);
}
})
}
allAPIRequests() {
this.userAPIRequests()
this.quoteAPIRequests()
this.pokemonAPIRequests()
this.aboutMeAPIRequests()
}
}