forked from KKBOX/OpenAPI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArtistFetcher.js
More file actions
96 lines (89 loc) · 2.71 KB
/
Copy pathArtistFetcher.js
File metadata and controls
96 lines (89 loc) · 2.71 KB
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
import { ARTISTS as ENDPOINT } from '../Endpoint';
import Fetcher from './Fetcher';
/**
* Get artist metadata.
* @see https://docs-en.kkbox.codes/v1.1/reference#artists
*/
export default class ArtistFetcher extends Fetcher {
/**
* @ignore
*/
constructor(http, territory = 'TW') {
super(http, territory);
/**
* @ignore
*/
this.artistID = undefined;
}
/**
* Init the artist object.
*
* @param {string} artistID - The ID of an artist.
* @return {Artist}
* @see https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id
*/
setArtistID(artistID) {
this.artistID = artistID;
return this;
}
/**
* Fetch metadata of the artist you find.
*
* @return {Promise}
* @example api.artistFetcher.setArtistID('Cnv_K6i5Ft4y41SxLy').fetchMetadata();
* @see https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id
*/
fetchMetadata() {
return this.http.get(ENDPOINT + '/' + this.artistID, {
territory: this.territory
});
}
/**
* Fetch albums belong to an artist.
*
* @param {number} [limit] - The size for one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example api.artistFetcher.setArtistID('Cnv_K6i5Ft4y41SxLy').fetchAlbums();
* @see https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id-albums
*/
fetchAlbums(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + '/' + this.artistID + '/albums', {
territory: this.territory,
limit: limit,
offset: offset
});
}
/**
* Fetch top tracks belong to an artist.
*
* @param {number} [limit] - The size for one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example api.artistFetcher.setArtistID('Cnv_K6i5Ft4y41SxLy').fetchTopTracks();
* @see https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id-toptracks
*/
fetchTopTracks(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + '/' + this.artistID + '/top-tracks', {
territory: this.territory,
limit: limit,
offset: offset
});
}
/**
* Fetch related artists
*
* @param {number} [limit] - The size for one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example api.artistFetcher.setArtistID('Cnv_K6i5Ft4y41SxLy').fetchRelatedArtists();
* @see https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id-relatedartists
*/
fetchRelatedArtists(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + '/' + this.artistID + '/related-artists', {
territory: this.territory,
limit: limit,
offset: offset
});
}
}