Skip to content

Commit 2e96603

Browse files
committed
add scope documentation to endpoints #87
1 parent 847e6c9 commit 2e96603

File tree

15 files changed

+332
-121
lines changed

15 files changed

+332
-121
lines changed

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientFollowingAPI.kt

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.endpoints.public.FollowingAPI
5-
import com.adamratzman.spotify.http.EndpointBuilder
6-
import com.adamratzman.spotify.http.encode
74
import com.adamratzman.spotify.SpotifyAPI
85
import com.adamratzman.spotify.SpotifyClientAPI
96
import com.adamratzman.spotify.SpotifyRestAction
107
import com.adamratzman.spotify.SpotifyRestActionPaging
8+
import com.adamratzman.spotify.SpotifyScope
9+
import com.adamratzman.spotify.endpoints.public.FollowingAPI
10+
import com.adamratzman.spotify.http.EndpointBuilder
11+
import com.adamratzman.spotify.http.encode
1112
import com.adamratzman.spotify.models.Artist
1213
import com.adamratzman.spotify.models.ArtistURI
1314
import com.adamratzman.spotify.models.CursorBasedPagingObject
@@ -22,11 +23,14 @@ import java.util.function.Supplier
2223
*/
2324
class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
2425
/**
25-
* Check to see if the current user is following another Spotify users.
26+
* Check to see if the current user is following another Spotify user.
27+
*
28+
* **Requires** the [SpotifyScope.USER_FOLLOW_READ] scope
2629
*
27-
* @param user user id or uri to check.
30+
* @param user The user id or uri to check.
2831
*
2932
* @throws BadRequestException if [user] is a non-existing id
33+
* @return Whether the current user is following [user]
3034
*/
3135
fun isFollowingUser(user: String): SpotifyRestAction<Boolean> {
3236
return toAction(Supplier {
@@ -35,14 +39,18 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
3539
}
3640

3741
/**
38-
* Check to see if the logged-in Spotify user is following the specified playlist.
42+
* Check to see if the current Spotify user is following the specified playlist.
43+
*
44+
* Checking if the user is privately following a playlist is only possible for the current user when
45+
* that user has granted access to the [SpotifyScope.PLAYLIST_READ_PRIVATE] scope.
3946
*
4047
* @param playlistOwner id or uri of the creator of the playlist
4148
* @param playlistId playlist id or uri
4249
*
43-
* @return booleans representing whether the user follows the playlist. User IDs **not** found will return false
50+
* @return Boolean representing whether the user follows the playlist
4451
*
4552
* @throws [BadRequestException] if the playlist is not found
53+
* @return Whether the current user is following [playlistId]
4654
*/
4755
fun isFollowingPlaylist(playlistOwner: String, playlistId: String): SpotifyRestAction<Boolean> {
4856
return toAction(Supplier {
@@ -57,9 +65,12 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
5765
/**
5866
* Check to see if the current user is following one or more other Spotify users.
5967
*
68+
* **Requires** the [SpotifyScope.USER_FOLLOW_READ] scope
69+
*
6070
* @param users List of the user Spotify IDs to check. Max 50
6171
*
6272
* @throws BadRequestException if [users] contains a non-existing id
73+
* @return A list of booleans corresponding to [users] of whether the current user is following that user
6374
*/
6475
fun isFollowingUsers(vararg users: String): SpotifyRestAction<List<Boolean>> {
6576
return toAction(Supplier {
@@ -73,9 +84,12 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
7384
/**
7485
* Check to see if the current user is following a Spotify artist.
7586
*
76-
* @param artist artist id to check.
87+
* **Requires** the [SpotifyScope.USER_FOLLOW_READ] scope
88+
*
89+
* @param artist The artist id to check.
7790
*
7891
* @throws BadRequestException if [artist] is a non-existing id
92+
* @return Whether the current user is following [artist]
7993
*/
8094
fun isFollowingArtist(artist: String): SpotifyRestAction<Boolean> {
8195
return toAction(Supplier {
@@ -86,9 +100,12 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
86100
/**
87101
* Check to see if the current user is following one or more artists.
88102
*
103+
* **Requires** the [SpotifyScope.USER_FOLLOW_READ] scope
104+
*
89105
* @param artists List of the artist ids or uris to check. Max 50
90106
*
91107
* @throws BadRequestException if [artists] contains a non-existing id
108+
* @return A list of booleans corresponding to [artists] of whether the current user is following that artist
92109
*/
93110
fun isFollowingArtists(vararg artists: String): SpotifyRestAction<List<Boolean>> {
94111
return toAction(Supplier {
@@ -102,6 +119,11 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
102119
/**
103120
* Get the current user’s followed artists.
104121
*
122+
* **Requires** the [SpotifyScope.USER_FOLLOW_READ] scope
123+
*
124+
* @param limit The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.
125+
* @param after The last artist ID retrieved from the previous request.
126+
*
105127
* @return [CursorBasedPagingObject] ([Information about them](https://github.com/adamint/spotify-web-api-kotlin/blob/master/README.md#the-benefits-of-linkedresults-pagingobjects-and-cursor-based-paging-objects)
106128
* with full [Artist] objects
107129
*/
@@ -122,6 +144,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
122144
/**
123145
* Add the current user as a follower of another user
124146
*
147+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
148+
*
125149
* @throws BadRequestException if an invalid id is provided
126150
*/
127151
fun followUser(user: String): SpotifyRestAction<Unit> {
@@ -133,6 +157,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
133157
/**
134158
* Add the current user as a follower of other users
135159
*
160+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
161+
*
136162
* @throws BadRequestException if an invalid id is provided
137163
*/
138164
fun followUsers(vararg users: String): SpotifyRestAction<Unit> {
@@ -148,6 +174,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
148174
/**
149175
* Add the current user as a follower of an artist
150176
*
177+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
178+
*
151179
* @throws BadRequestException if an invalid id is provided
152180
*/
153181
fun followArtist(artistId: String): SpotifyRestAction<Unit> {
@@ -159,6 +187,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
159187
/**
160188
* Add the current user as a follower of other artists
161189
*
190+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
191+
*
162192
* @throws BadRequestException if an invalid id is provided
163193
*/
164194
fun followArtists(vararg artists: String): SpotifyRestAction<Unit> {
@@ -174,6 +204,13 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
174204
/**
175205
* Add the current user as a follower of a playlist.
176206
*
207+
* Following a playlist publicly requires authorization of the [SpotifyScope.PLAYLIST_MODIFY_PUBLIC] scope;
208+
* following it privately requires the [SpotifyScope.PLAYLIST_MODIFY_PRIVATE] scope.
209+
*
210+
* Note that the scopes you provide determine only whether the current user can themselves follow the playlist
211+
* publicly or privately (i.e. show others what they are following), not whether the playlist itself is
212+
* public or private.
213+
*
177214
* @param playlist the spotify id or uri of the playlist. Any playlist can be followed, regardless of its
178215
* public/private status, as long as you know its playlist ID.
179216
* @param followPublicly Defaults to true. If true the playlist will be included in user’s public playlists,
@@ -194,6 +231,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
194231
/**
195232
* Remove the current user as a follower of another user
196233
*
234+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
235+
*
197236
* @param user The user to be unfollowed from
198237
*
199238
* @throws BadRequestException if [user] is not found
@@ -207,6 +246,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
207246
/**
208247
* Remove the current user as a follower of other users
209248
*
249+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
250+
*
210251
* @param users The users to be unfollowed from
211252
*
212253
* @throws BadRequestException if an invalid id is provided
@@ -224,6 +265,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
224265
/**
225266
* Remove the current user as a follower of an artist
226267
*
268+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
269+
*
227270
* @param artist The artist to be unfollowed from
228271
*
229272
* @throws BadRequestException if an invalid id is provided
@@ -237,6 +280,8 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
237280
/**
238281
* Remove the current user as a follower of artists
239282
*
283+
* **Requires** the [SpotifyScope.USER_FOLLOW_MODIFY] scope
284+
*
240285
* @param artists The artists to be unfollowed from
241286
*
242287
* @throws BadRequestException if an invalid id is provided
@@ -254,7 +299,13 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
254299
/**
255300
* Remove the current user as a follower of a playlist.
256301
*
257-
* @param playlist the spotify id or uri of the playlist that is to be no longer followed.
302+
* Unfollowing a publicly followed playlist for a user requires authorization of the [SpotifyScope.PLAYLIST_MODIFY_PUBLIC] scope;
303+
* unfollowing a privately followed playlist requires the [SpotifyScope.PLAYLIST_MODIFY_PRIVATE] scope.
304+
*
305+
* Note that the scopes you provide relate only to whether the current user is following the playlist publicly or
306+
* privately (i.e. showing others what they are following), not whether the playlist itself is public or private.
307+
*
308+
* @param playlist The spotify id or uri of the playlist that is to be no longer followed.
258309
*
259310
* @throws BadRequestException if the playlist is not found
260311
*/

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientLibraryAPI.kt

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package com.adamratzman.spotify.endpoints.client
44
import com.adamratzman.spotify.SpotifyAPI
55
import com.adamratzman.spotify.SpotifyRestAction
66
import com.adamratzman.spotify.SpotifyRestActionPaging
7+
import com.adamratzman.spotify.SpotifyScope
78
import com.adamratzman.spotify.http.EndpointBuilder
89
import com.adamratzman.spotify.http.SpotifyEndpoint
910
import com.adamratzman.spotify.http.encode
@@ -24,12 +25,14 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
2425
/**
2526
* Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library.
2627
*
28+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
29+
*
2730
* @param limit The number of objects to return. Default: 20. Minimum: 1. Maximum: 50.
2831
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
2932
* @param market Provide this parameter if you want the list of returned items to be relevant to a particular country.
3033
* If omitted, the returned items will be relevant to all countries.
3134
*
32-
* @return Paging Object of [SavedTrack] ordered by position in library
35+
* @return [PagingObject] of [SavedTrack] ordered by position in library
3336
*/
3437
fun getSavedTracks(
3538
limit: Int? = null,
@@ -47,6 +50,8 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
4750
/**
4851
* Get a list of the albums saved in the current Spotify user’s ‘Your Music’ library.
4952
*
53+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
54+
*
5055
* @param limit The number of objects to return. Default: 20. Minimum: 1. Maximum: 50.
5156
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
5257
* @param market Provide this parameter if you want the list of returned items to be relevant to a particular country.
@@ -70,8 +75,10 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
7075
/**
7176
* Check if the [LibraryType] with id [id] is already saved in the current Spotify user’s ‘Your Music’ library.
7277
*
73-
* @param type the type of object (album or track)
74-
* @param id the spotify id or uri of the object
78+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
79+
*
80+
* @param type The type of object (album or track)
81+
* @param id The spotify id or uri of the object
7582
*
7683
* @throws BadRequestException if [id] is not found
7784
*/
@@ -84,8 +91,10 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
8491
/**
8592
* Check if one or more of [LibraryType] is already saved in the current Spotify user’s ‘Your Music’ library.
8693
*
87-
* @param type the type of objects (album or track)
88-
* @param ids the spotify ids or uris of the objects
94+
* **Requires** the [SpotifyScope.USER_LIBRARY_READ] scope
95+
*
96+
* @param type The type of objects (album or track)
97+
* @param ids The spotify ids or uris of the objects
8998
*
9099
* @throws BadRequestException if any of the provided ids is invalid
91100
*/
@@ -101,8 +110,10 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
101110
/**
102111
* Save one of [LibraryType] to the current user’s ‘Your Music’ library.
103112
*
104-
* @param type the type of object (album or track)
105-
* @param id the spotify id or uri of the object
113+
* **Requires** the [SpotifyScope.USER_LIBRARY_MODIFY] scope
114+
*
115+
* @param type The type of object (album or track)
116+
* @param id The spotify id or uri of the object
106117
*
107118
* @throws BadRequestException if the id is invalid
108119
*/
@@ -115,8 +126,10 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
115126
/**
116127
* Save one or more of [LibraryType] to the current user’s ‘Your Music’ library.
117128
*
118-
* @param type the type of objects to check against (album or track)
119-
* @param ids the spotify ids or uris of the objects
129+
* **Requires** the [SpotifyScope.USER_LIBRARY_MODIFY] scope
130+
*
131+
* @param type The type of objects to check against (album or track)
132+
* @param ids The spotify ids or uris of the objects
120133
*
121134
* @throws BadRequestException if any of the provided ids is invalid
122135
*/
@@ -130,8 +143,12 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
130143
/**
131144
* Remove one of [LibraryType] (track or album) from the current user’s ‘Your Music’ library.
132145
*
133-
* @param type the type of object to check against (album or track)
134-
* @param id the spotify id or uri of the object
146+
* Changes to a user’s saved items may not be visible in other Spotify applications immediately.
147+
*
148+
* **Requires** the [SpotifyScope.USER_LIBRARY_MODIFY] scope
149+
*
150+
* @param type The type of object to check against (album or track)
151+
* @param id The spotify id or uri of the object
135152
*
136153
* @throws BadRequestException if any of the provided ids is invalid
137154
*/
@@ -144,8 +161,12 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
144161
/**
145162
* Remove one or more of the [LibraryType] (tracks or albums) from the current user’s ‘Your Music’ library.
146163
*
147-
* @param type the type of objects to check against (album or track)
148-
* @param ids the spotify ids or uris of the objects
164+
* Changes to a user’s saved items may not be visible in other Spotify applications immediately.
165+
166+
* **Requires** the [SpotifyScope.USER_LIBRARY_MODIFY] scope
167+
*
168+
* @param type The type of objects to check against (album or track)
169+
* @param ids The spotify ids or uris of the objects
149170
*
150171
* @throws BadRequestException if any of the provided ids is invalid
151172
*/
@@ -161,7 +182,7 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
161182
* Type of object in a user's Spotify library
162183
*
163184
* @param value Spotify id for the type
164-
* @param id how to transform an id (or uri) input into its Spotify id
185+
* @param id How to transform an id (or uri) input into its Spotify id
165186
*/
166187
enum class LibraryType(private val value: String, internal val id: (String) -> String) {
167188
TRACK("tracks", { TrackURI(it).id }), ALBUM("albums", { AlbumURI(it).id });

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPersonalizationAPI.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.http.EndpointBuilder
5-
import com.adamratzman.spotify.http.SpotifyEndpoint
64
import com.adamratzman.spotify.SpotifyAPI
75
import com.adamratzman.spotify.SpotifyRestActionPaging
6+
import com.adamratzman.spotify.SpotifyScope
7+
import com.adamratzman.spotify.http.EndpointBuilder
8+
import com.adamratzman.spotify.http.SpotifyEndpoint
89
import com.adamratzman.spotify.models.Artist
910
import com.adamratzman.spotify.models.PagingObject
1011
import com.adamratzman.spotify.models.Track
@@ -28,6 +29,7 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
2829

2930
/**
3031
* Get the current user’s top artists based on calculated affinity.
32+
*
3133
* Affinity is a measure of the expected preference a user has for a particular track or artist. It is based on user
3234
* behavior, including play history, but does not include actions made while in incognito mode. Light or infrequent
3335
* users of Spotify may not have sufficient play history to generate a full affinity data set. As a user’s behavior
@@ -36,9 +38,11 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
3638
* for each user. In the future, it is likely that this restriction will be relaxed. This data is typically updated
3739
* once each day for each user.
3840
*
41+
* **Requires** the [SpotifyScope.USER_TOP_READ] scope
42+
*
3943
* @param limit The number of objects to return. Default: 20. Minimum: 1. Maximum: 50.
4044
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
41-
* @param timeRange the time range to which to compute this. The default is [TimeRange.MEDIUM_TERM]
45+
* @param timeRange The time range to which to compute this. The default is [TimeRange.MEDIUM_TERM]
4246
*
4347
* @return [PagingObject] of full [Artist] objects sorted by affinity
4448
*/
@@ -58,6 +62,7 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5862

5963
/**
6064
* Get the current user’s top tracks based on calculated affinity.
65+
*
6166
* Affinity is a measure of the expected preference a user has for a particular track or artist. It is based on user
6267
* behavior, including play history, but does not include actions made while in incognito mode. Light or infrequent
6368
* users of Spotify may not have sufficient play history to generate a full affinity data set. As a user’s behavior
@@ -66,9 +71,11 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6671
* for each user. In the future, it is likely that this restriction will be relaxed. This data is typically updated
6772
* once each day for each user.
6873
*
74+
* **Requires** the [SpotifyScope.USER_TOP_READ] scope
75+
*
6976
* @param limit The number of objects to return. Default: 20. Minimum: 1. Maximum: 50.
7077
* @param offset The index of the first item to return. Default: 0. Use with limit to get the next set of items
71-
* @param timeRange the time range to which to compute this. The default is [TimeRange.MEDIUM_TERM]
78+
* @param timeRange The time range to which to compute this. The default is [TimeRange.MEDIUM_TERM]
7279
*
7380
* @return [PagingObject] of full [Track] objects sorted by affinity
7481
*/

0 commit comments

Comments
 (0)