forked from KKBOX/OpenAPI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlbumFetcher.js
More file actions
71 lines (65 loc) · 1.83 KB
/
Copy pathAlbumFetcher.js
File metadata and controls
71 lines (65 loc) · 1.83 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
import { ALBUMS as ENDPOINT } from '../Endpoint';
import Fetcher from './Fetcher';
/**
* Fetch metadata and tracks of a album.
* @see https://docs-en.kkbox.codes/v1.1/reference#albums
*/
export default class AlbumFetcher extends Fetcher {
/**
* @ignore
*/
constructor(http, territory = 'TW') {
super(http, territory);
/**
* @ignore
*/
this.albumID = undefined;
}
/**
* Set the album fetcher.
*
* @param {string} albumID - The ID of an album.
* @return {AlbumFetcher}
* @see https://docs-en.kkbox.codes/v1.1/reference#albums-album_id
*/
setAlbumID(albumID) {
this.albumID = albumID;
return this;
}
/**
* Fetch metadata of the album you create.
*
* @return {Promise}
* @example api.albumFetcher.setAlbumID('KmRKnW5qmUrTnGRuxF').fetchMetadata();
* @see https://docs-en.kkbox.codes/v1.1/reference#albums-album_id
*/
fetchMetadata() {
return this.http.get(ENDPOINT + '/' + this.albumID, {
territory: this.territory
});
}
/**
* Get KKBOX web widget uri of the album.
* @example https://widget.kkbox.com/v1/?id=4qtXcj31wYJTRZbb23&type=album
* @return {string}
*/
getWidgetUri() {
return `https://widget.kkbox.com/v1/?id=${this.albumID}&type=album`;
}
/**
* Get tracks in an album. Result will be return with pagination.
*
* @param {number} [limit] - The size for one page.
* @param {number} [offset] - The offset index for first element.
* @return {Promise}
* @example api.albumFetcher.setAlbumID('KmRKnW5qmUrTnGRuxF').fetchTracks();
* @see https://docs-en.kkbox.codes/v1.1/reference#albums-album_id-tracks
*/
fetchTracks(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + '/' + this.albumID + '/tracks', {
territory: this.territory,
limit: limit,
offset: offset
});
}
}