@@ -36,7 +36,10 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
3636 * @throws BadRequestException if [user] is a non-existing id
3737 * @return Whether the current user is following [user]
3838 */
39- public suspend fun isFollowingUser (user : String ): Boolean = isFollowingUsers(user)[0 ]
39+ public suspend fun isFollowingUser (user : String ): Boolean {
40+ requireScopes(SpotifyScope .USER_FOLLOW_READ )
41+ return isFollowingUsers(user)[0 ]
42+ }
4043
4144 /* *
4245 * Check to see if the current user is following another Spotify user.
@@ -50,8 +53,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
5053 * @throws BadRequestException if [user] is a non-existing id
5154 * @return Whether the current user is following [user]
5255 */
53- public fun isFollowingUserRestAction (user : String ): SpotifyRestAction <Boolean > =
54- SpotifyRestAction { isFollowingUser(user) }
56+ public fun isFollowingUserRestAction (user : String ): SpotifyRestAction <Boolean > {
57+ return SpotifyRestAction { isFollowingUser(user) }
58+ }
5559
5660 /* *
5761 * Check to see if the current Spotify user is following the specified playlist.
@@ -68,11 +72,12 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
6872 * @throws [BadRequestException] if the playlist is not found
6973 * @return Whether the current user is following [playlistId]
7074 */
71- public suspend fun isFollowingPlaylist (playlistId : String ): Boolean =
72- isFollowingPlaylist(
75+ public suspend fun isFollowingPlaylist (playlistId : String ): Boolean {
76+ return isFollowingPlaylist(
7377 playlistId,
7478 (api as SpotifyClientApi ).getUserId()
7579 )
80+ }
7681
7782 /* *
7883 * Check to see if the current Spotify user is following the specified playlist.
@@ -105,6 +110,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
105110 * @return A list of booleans corresponding to [users] of whether the current user is following that user
106111 */
107112 public suspend fun isFollowingUsers (vararg users : String ): List <Boolean > {
113+ requireScopes(SpotifyScope .USER_FOLLOW_READ )
108114 checkBulkRequesting(50 , users.size)
109115 return bulkRequest(50 , users.toList()) { chunk ->
110116 get(
@@ -126,8 +132,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
126132 * @throws BadRequestException if [users] contains a non-existing id
127133 * @return A list of booleans corresponding to [users] of whether the current user is following that user
128134 */
129- public fun isFollowingUsersRestAction (vararg users : String ): SpotifyRestAction <List <Boolean >> =
130- SpotifyRestAction { isFollowingUsers(* users) }
135+ public fun isFollowingUsersRestAction (vararg users : String ): SpotifyRestAction <List <Boolean >> {
136+ return SpotifyRestAction { isFollowingUsers(* users) }
137+ }
131138
132139 /* *
133140 * Check to see if the current user is following a Spotify artist.
@@ -155,8 +162,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
155162 * @throws BadRequestException if [artist] is a non-existing id
156163 * @return Whether the current user is following [artist]
157164 */
158- public fun isFollowingArtistRestAction (artist : String ): SpotifyRestAction <Boolean > =
159- SpotifyRestAction { isFollowingArtist(artist) }
165+ public fun isFollowingArtistRestAction (artist : String ): SpotifyRestAction <Boolean > {
166+ return SpotifyRestAction { isFollowingArtist(artist) }
167+ }
160168
161169 /* *
162170 * Check to see if the current user is following one or more artists.
@@ -171,6 +179,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
171179 * @return A list of booleans corresponding to [artists] of whether the current user is following that artist
172180 */
173181 public suspend fun isFollowingArtists (vararg artists : String ): List <Boolean > {
182+ requireScopes(SpotifyScope .USER_FOLLOW_READ )
174183 checkBulkRequesting(50 , artists.size)
175184 return bulkRequest(50 , artists.toList()) { chunk ->
176185 get(
@@ -192,8 +201,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
192201 * @throws BadRequestException if [artists] contains a non-existing id
193202 * @return A list of booleans corresponding to [artists] of whether the current user is following that artist
194203 */
195- public fun isFollowingArtistsRestAction (vararg artists : String ): SpotifyRestAction <List <Boolean >> =
196- SpotifyRestAction { isFollowingArtists(* artists) }
204+ public fun isFollowingArtistsRestAction (vararg artists : String ): SpotifyRestAction <List <Boolean >> {
205+ return SpotifyRestAction { isFollowingArtists(* artists) }
206+ }
197207
198208 /* *
199209 * Get the current user’s followed artists.
@@ -211,12 +221,15 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
211221 public suspend fun getFollowedArtists (
212222 limit : Int? = api.spotifyApiOptions.defaultLimit,
213223 after : String? = null
214- ): CursorBasedPagingObject <Artist > = get(
215- endpointBuilder(" /me/following" ).with (" type" , " artist" ).with (" limit" , limit).with (
216- " after" ,
217- after
218- ).toString()
219- ).toCursorBasedPagingObject(Artist ::class , Artist .serializer(), " artists" , api, json)
224+ ): CursorBasedPagingObject <Artist > {
225+ requireScopes(SpotifyScope .USER_FOLLOW_READ )
226+ return get(
227+ endpointBuilder(" /me/following" ).with (" type" , " artist" ).with (" limit" , limit).with (
228+ " after" ,
229+ after
230+ ).toString()
231+ ).toCursorBasedPagingObject(Artist ::class , Artist .serializer(), " artists" , api, json)
232+ }
220233
221234 /* *
222235 * Get the current user’s followed artists.
@@ -270,6 +283,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
270283 * @throws BadRequestException if an invalid id is provided
271284 */
272285 public suspend fun followUsers (vararg users : String ) {
286+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
273287 checkBulkRequesting(50 , users.size)
274288 bulkRequest(50 , users.toList()) { chunk ->
275289 put(
@@ -313,7 +327,8 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
313327 *
314328 * @throws BadRequestException if an invalid id is provided
315329 */
316- public fun followArtistRestAction (artistId : String ): SpotifyRestAction <Unit > = SpotifyRestAction { followArtist(artistId) }
330+ public fun followArtistRestAction (artistId : String ): SpotifyRestAction <Unit > =
331+ SpotifyRestAction { followArtist(artistId) }
317332
318333 /* *
319334 * Add the current user as a follower of other artists
@@ -327,6 +342,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
327342 * @throws BadRequestException if an invalid id is provided
328343 */
329344 public suspend fun followArtists (vararg artists : String ) {
345+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
330346 checkBulkRequesting(50 , artists.size)
331347 bulkRequest(50 , artists.toList()) { chunk ->
332348 put(
@@ -369,10 +385,14 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
369385 *
370386 * @throws BadRequestException if the playlist is not found
371387 */
372- public suspend fun followPlaylist (playlist : String , followPublicly : Boolean = true): String = put(
373- endpointBuilder(" /playlists/${PlaylistUri (playlist).id} /followers" ).toString(),
374- " {\" public\" : $followPublicly }"
375- )
388+ public suspend fun followPlaylist (playlist : String , followPublicly : Boolean = true): String {
389+ requireScopes(SpotifyScope .PLAYLIST_MODIFY_PUBLIC , SpotifyScope .PLAYLIST_MODIFY_PRIVATE , anyOf = true )
390+
391+ return put(
392+ endpointBuilder(" /playlists/${PlaylistUri (playlist).id} /followers" ).toString(),
393+ " {\" public\" : $followPublicly }"
394+ )
395+ }
376396
377397 /* *
378398 * Add the current user as a follower of a playlist.
@@ -393,10 +413,13 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
393413 *
394414 * @throws BadRequestException if the playlist is not found
395415 */
396- public fun followPlaylistRestAction (playlist : String , followPublicly : Boolean ): SpotifyRestAction <String > =
397- SpotifyRestAction {
416+ public fun followPlaylistRestAction (playlist : String , followPublicly : Boolean ): SpotifyRestAction <String > {
417+ requireScopes(SpotifyScope .PLAYLIST_MODIFY_PUBLIC , SpotifyScope .PLAYLIST_MODIFY_PRIVATE , anyOf = true )
418+
419+ return SpotifyRestAction {
398420 followPlaylist(playlist, followPublicly)
399421 }
422+ }
400423
401424 /* *
402425 * Remove the current user as a follower of another user
@@ -437,6 +460,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
437460 * @throws BadRequestException if an invalid id is provided
438461 */
439462 public suspend fun unfollowUsers (vararg users : String ) {
463+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
440464 checkBulkRequesting(50 , users.size)
441465 bulkRequest(50 , users.toList()) { list ->
442466 delete(
@@ -502,6 +526,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
502526 * @throws BadRequestException if an invalid id is provided
503527 */
504528 public suspend fun unfollowArtists (vararg artists : String ) {
529+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
505530 checkBulkRequesting(50 , artists.size)
506531 bulkRequest(50 , artists.toList()) { list ->
507532 delete(
@@ -542,8 +567,11 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
542567 *
543568 * @throws BadRequestException if the playlist is not found
544569 */
545- public suspend fun unfollowPlaylist (playlist : String ): String =
546- delete(endpointBuilder(" /playlists/${PlaylistUri (playlist).id} /followers" ).toString())
570+ public suspend fun unfollowPlaylist (playlist : String ): String {
571+ requireScopes(SpotifyScope .PLAYLIST_MODIFY_PUBLIC , SpotifyScope .PLAYLIST_MODIFY_PRIVATE , anyOf = true )
572+
573+ return delete(endpointBuilder(" /playlists/${PlaylistUri (playlist).id} /followers" ).toString())
574+ }
547575
548576 /* *
549577 * Remove the current user as a follower of a playlist.
0 commit comments