Skip to content

Commit 673c40a

Browse files
committed
write ClientFollowingApi and ClientLibraryApi samples
1 parent c46d1fd commit 673c40a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

samples/src/main/kotlin/private/ClientFollowingApiSample.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,46 @@ fun main() {
1414
}
1515
}.build()
1616

17+
// see if you're following playlist "I'm Good Radio"
18+
println(api.following.isFollowingPlaylist("spotify:playlist:37i9dQZF1E8L0j2hm3kP31").complete())
19+
20+
// see if you're following users adamratzman1 and adamratzman
21+
println(api.following.isFollowingUsers("adamratzman1", "adamratzman").complete())
22+
23+
// see if you're following artist Louane
24+
println(api.following.isFollowingArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete())
25+
26+
// get all followed artists, limiting 1 each request
27+
println(api.following.getFollowedArtists(limit = 1).getAllItems().complete().map { it.name })
28+
29+
30+
// follow and unfollow, if you weren't previously following, the artist Louane
31+
32+
val isFollowingLouane = api.following.isFollowingArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete()
33+
34+
if (isFollowingLouane) api.following.unfollowArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete()
35+
api.following.followArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete()
36+
37+
if (!isFollowingLouane) api.following.unfollowArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete()
38+
39+
40+
// follow and unfollow, if you weren't previously following, the user adamratzman1
41+
42+
val isFollowingAdam = api.following.isFollowingUser("adamratzman1").complete()
43+
44+
if (isFollowingAdam) api.following.unfollowUser("adamratzman1").complete()
45+
api.following.followUser("adamratzman1").complete()
46+
47+
if (!isFollowingAdam) api.following.unfollowUser("adamratzman1").complete()
48+
49+
50+
// follow and unfollow, if you weren't previously following, the playlist Today's Top Hits
51+
52+
val isFollowingTodaysTopHits = api.following.isFollowingPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
53+
54+
if (isFollowingTodaysTopHits) api.following.unfollowPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
55+
api.following.followPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
56+
57+
if (!isFollowingTodaysTopHits) api.following.unfollowPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
58+
1759
}

samples/src/main/kotlin/private/ClientLibraryApiSample.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package private
33

44
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
import com.adamratzman.spotify.endpoints.client.LibraryType.TRACK
56

67
fun main() {
78
// instantiate api
@@ -14,4 +15,17 @@ fun main() {
1415
}
1516
}.build()
1617

18+
19+
// get all your saved tracks
20+
println(api.library.getSavedTracks(limit = 50).getAllItems().complete().map { it.track.name })
21+
22+
// get your 11-20th saved albums
23+
println(api.library.getSavedAlbums(limit = 10, offset = 10).complete().map { it.album.name })
24+
25+
// check if your library contains the track "I'm Good" by the Mowgli's
26+
println(api.library.contains(TRACK, api.search.searchTrack("I'm Good the Mowgli's").complete()[0].id).complete())
27+
28+
// add and remove track "Up" by Nav
29+
api.library.add(TRACK, "spotify:track:5qbcsZMwL0x46sX7VO37Ye").complete()
30+
api.library.remove(TRACK, "spotify:track:5qbcsZMwL0x46sX7VO37Ye").complete()
1731
}

0 commit comments

Comments
 (0)