@@ -65,8 +65,8 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
65
65
fun isFollowingPlaylist (playlistId : String ): SpotifyRestAction <Boolean > {
66
66
return toAction {
67
67
isFollowingPlaylist(
68
- playlistId,
69
- (api as SpotifyClientApi ).userId
68
+ playlistId,
69
+ (api as SpotifyClientApi ).userId
70
70
).complete()
71
71
}
72
72
}
@@ -86,8 +86,8 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
86
86
fun isFollowingUsers (vararg users : String ): SpotifyRestAction <List <Boolean >> {
87
87
return toAction {
88
88
get(
89
- EndpointBuilder (" /me/following/contains" ).with (" type" , " user" )
90
- .with (" ids" , users.joinToString(" ," ) { UserUri (it).id.encodeUrl() }).toString()
89
+ EndpointBuilder (" /me/following/contains" ).with (" type" , " user" )
90
+ .with (" ids" , users.joinToString(" ," ) { UserUri (it).id.encodeUrl() }).toString()
91
91
).toList(Boolean .serializer().list, api, json)
92
92
}
93
93
}
@@ -125,8 +125,8 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
125
125
fun isFollowingArtists (vararg artists : String ): SpotifyRestAction <List <Boolean >> {
126
126
return toAction {
127
127
get(
128
- EndpointBuilder (" /me/following/contains" ).with (" type" , " artist" )
129
- .with (" ids" , artists.joinToString(" ," ) { ArtistUri (it).id.encodeUrl() }).toString()
128
+ EndpointBuilder (" /me/following/contains" ).with (" type" , " artist" )
129
+ .with (" ids" , artists.joinToString(" ," ) { ArtistUri (it).id.encodeUrl() }).toString()
130
130
).toList(Boolean .serializer().list, api, json)
131
131
}
132
132
}
@@ -138,22 +138,22 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
138
138
*
139
139
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/follow/get-followed/)**
140
140
*
141
- * @param limit The maximum number of items to return. Default: 20 . Minimum: 1. Maximum: 50.
141
+ * @param limit The maximum number of items to return. Default: 50 (or api limit) . Minimum: 1. Maximum: 50.
142
142
* @param after The last artist ID retrieved from the previous request.
143
143
*
144
144
* @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)
145
145
* with full [Artist] objects
146
146
*/
147
147
fun getFollowedArtists (
148
- limit : Int? = null ,
148
+ limit : Int? = api.defaultLimit ,
149
149
after : String? = null
150
150
): SpotifyRestActionPaging <Artist , CursorBasedPagingObject <Artist >> {
151
151
return toActionPaging {
152
152
get(
153
- EndpointBuilder (" /me/following" ).with (" type" , " artist" ).with (" limit" , limit).with (
154
- " after" ,
155
- after
156
- ).toString()
153
+ EndpointBuilder (" /me/following" ).with (" type" , " artist" ).with (" limit" , limit).with (
154
+ " after" ,
155
+ after
156
+ ).toString()
157
157
).toCursorBasedPagingObject(Artist .serializer(), " artists" , this , json)
158
158
}
159
159
}
@@ -180,14 +180,19 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
180
180
*
181
181
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/follow/follow-artists-users/)**
182
182
*
183
+ * @param users User ids or uris. Maximum **50**.
184
+ *
183
185
* @throws BadRequestException if an invalid id is provided
184
186
*/
185
187
fun followUsers (vararg users : String ): SpotifyRestAction <Unit > {
188
+ if (users.size > 50 && ! api.allowBulkRequests) throw BadRequestException (" Too many users (${users.size} ) provided, only 50 allowed" , IllegalArgumentException (" Bulk requests are not turned on, and too many users were provided" ))
186
189
return toAction {
187
- put(
188
- EndpointBuilder (" /me/following" ).with (" type" , " user" )
189
- .with (" ids" , users.joinToString(" ," ) { UserUri (it).id.encodeUrl() }).toString()
190
- )
190
+ users.toList().chunked(50 ).forEach { list ->
191
+ put(
192
+ EndpointBuilder (" /me/following" ).with (" type" , " user" )
193
+ .with (" ids" , list.joinToString(" ," ) { UserUri (it).id.encodeUrl() }).toString()
194
+ )
195
+ }
191
196
Unit
192
197
}
193
198
}
@@ -214,14 +219,19 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
214
219
*
215
220
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/follow/follow-artists-users/)**
216
221
*
222
+ * @param artists User ids or uris. Maximum **50**.
223
+ *
217
224
* @throws BadRequestException if an invalid id is provided
218
225
*/
219
226
fun followArtists (vararg artists : String ): SpotifyRestAction <Unit > {
227
+ if (artists.size > 50 && ! api.allowBulkRequests) throw BadRequestException (" Too many artists (${artists.size} ) provided, only 50 allowed" , IllegalArgumentException (" Bulk requests are not turned on, and too many artists were provided" ))
220
228
return toAction {
221
- put(
222
- EndpointBuilder (" /me/following" ).with (" type" , " artist" )
223
- .with (" ids" , artists.joinToString(" ," ) { ArtistUri (it).id.encodeUrl() }).toString()
224
- )
229
+ artists.toList().chunked(50 ).forEach { list ->
230
+ put(
231
+ EndpointBuilder (" /me/following" ).with (" type" , " artist" )
232
+ .with (" ids" , list.joinToString(" ," ) { ArtistUri (it).id.encodeUrl() }).toString()
233
+ )
234
+ }
225
235
Unit
226
236
}
227
237
}
@@ -248,8 +258,8 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
248
258
fun followPlaylist (playlist : String , followPublicly : Boolean = true): SpotifyRestAction <Unit > {
249
259
return toAction {
250
260
put(
251
- EndpointBuilder (" /playlists/${PlaylistUri (playlist).id} /followers" ).toString(),
252
- " {\" public\" : $followPublicly }"
261
+ EndpointBuilder (" /playlists/${PlaylistUri (playlist).id} /followers" ).toString(),
262
+ " {\" public\" : $followPublicly }"
253
263
)
254
264
Unit
255
265
}
@@ -279,16 +289,19 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
279
289
*
280
290
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/)**
281
291
*
282
- * @param users The users to be unfollowed from
292
+ * @param users The users to be unfollowed from. Maximum **50**.
283
293
*
284
294
* @throws BadRequestException if an invalid id is provided
285
295
*/
286
296
fun unfollowUsers (vararg users : String ): SpotifyRestAction <Unit > {
297
+ if (users.size > 50 && ! api.allowBulkRequests) throw BadRequestException (" Too many users (${users.size} ) provided, only 50 allowed" , IllegalArgumentException (" Bulk requests are not turned on, and too many users were provided" ))
287
298
return toAction {
288
- delete(
289
- EndpointBuilder (" /me/following" ).with (" type" , " user" )
290
- .with (" ids" , users.joinToString(" ," ) { UserUri (it).id.encodeUrl() }).toString()
291
- )
299
+ users.toList().chunked(50 ).forEach { list ->
300
+ delete(
301
+ EndpointBuilder (" /me/following" ).with (" type" , " user" )
302
+ .with (" ids" , list.joinToString(" ," ) { UserUri (it).id.encodeUrl() }).toString()
303
+ )
304
+ }
292
305
Unit
293
306
}
294
307
}
@@ -317,16 +330,20 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
317
330
*
318
331
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/)**
319
332
*
320
- * @param artists The artists to be unfollowed from
333
+ * @param artists The artists to be unfollowed from. Maximum **50**.
334
+ *
321
335
*
322
336
* @throws BadRequestException if an invalid id is provided
323
337
*/
324
338
fun unfollowArtists (vararg artists : String ): SpotifyRestAction <Unit > {
339
+ if (artists.size > 50 && ! api.allowBulkRequests) throw BadRequestException (" Too many artists (${artists.size} ) provided, only 50 allowed" , IllegalArgumentException (" Bulk requests are not turned on, and too many artists were provided" ))
325
340
return toAction {
326
- delete(
327
- EndpointBuilder (" /me/following" ).with (" type" , " artist" )
328
- .with (" ids" , artists.joinToString(" ," ) { ArtistUri (it).id.encodeUrl() }).toString()
329
- )
341
+ artists.toList().chunked(50 ).forEach { list ->
342
+ delete(
343
+ EndpointBuilder (" /me/following" ).with (" type" , " artist" )
344
+ .with (" ids" , list.joinToString(" ," ) { ArtistUri (it).id.encodeUrl() }).toString()
345
+ )
346
+ }
330
347
Unit
331
348
}
332
349
}
0 commit comments