-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSharedPlaylistFetcher.js
More file actions
77 lines (71 loc) · 2.02 KB
/
Copy pathSharedPlaylistFetcher.js
File metadata and controls
77 lines (71 loc) · 2.02 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 { SHARED_PLAYLISTS as ENDPOINT } from '../Endpoint';
import Fetcher from './Fetcher';
/**
* Get playlist metadata.
* @see https://docs-en.kkbox.codes/v1.1/reference#shared-playlists
*/
export default class SharedPlaylistFetcher extends Fetcher {
/**
* @ignore
*/
constructor(http, territory = 'TW') {
super(http, territory);
/**
* @ignore
*/
this.playlistID = undefined;
}
/**
* Init the shared playlist fetcher.
*
* @param {string} playlistID - The ID of a playlist.
* @return {SharedPlaylistFetcher}
* @see https://docs-en.kkbox.codes/v1.1/reference#sharedplaylists-playlist_id
*/
setPlaylistID(playlistID) {
this.playlistID = playlistID;
return this;
}
/**
* Fetch metadata of the shared playlist with the shared playlist fetcher.
*
* @return {Promise}
* @example
* api.sharedPlaylistFetcher
* .setPlaylistID('4nUZM-TY2aVxZ2xaA-')
* .fetchMetadata();
* @see https://docs-en.kkbox.codes/v1.1/reference#sharedplaylists-playlist_id
*/
fetchMetadata() {
return this.http.get(ENDPOINT + '/' + this.playlistID, {
territory: this.territory
});
}
/**
* Get KKBOX web widget uri of the playlist.
* @example https://widget.kkbox.com/v1/?id=KmjwNXizu5MxHFSloP&type=playlist
* @return {string}
*/
getWidgetUri() {
return `https://widget.kkbox.com/v1/?id=${this.playlistID}&type=playlist`;
}
/**
* Fetch track list of a shared playlist.
*
* @param {number} [limit] - The size for one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example
* api.sharedPlaylistFetcher
* .setPlaylistID('4nUZM-TY2aVxZ2xaA-')
* .fetchTracks();
* @see https://docs-en.kkbox.codes/v1.1/reference#sharedplaylists-playlist_id-tracks
*/
fetchTracks(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + '/' + this.playlistID + '/tracks', {
territory: this.territory,
limit: limit,
offset: offset
});
}
}