forked from KKBOX/OpenAPI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApi.js
More file actions
96 lines (83 loc) · 3.03 KB
/
Copy pathApi.js
File metadata and controls
96 lines (83 loc) · 3.03 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import HttpClient from './HttpClient'
import SearchFetcher from './SearchFetcher'
import TrackFetcher from './TrackFetcher'
import AlbumFetcher from './AlbumFetcher'
import ArtistFetcher from './ArtistFetcher'
import FeaturedPlaylistFetcher from './FeaturedPlaylistFetcher'
import FeaturedPlaylistCategoryFetcher from './FeaturedPlaylistCategoryFetcher'
import NewReleaseCategoryFetcher from './NewReleaseCategoryFetcher'
import NewHitsPlaylistFetcher from './NewHitsPlaylistFetcher'
import GenreStationFetcher from './GenreStationFetcher'
import MoodStationFetcher from './MoodStationFetcher'
import ChartFetcher from './ChartFetcher'
/**
* Fetch KKBOX resources.
*/
export default class Api {
/**
* Need access token to initialize.
*
* @param {string} token - Get via Auth.
* @param {string} [territory = 'TW'] - ['TW', 'HK', 'SG', 'MY', 'JP'] The territory for the fetcher.
* @example new Api(token)
* @example new Api(token, 'TW')
*/
constructor(token, territory = 'TW') {
this.territory = territory
this.httpClient = undefined
this.setToken(token)
}
/**
* Set new token and create fetchers with the new token.
*
* @param {string} token - Get via Auth.
* @example api.setToken(token)
*/
setToken(token) {
this.httpClient = new HttpClient(token)
/**
* @type {SearchFetcher}
*/
this.searchFetcher = new SearchFetcher(this.httpClient, this.territory)
/**
* @type {TrackFetcher}
*/
this.trackFetcher = new TrackFetcher(this.httpClient, this.territory)
/**
* @type {AlbumFetcher}
*/
this.albumFetcher = new AlbumFetcher(this.httpClient, this.territory)
/**
* @type {ArtistFetcher}
*/
this.artistFetcher = new ArtistFetcher(this.httpClient, this.territory)
/**
* @type {FeaturedPlaylistFetcher}
*/
this.featuredPlaylistFetcher = new FeaturedPlaylistFetcher(this.httpClient, this.territory)
/**
* @type {FeaturedPlaylistCategoryFetcher}
*/
this.featuredPlaylistCategoryFetcher = new FeaturedPlaylistCategoryFetcher(this.httpClient, this.territory)
/**
* @type {NewReleaseCategoryFetcher}
*/
this.newReleaseCategoryFetcher = new NewReleaseCategoryFetcher(this.httpClient, this.territory)
/**
* @type {NewHitsPlaylistFetcher}
*/
this.newHitsPlaylistFetcher = new NewHitsPlaylistFetcher(this.httpClient, this.territory)
/**
* @type {GenreStationFetcher}
*/
this.genreStationFetcher = new GenreStationFetcher(this.httpClient, this.territory)
/**
* @type {MoodStationFetcher}
*/
this.moodStationFetcher = new MoodStationFetcher(this.httpClient, this.territory)
/**
* @type {ChartFetcher}
*/
this.chartFetcher = new ChartFetcher(this.httpClient, this.territory)
}
}