Skip to content

Commit 780566d

Browse files
committed
public artists api documentation
1 parent 611d0ab commit 780566d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main/kotlin/com/adamratzman/spotify/endpoints/pub/artists/ArtistsAPI.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4343
*
4444
* @throws BadRequestException if [artistId] is not found, or filter parameters are illegal
4545
*/
46-
fun getArtistAlbums(artistId: String, market: Market? = null, limit: Int = 20, offset: Int = 0, vararg include: AlbumInclusionStrategy): SpotifyRestAction<LinkedResult<SimpleAlbum>> {
46+
fun getArtistAlbums(artistId: String, market: Market? = null, limit: Int = 20, offset: Int = 0, include: List<AlbumInclusionStrategy> = listOf()): SpotifyRestAction<LinkedResult<SimpleAlbum>> {
4747
return toAction(Supplier {
4848
get("https://api.spotify.com/v1/artists/${artistId.encode()}/albums?limit=$limit&offset=$offset" +
4949
if (market != null) "&market=${market.code}" else "" +
@@ -56,13 +56,29 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5656
ALBUM("album"), SINGLE("single"), APPEARS_ON("appears_on"), COMPILATION("compilation")
5757
}
5858

59+
/**
60+
* Get Spotify catalog information about an artist’s top tracks **by country**.
61+
* @param artistId The Spotify ID for the artist.
62+
* @param market The country ([Market]) to search. Unlike endpoints with optional Track Relinking, the Market is **not** optional.
63+
*
64+
* @throws BadRequestException if tracks are not available in the specified [Market] or the [artistId] is not found
65+
*/
5966
fun getArtistTopTracks(artistId: String, market: Market): SpotifyRestAction<List<Track>> {
6067
return toAction(Supplier {
6168
get("https://api.spotify.com/v1/artists/${artistId.encode()}/top-tracks?country=${market.code}").toObject<TrackList>(api).tracks.map { it!! }
6269
})
6370

6471
}
6572

73+
/**
74+
* Get Spotify catalog information about artists similar to a given artist.
75+
* Similarity is based on analysis of the Spotify community’s listening history.
76+
*
77+
* @param artistId The Spotify ID for the artist.
78+
*
79+
* @return List of *never-null*, but possibly empty Artist objects representing similar artists
80+
* @throws BadRequestException if the [artistId] is not found
81+
*/
6682
fun getRelatedArtists(artistId: String): SpotifyRestAction<List<Artist>> {
6783
return toAction(Supplier {
6884
get("https://api.spotify.com/v1/artists/${artistId.encode()}/related-artists").toObject<ArtistList>(api).artists.map { it!! }

src/test/kotlin/com/adamratzman/spotify/endpoints/pub/artists/ArtistsAPITest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.adamratzman.spotify.kotlin.endpoints.pub.artists
22

3+
import com.adamratzman.spotify.endpoints.pub.artists.ArtistsAPI
34
import com.adamratzman.spotify.main.api
45
import com.adamratzman.spotify.utils.BadRequestException
56
import com.adamratzman.spotify.utils.Market
@@ -15,7 +16,8 @@ class ArtistsAPITest : TestCase() {
1516
}
1617

1718
fun testGetArtistAlbums() {
18-
println(api.artists.getArtistAlbums("0C8ZW7ezQVs4URX5aX7Kqx").complete())
19+
println(api.artists.getArtistAlbums("0C8ZW7ezQVs4URX5aX7Kqx",
20+
include = listOf(ArtistsAPI.AlbumInclusionStrategy.ALBUM, ArtistsAPI.AlbumInclusionStrategy.SINGLE)).complete())
1921
}
2022

2123
fun testGetArtistTopTracks() {

0 commit comments

Comments
 (0)