This repository was archived by the owner on Apr 29, 2025. It is now read-only.
forked from KKBOX/OpenAPI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartFetcher.js
More file actions
73 lines (67 loc) · 2.05 KB
/
Copy pathChartFetcher.js
File metadata and controls
73 lines (67 loc) · 2.05 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
import {CHARTS as ENDPOINT} from '../Endpoint'
import Fetcher from './Fetcher'
/**
* The fetcher that can fetch chart playlists.
* @see https://docs-en.kkbox.codes/v1.1/reference#charts
*/
export default class ChartFetcher extends Fetcher {
/**
* @ignore
*/
constructor(http, territory = 'TW') {
super(http, territory)
/**
* @ignore
*/
this.playlist_id = undefined
}
/**
* Fetch chart playlists.
*
* @return {Promise}
* @example api.chartFetcher.fetchCharts()
* @see https://docs-en.kkbox.codes/v1.1/reference#charts_1
*/
fetchCharts() {
return this.http.get(ENDPOINT, {
territory: this.territory
})
}
/**
* Init the chart fetcher.
*
* @param {string} playlist_id - The playlist ID.
* @return {ChartFetcher}
* @see https://docs-en.kkbox.codes/v1.1/reference#charts-playlist_id
*/
setPlaylistID(playlist_id) {
this.playlist_id = playlist_id
return this
}
/**
* Fetch playlist of the chart you set.
*
* @return {Promise}
* @example api.chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchMetadata()
* @see https://docs-en.kkbox.codes/v1.1/reference#charts-playlist_id
*/
fetchMetadata() {
return this.http.get(ENDPOINT + this.playlist_id, {territory: this.territory})
}
/**
* Fetch tracks of the playlist with the chart fetcher you init. 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.chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchTracks()
* @see https://docs-en.kkbox.codes/v1.1/reference#charts-playlist_id-tracks
*/
fetchTracks(limit = undefined, offset = undefined) {
return this.http.get(ENDPOINT + this.playlist_id + '/tracks', {
territory: this.territory,
limit: limit,
offset: offset
})
}
}