Skip to content

Commit 1f86c1c

Browse files
committed
add ClientPersonalizationApi and ClientProfileApi samples
1 parent a73a6fe commit 1f86c1c

File tree

7 files changed

+21
-7
lines changed

7 files changed

+21
-7
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ fun main() {
2626
// get all followed artists, limiting 1 each request
2727
println(api.following.getFollowedArtists(limit = 1).getAllItems().complete().map { it.name })
2828

29-
3029
// follow and unfollow, if you weren't previously following, the artist Louane
3130

3231
val isFollowingLouane = api.following.isFollowingArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete()
@@ -36,7 +35,6 @@ fun main() {
3635

3736
if (!isFollowingLouane) api.following.unfollowArtist("spotify:artist:7wjeXCtRND2ZdKfMJFu6JC").complete()
3837

39-
4038
// follow and unfollow, if you weren't previously following, the user adamratzman1
4139

4240
val isFollowingAdam = api.following.isFollowingUser("adamratzman1").complete()
@@ -46,7 +44,6 @@ fun main() {
4644

4745
if (!isFollowingAdam) api.following.unfollowUser("adamratzman1").complete()
4846

49-
5047
// follow and unfollow, if you weren't previously following, the playlist Today's Top Hits
5148

5249
val isFollowingTodaysTopHits = api.following.isFollowingPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
@@ -55,5 +52,4 @@ fun main() {
5552
api.following.followPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
5653

5754
if (!isFollowingTodaysTopHits) api.following.unfollowPlaylist("spotify:playlist:37i9dQZF1DXcBWIGoYBM5M").complete()
58-
5955
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ fun main() {
1515
}
1616
}.build()
1717

18-
1918
// get all your saved tracks
2019
println(api.library.getSavedTracks(limit = 50).getAllItems().complete().map { it.track.name })
2120

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

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

44
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
5+
import com.adamratzman.spotify.endpoints.client.ClientPersonalizationApi.TimeRange.LONG_TERM
6+
import com.adamratzman.spotify.endpoints.client.ClientPersonalizationApi.TimeRange.SHORT_TERM
57

68
fun main() {
79
// instantiate api
@@ -14,4 +16,9 @@ fun main() {
1416
}
1517
}.build()
1618

19+
// print your top 30 artists over the last few years
20+
println(api.personalization.getTopArtists(30, timeRange = LONG_TERM).complete().items.map { it.name })
21+
22+
// print your top 20 tracks in the last 4 weeks
23+
println(api.personalization.getTopTracks(timeRange = SHORT_TERM).complete().items.map { track -> "${track.name} by ${track.artists.joinToString(", ") { it.name }}" })
1724
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ fun main() {
1313
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
1414
}
1515
}.build()
16-
1716
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ fun main() {
1313
tokenString = System.getenv("SPOTIFY_TOKEN_STRING")
1414
}
1515
}.build()
16-
1716
}

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

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

17+
// get and print your follower count and, if the associated scope has been authorized, the user's birthday
18+
val profile = api.users.getClientProfile().complete()
19+
20+
println("${profile.followers.total} | ${profile.birthdate}")
1721
}

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientPersonalizationApi.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@ class ClientPersonalizationApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
2828
* @param id the Spotify id of the time frame
2929
*/
3030
enum class TimeRange(val id: String) {
31+
/**
32+
* Calculated from several years of data and including all new data as it becomes available
33+
*/
3134
LONG_TERM("long_term"),
35+
/**
36+
* Approximately last 6 months
37+
*/
3238
MEDIUM_TERM("medium_term"),
39+
40+
/**
41+
* Approximately last 4 weeks
42+
*/
3343
SHORT_TERM("short_term");
3444

3545
override fun toString() = id

0 commit comments

Comments
 (0)