Skip to content

Commit 2af0d21

Browse files
authored
Merge pull request #6 from ajhsu/feature/fill-up-missing-endpoints
Fill up some of missing endpoints
2 parents a4c7757 + 16358c1 commit 2af0d21

6 files changed

Lines changed: 109 additions & 4 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kkbox/kkbox-js-sdk",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "KKBOX Open API developer SDK for JavaScript. Use it to easily access KKBOX open API to get various metadata about KKBOX's tracks, albums, artists, playlists and stations. ",
55
"main": "./dist/SDK.js",
66
"scripts": {

src/api/ArtistFetcher.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,21 @@ export default class ArtistFetcher extends Fetcher {
7474
offset: offset
7575
})
7676
}
77+
78+
/**
79+
* Fetch related artists
80+
*
81+
* @param {number} [limit] - The size for one page.
82+
* @param {number} [offset] - The offset index for first element.
83+
* @return {Promise}
84+
* @example api.artistFetcher.setArtistID('Cnv_K6i5Ft4y41SxLy').fetchRelatedArtists()
85+
* @see https://docs-en.kkbox.codes/v1.1/reference#artists-artist_id-relatedartists
86+
*/
87+
fetchRelatedArtists(limit = undefined, offset = undefined) {
88+
return this.http.get(ENDPOINT + this.artist_id + '/related-artists', {
89+
territory: this.territory,
90+
limit: limit,
91+
offset: offset
92+
})
93+
}
7794
}

src/api/ChartFetcher.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export default class ChartFetcher extends Fetcher {
1111
*/
1212
constructor(http, territory = 'TW') {
1313
super(http, territory = 'TW')
14+
15+
/**
16+
* @ignore
17+
*/
18+
this.playlist_id = undefined
1419
}
1520

1621
/**
@@ -25,4 +30,44 @@ export default class ChartFetcher extends Fetcher {
2530
territory: this.territory
2631
})
2732
}
33+
34+
/**
35+
* Init the chart fetcher.
36+
*
37+
* @param {string} playlist_id - The playlist ID.
38+
* @return {ChartFetcher}
39+
* @see https://docs-en.kkbox.codes/v1.1/reference#charts-playlist_id
40+
*/
41+
setPlaylistID(playlist_id) {
42+
this.playlist_id = playlist_id
43+
return this
44+
}
45+
46+
/**
47+
* Fetch playlist of the chart you set.
48+
*
49+
* @return {Promise}
50+
* @example api.chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchMetadata()
51+
* @see https://docs-en.kkbox.codes/v1.1/reference#charts-playlist_id
52+
*/
53+
fetchMetadata() {
54+
return this.http.get(ENDPOINT + this.playlist_id, {territory: this.territory})
55+
}
56+
57+
/**
58+
* Fetch tracks of the playlist with the chart fetcher you init. Result will be paged.
59+
*
60+
* @param {number} [limit] - The size of one page.
61+
* @param {number} [offset] - The offset index for first element.
62+
* @return {Promise}
63+
* @example api.chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchTracks()
64+
* @see https://docs-en.kkbox.codes/v1.1/reference#charts-playlist_id-tracks
65+
*/
66+
fetchTracks(limit = undefined, offset = undefined) {
67+
return this.http.get(ENDPOINT + this.playlist_id + '/tracks', {
68+
territory: this.territory,
69+
limit: limit,
70+
offset: offset
71+
})
72+
}
2873
}

src/api/NewHitsPlaylistFetcher.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class NewHitsPlaylistFetcher extends Fetcher {
4646
}
4747

4848
/**
49-
* Fetch metadata of the new release category you set.
49+
* Fetch metadata of the new hits playlist you set.
5050
*
5151
* @return {Promise}
5252
* @example api.newHitsPlaylistFetcher.setPlaylistID('DZrC8m29ciOFY2JAm3').fetchMetadata()
@@ -55,4 +55,21 @@ export default class NewHitsPlaylistFetcher extends Fetcher {
5555
fetchMetadata() {
5656
return this.http.get(ENDPOINT + this.playlist_id, {territory: this.territory})
5757
}
58+
59+
/**
60+
* Fetch tracks of the new hits playlist you set. Result will be paged.
61+
*
62+
* @param {number} [limit] - The size of one page.
63+
* @param {number} [offset] - The offset index for first element.
64+
* @return {Promise}
65+
* @example api.newHitsPlaylistFetcher.setPlaylistID('DZrC8m29ciOFY2JAm3').fetchTracks()
66+
* @see https://docs-en.kkbox.codes/v1.1/reference#newhitsplaylists-playlist_id-tracks
67+
*/
68+
fetchTracks(limit = undefined, offset = undefined) {
69+
return this.http.get(ENDPOINT + this.playlist_id + '/tracks', {
70+
territory: this.territory,
71+
limit: limit,
72+
offset: offset
73+
})
74+
}
5875
}

test/apitest.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ describe('Api Begin to Test', () => {
218218
artistFetcher.fetchTopTracks().then(response => response.status.should.be.exactly(200), reject => should.not.exists(reject))
219219
})
220220
})
221+
222+
describe('#fetchRelatedArtists()', () => {
223+
it('should response status 200', (done) => {
224+
artistFetcher.fetchRelatedArtists().then(response => response.status.should.be.exactly(200), reject => should.not.exists(reject))
225+
})
226+
})
221227
})
222228

223229
describe('Artist fetch album tests', () => {
@@ -352,6 +358,20 @@ describe('Api Begin to Test', () => {
352358
})
353359
})
354360
})
361+
362+
describe('#fetchMetadata()', () => {
363+
it('should succeed', (done) => {
364+
chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchMetadata()
365+
.then(response => response.status.should.be.exactly(200), reject => should.not.exists(reject))
366+
})
367+
})
368+
369+
describe('#fetchTracks()', () => {
370+
it('should succeed', (done) => {
371+
chartFetcher.setPlaylistID('4mJSYXvueA8t0odsny').fetchTracks()
372+
.then(response => response.status.should.be.exactly(200), reject => should.not.exists(reject))
373+
})
374+
})
355375
})
356376

357377
describe('New Release Category', () => {
@@ -413,7 +433,13 @@ describe('Api Begin to Test', () => {
413433
return f.fetchMetadata().then(response => response.status.should.be.exactly(200), reject => should.not.exists(reject)).catch(error => should.not.exsits(error))
414434
})
415435
})
416-
})
436+
437+
describe('#fetchTracks()', () => {
438+
it('should succeed', () => {
439+
return f.fetchTracks().then(response => response.status.should.be.exactly(200), reject => should.not.exists(reject)).catch(error => should.not.exsits(error))
440+
})
441+
})
442+
})
417443
}, reject => should.not.exists(reject))
418444
})
419445
})

0 commit comments

Comments
 (0)