KKBOXOpenAPI
public class KKBOXOpenAPI
The class helps you to access KKBOX’s Open API in Swift programming language.
Please create an instance of the class by calling
KKBOXOpenAPI.init(clientID:, secret:, scope:) and then fetch an access
token by passing a client credential. Then you can do the other API calls.
-
Create an instance of KKBOXOpenAPI by giving a client ID and secret.
To obtain a client ID and secret, visit KKBOX’s Developer Site .
Declaration
Swift
public init(clientID: String, secret: String, scope: KKScope = .none)Parameters
clientIDA valid client ID
secretA valid client Secret
scopeScope of the client.
-
Scope of the client. It is
KKScope.noneby default.Declaration
Swift
public var requestScope: KKScope -
The current access token.
Declaration
Swift
public private(set) var accessToken: KKAccessToken? { get set } -
MARK: - Authentication If the user has logged-in into KKBOX or not.
Declaration
Swift
public var isLoggedIn: Bool { get } -
Remove current access token.
Declaration
Swift
public func logout()
-
Fetch an access token by passing client credential.
Throws
KKBOXOpenAPIError.failedToCreateClientCredentialDeclaration
Swift
public func fetchAccessTokenByClientCredential(callback: @escaping (_ result: KKAPIResult<KKAccessToken>) -> ()) throws -> URLSessionTaskParameters
callbackThe callback closure.
resultThe access token.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch a song track by giving a song track ID.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(track ID: String, territory: KKTerritory = .taiwan, callback: @escaping (_ result: KKAPIResult<KKTrackInfo>) -> ()) throws -> URLSessionTaskParameters
IDID of the track.
territoryThe Territory
callbackThe callback closure.
resultThe result that contains the song track info.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch an album by giving an album ID.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(album ID: String, territory: KKTerritory = .taiwan, callback: @escaping (_ result: KKAPIResult<KKAlbumInfo>) -> ()) throws -> URLSessionTaskParameters
IDID of the album.
territoryThe Territory.
callbackThe callback closure.
resultThe result that contains the album info.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetch(tracksInAlbum ID: String, territory: KKTerritory = .taiwan, callback: @escaping (_ result: KKAPIResult<KKTrackList>) -> ()) throws -> URLSessionTaskParameters
IDID of the album.
territoryThe Territory.
callbackThe callback closure.
resultThe result that contains tracks of the album.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch the profile by giving an artist ID.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(artist ID: String, territory: KKTerritory = .taiwan, callback: @escaping (_ result: KKAPIResult<KKArtistInfo>) -> ()) throws -> URLSessionTaskParameters
IDID of the artist.
territoryThe Territory.
callbackThe callback closure.
resultThe result that contains profile of the artist.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetch(albumsBelongToArtist ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 200, callback: @escaping (_ result: KKAPIResult<KKAlbumList>) -> ()) throws -> URLSessionTaskParameters
IDID of the artist.
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 200 by default.
callbackThe callback closure.
resultThe result that contains albums of the artist.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetch(topTracksOfArtist ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 200, callback: @escaping (_ result: KKAPIResult<KKTrackList>) -> ()) throws -> URLSessionTaskParameters
IDID of the artist.
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 200 by default.
callbackThe callback closure.
resultThe result that contains top tracks of the artist.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetch(relatedArtistsOfArtist ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 20, callback: @escaping (_ result: KKAPIResult<KKArtistList>) -> ()) throws -> URLSessionTaskParameters
IDID of the artist.
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 20 by default.
callbackThe callback closure.
resultThe result that contains related artists of the artist.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch a playlist’s metadata and tracks by giving the playlist ID
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(playlist ID: String, territory: KKTerritory = .taiwan, callback: @escaping (_ result: KKAPIResult<KKPlaylistInfo>) -> ()) throws -> URLSessionTaskParameters
IDThe playlist ID.
territoryThe Territory.
callbackThe callback closure.
resultThe result that contains the metadata and tracks of the playlist.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch tracks contained in a playlist.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(tracksInPlaylist ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 20, callback: @escaping (_ result: KKAPIResult<KKTrackList>) -> ()) throws -> URLSessionTaskParameters
IDThe playlist ID.
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 20 by default.
callbackThe callback closure.
resultThe result that contains the metadata of the playlist.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetchFeaturedPlaylists(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKPlaylistList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the featured playlists.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetchNewHitsPlaylists(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 10, callback: @escaping (_ result: KKAPIResult<KKPlaylistList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 10 by default.
callbackThe callback closure.
resultThe result that contains the New-Hits playlists.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetchFeaturedPlaylistCategories(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKFeaturedPlaylistCategoryList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains featured playlist categories.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch featured playlists in a category.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetchFeaturedPlaylist(inCategory ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKFeaturedPlaylistCategory>) -> ()) throws -> URLSessionTaskParameters
IDThe category ID.
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains featured playlists.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetchMoodStations(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKRadioStationList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the mood station categories.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch tracks in a mood radio station.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(tracksInMoodStation ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKRadioStation>) -> ()) throws -> URLSessionTaskParameters
IDMood station ID
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the tracks.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetchGenreStations(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKRadioStationList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the mood genre categories.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch tracks in a genre radio station.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(tracksInGenreStation ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKRadioStation>) -> ()) throws -> URLSessionTaskParameters
IDGenre station ID
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the tracks.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch the categories of the new released albums.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetchNewReleaseAlbumsCategories(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKNewReleasedAlbumsCategoryList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the categories.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Fetch albums in a given new released albums category.
See API reference.
Throws
KKBOXOpenAPIError.requireAccessToken.Declaration
Swift
public func fetch(newReleasedAlbumsUnderCategory ID: String, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 100, callback: @escaping (_ result: KKAPIResult<KKNewReleasedAlbumsCategory>) -> ()) throws -> URLSessionTaskParameters
IDThe category ID.
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 100 by default.
callbackThe callback closure.
resultThe result that contains the albums.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func fetchCharts(territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 50, callback: @escaping (_ result: KKAPIResult<KKPlaylistList>) -> ()) throws -> URLSessionTaskParameters
territoryThe Territory.
offsetThe offset. 0 by default.
limitThe limit. 50 by default.
callbackThe callback closure.
resultThe result that contains the charts.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
-
Declaration
Swift
public func search(with keyword: String, types: KKSearchType, territory: KKTerritory = .taiwan, offset: Int = 0, limit: Int = 50, callback: @escaping (_ result: KKAPIResult<KKSearchResults>) -> ()) throws -> URLSessionTaskParameters
keywordThe search keyword.
typesArtists, albums, tracks or playlists.
territoryThe territory.
offsetThe offset. 0 by default.
limitThe limit. 50 by default.
callbackThe callback closure.
resultThe result that contains search results.
Return Value
A URLSessionTask that you can use it to cancel current fetch.
KKBOXOpenAPI Class Reference