forked from KKBOX/OpenAPI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewHitsPlaylistFetcher.js
More file actions
77 lines (71 loc) · 2.2 KB
/
Copy pathNewHitsPlaylistFetcher.js
File metadata and controls
77 lines (71 loc) · 2.2 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
import { NEW_HITS_PLAYLISTS as ENDPOINT } from '../Endpoint';
import Fetcher from './Fetcher';
/**
* List new hits playlists.
* @see https://docs-en.kkbox.codes/v1.1/reference#new-hits-playlists
*/
export default class NewHitsPlaylistFetcher extends Fetcher {
/**
* @ignore
*/
constructor(http, territory = 'TW') {
super(http, territory);
/**
* @ignore
*/
this.playlistID = undefined;
}
/**
* Fetch all new hits playlists.
*
* @param {number} [limit] - The size of one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example api.newHitsPlaylistFetcher.fetchAllNewHitsPlaylists();
* @see https://docs-en.kkbox.codes/v1.1/reference#newhitsplaylists
*/
fetchAllNewHitsPlaylists(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT, {
territory: this.territory
});
}
/**
* Init the new hits playlist fetcher.
*
* @param {string} playlistID - The playlist ID.
* @return {NewHitsPlaylistFetcher}
* @see https://docs-en.kkbox.codes/v1.1/reference#newhitsplaylists-playlist_id
*/
setPlaylistID(playlistID) {
this.playlistID = playlistID;
return this;
}
/**
* Fetch metadata of the new hits playlist you set.
*
* @return {Promise}
* @example api.newHitsPlaylistFetcher.setPlaylistID('DZrC8m29ciOFY2JAm3').fetchMetadata();
* @see https://docs-en.kkbox.codes/v1.1/reference#newhitsplaylists-playlist_id
*/
fetchMetadata() {
return this.http.get(ENDPOINT + '/' + this.playlistID, {
territory: this.territory
});
}
/**
* Fetch tracks of the new hits playlist you set. Result will be paged.
*
* @param {number} [limit] - The size of one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example api.newHitsPlaylistFetcher.setPlaylistID('DZrC8m29ciOFY2JAm3').fetchTracks();
* @see https://docs-en.kkbox.codes/v1.1/reference#newhitsplaylists-playlist_id-tracks
*/
fetchTracks(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + '/' + this.playlistID + '/tracks', {
territory: this.territory,
limit: limit,
offset: offset
});
}
}