-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (38 loc) · 1.07 KB
/
main.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
require('es6-promise').polyfill();
require('isomorphic-fetch');
const BASE_URL_MUSICBRAINZ = `https://musicbrainz.org/ws/2/`;
const setMusicbrainzSearchQuery = (musicbrainzId, lookupRequest) => {
return `${BASE_URL_MUSICBRAINZ}${lookupRequest}/${musicbrainzId}?fmt=json`
}
const getDataArtist = async (musicbrainzId) => {
try {
const response = await fetch(setMusicbrainzSearchQuery(musicbrainzId,'artist'));
const data = await response.json();
return data ;
} catch (error) {
throw error;
}
}
const getDataLabel = async (musicbrainzId) => {
try {
const response = await fetch(setMusicbrainzSearchQuery(musicbrainzId,'label'));
const data = await response.json();
return data ;
} catch (error) {
throw error;
}
}
const getDataRecording = async (musicbrainzId) => {
try {
const response = await fetch(setMusicbrainzSearchQuery(musicbrainzId,'recording'));
const data = await response.json();
return data ;
} catch (error) {
throw error;
}
}
module.exports = mbrainz = {
getDataArtist,
getDataLabel,
getDataRecording
}