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
69 lines (63 loc) · 2.06 KB
/
Copy pathAlbumFetcher.js
File metadata and controls
69 lines (63 loc) · 2.06 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
import {ALBUMS as ENDPOINT} from '../Endpoint'
import Fetcher from './Fetcher'
/**
* Fetch metadata and tracks of a album.
* @see https://kkbox.gelato.io/docs/versions/v1.1/resources/albums
*/
export default class AlbumFetcher extends Fetcher {
/**
* @ignore
*/
constructor(http, territory = 'TW') {
super(http, territory)
/**
* @ignore
*/
this.album_id = undefined
}
/**
* Set the album fetcher.
*
* @param {string} album_id - The ID of an album.
* @return {AlbumFetcher}
* @see https://kkbox.gelato.io/docs/versions/v1.1/resources/albums/endpoints/get-albums-album_id
*/
setAlbumID(album_id) {
this.album_id = album_id
return this
}
/**
* Fetcy metadata of the album you create.
*
* @return {Promise}
* @example api.albumFetcher.setAlbumID('KmRKnW5qmUrTnGRuxF').fetchMetadata()
* @see https://kkbox.gelato.io/docs/versions/v1.1/resources/albums/endpoints/get-albums-album_id
*/
fetchMetadata() {
return this.http.get(ENDPOINT + this.album_id, {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.album_id}&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://kkbox.gelato.io/docs/versions/v1.1/resources/albums/endpoints/get-albums-album_id-tracks
*/
fetchTracks(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + this.album_id + '/tracks', {
territory: this.territory,
limit: limit,
offset: offset
})
}
}