-
Notifications
You must be signed in to change notification settings - Fork 0
/
kpoppingapi.js
66 lines (55 loc) · 1.91 KB
/
kpoppingapi.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
const axios = require('axios');
class KpoppingApi {
constructor() {
this.baseUrl = 'https://kpoppingapi.netlify.app/api';
}
async getIdolpics(idolName, groupName) {
let url = `${this.baseUrl}/idolpics/${idolName}/${groupName || ''}`;
try {
const res = await axios.get(url);
return res.data.images || res.data.message;
} catch (error) {
if (error.response) {
console.error(`Server responded with status code ${error.response.status}: ${error.response.data.message}`);
} else if (error.request) {
console.error('No response received from the server');
} else {
console.error('Error setting up the request:', error.message);
}
throw error;
}
}
async getGroupImages(groupName) {
let url = `${this.baseUrl}/groupImages/${groupName}`;
try {
const res = await axios.get(url);
return res.data.images || res.data.message;
} catch (error) {
if (error.response) {
console.error(`Server responded with status code ${error.response.status}: ${error.response.data.message}`);
} else if (error.request) {
console.error('No response received from the server');
} else {
console.error('Error setting up the request:', error.message);
}
throw error;
}
}
async getProfileData(name, group) {
let url = `${this.baseUrl}/profile/${name}/${group || ''}`;
try {
const res = await axios.get(url);
return res.data || res.data.message;
} catch (error) {
if (error.response) {
console.error(`Server responded with status code ${error.response.status}: ${error.response.data.message}`);
} else if (error.request) {
console.error('No response received from the server');
} else {
console.error('Error setting up the request:', error.message);
}
throw error;
}
}
}
module.exports = KpoppingApi;