@@ -36,7 +36,10 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
36
36
* @throws BadRequestException if [user] is a non-existing id
37
37
* @return Whether the current user is following [user]
38
38
*/
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
+ }
40
43
41
44
/* *
42
45
* Check to see if the current user is following another Spotify user.
@@ -50,8 +53,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
50
53
* @throws BadRequestException if [user] is a non-existing id
51
54
* @return Whether the current user is following [user]
52
55
*/
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
+ }
55
59
56
60
/* *
57
61
* Check to see if the current Spotify user is following the specified playlist.
@@ -68,11 +72,12 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
68
72
* @throws [BadRequestException] if the playlist is not found
69
73
* @return Whether the current user is following [playlistId]
70
74
*/
71
- public suspend fun isFollowingPlaylist (playlistId : String ): Boolean =
72
- isFollowingPlaylist(
75
+ public suspend fun isFollowingPlaylist (playlistId : String ): Boolean {
76
+ return isFollowingPlaylist(
73
77
playlistId,
74
78
(api as SpotifyClientApi ).getUserId()
75
79
)
80
+ }
76
81
77
82
/* *
78
83
* Check to see if the current Spotify user is following the specified playlist.
@@ -105,6 +110,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
105
110
* @return A list of booleans corresponding to [users] of whether the current user is following that user
106
111
*/
107
112
public suspend fun isFollowingUsers (vararg users : String ): List <Boolean > {
113
+ requireScopes(SpotifyScope .USER_FOLLOW_READ )
108
114
checkBulkRequesting(50 , users.size)
109
115
return bulkRequest(50 , users.toList()) { chunk ->
110
116
get(
@@ -126,8 +132,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
126
132
* @throws BadRequestException if [users] contains a non-existing id
127
133
* @return A list of booleans corresponding to [users] of whether the current user is following that user
128
134
*/
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
+ }
131
138
132
139
/* *
133
140
* Check to see if the current user is following a Spotify artist.
@@ -155,8 +162,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
155
162
* @throws BadRequestException if [artist] is a non-existing id
156
163
* @return Whether the current user is following [artist]
157
164
*/
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
+ }
160
168
161
169
/* *
162
170
* Check to see if the current user is following one or more artists.
@@ -171,6 +179,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
171
179
* @return A list of booleans corresponding to [artists] of whether the current user is following that artist
172
180
*/
173
181
public suspend fun isFollowingArtists (vararg artists : String ): List <Boolean > {
182
+ requireScopes(SpotifyScope .USER_FOLLOW_READ )
174
183
checkBulkRequesting(50 , artists.size)
175
184
return bulkRequest(50 , artists.toList()) { chunk ->
176
185
get(
@@ -192,8 +201,9 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
192
201
* @throws BadRequestException if [artists] contains a non-existing id
193
202
* @return A list of booleans corresponding to [artists] of whether the current user is following that artist
194
203
*/
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
+ }
197
207
198
208
/* *
199
209
* Get the current user’s followed artists.
@@ -211,12 +221,15 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
211
221
public suspend fun getFollowedArtists (
212
222
limit : Int? = api.spotifyApiOptions.defaultLimit,
213
223
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
+ }
220
233
221
234
/* *
222
235
* Get the current user’s followed artists.
@@ -270,6 +283,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
270
283
* @throws BadRequestException if an invalid id is provided
271
284
*/
272
285
public suspend fun followUsers (vararg users : String ) {
286
+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
273
287
checkBulkRequesting(50 , users.size)
274
288
bulkRequest(50 , users.toList()) { chunk ->
275
289
put(
@@ -313,7 +327,8 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
313
327
*
314
328
* @throws BadRequestException if an invalid id is provided
315
329
*/
316
- public fun followArtistRestAction (artistId : String ): SpotifyRestAction <Unit > = SpotifyRestAction { followArtist(artistId) }
330
+ public fun followArtistRestAction (artistId : String ): SpotifyRestAction <Unit > =
331
+ SpotifyRestAction { followArtist(artistId) }
317
332
318
333
/* *
319
334
* Add the current user as a follower of other artists
@@ -327,6 +342,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
327
342
* @throws BadRequestException if an invalid id is provided
328
343
*/
329
344
public suspend fun followArtists (vararg artists : String ) {
345
+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
330
346
checkBulkRequesting(50 , artists.size)
331
347
bulkRequest(50 , artists.toList()) { chunk ->
332
348
put(
@@ -369,10 +385,14 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
369
385
*
370
386
* @throws BadRequestException if the playlist is not found
371
387
*/
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
+ }
376
396
377
397
/* *
378
398
* Add the current user as a follower of a playlist.
@@ -393,10 +413,13 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
393
413
*
394
414
* @throws BadRequestException if the playlist is not found
395
415
*/
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 {
398
420
followPlaylist(playlist, followPublicly)
399
421
}
422
+ }
400
423
401
424
/* *
402
425
* Remove the current user as a follower of another user
@@ -437,6 +460,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
437
460
* @throws BadRequestException if an invalid id is provided
438
461
*/
439
462
public suspend fun unfollowUsers (vararg users : String ) {
463
+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
440
464
checkBulkRequesting(50 , users.size)
441
465
bulkRequest(50 , users.toList()) { list ->
442
466
delete(
@@ -502,6 +526,7 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
502
526
* @throws BadRequestException if an invalid id is provided
503
527
*/
504
528
public suspend fun unfollowArtists (vararg artists : String ) {
529
+ requireScopes(SpotifyScope .USER_FOLLOW_MODIFY )
505
530
checkBulkRequesting(50 , artists.size)
506
531
bulkRequest(50 , artists.toList()) { list ->
507
532
delete(
@@ -542,8 +567,11 @@ public class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
542
567
*
543
568
* @throws BadRequestException if the playlist is not found
544
569
*/
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
+ }
547
575
548
576
/* *
549
577
* Remove the current user as a follower of a playlist.
0 commit comments