@@ -8,38 +8,120 @@ import java.util.function.Supplier
88 * These endpoints allow you manage the artists, users and playlists that a Spotify user follows.
99 */
1010class UserFollowAPI (api : SpotifyAPI ) : SpotifyEndpoint(api) {
11- fun followingUsers (vararg userIds : String ): SpotifyRestAction <List <Boolean >> {
11+ /* *
12+ * Check to see if the current user is following another Spotify users.
13+ *
14+ * @param userId Spotify ID to check.
15+ *
16+ * @throws BadRequestException if [userId] is a non-existing id
17+ */
18+ fun isFollowingUser (userId : String ): SpotifyRestAction <Boolean > {
1219 return toAction(Supplier {
13- get( " https://api.spotify.com/v1/me/following/contains?type=user&ids= ${userIds.joinToString( " , " ) { it.encode() }} { it.encode() }} " ).toObject< List < Boolean >>(api)
20+ isFollowingUsers(userId).complete()[ 0 ]
1421 })
1522 }
1623
17- fun followingArtists (vararg userIds : String ): SpotifyRestAction <List <Boolean >> {
24+ /* *
25+ * Check to see if the current user is following one or more other Spotify users.
26+ *
27+ * @param userIds List of the user Spotify IDs to check. Max 50
28+ *
29+ * @throws BadRequestException if [userIds] contains a non-existing id
30+ */
31+ fun isFollowingUsers (vararg userIds : String ): SpotifyRestAction <List <Boolean >> {
1832 return toAction(Supplier {
19- get(" https://api.spotify.com/v1/me/following/contains?type=artist &ids=${userIds.joinToString(" ," ) { it.encode() }} " ).toObject<List <Boolean >>(api)
33+ get(" https://api.spotify.com/v1/me/following/contains?type=user &ids=${userIds.joinToString(" ," ) { it.encode() }} " ).toObject<List <Boolean >>(api)
2034 })
2135 }
2236
37+ /* *
38+ * Check to see if the current user is following a Spotify artist.
39+ *
40+ * @param artistId Spotify ID to check.
41+ *
42+ * @throws BadRequestException if [artistId] is a non-existing id
43+ */
44+ fun isFollowingArtist (artistId : String ): SpotifyRestAction <Boolean > {
45+ return toAction(Supplier {
46+ isFollowingArtists(artistId).complete()[0 ]
47+ })
48+ }
49+
50+ /* *
51+ * Check to see if the current user is following one or more artists.
52+ *
53+ * @param artistIds List of the artist Spotify IDs to check. Max 50
54+ *
55+ * @throws BadRequestException if [artistIds] contains a non-existing id
56+ */
57+ fun isFollowingArtists (vararg artistIds : String ): SpotifyRestAction <List <Boolean >> {
58+ return toAction(Supplier {
59+ get(" https://api.spotify.com/v1/me/following/contains?type=artist&ids=${artistIds.joinToString(" ," ) { it.encode() }} " ).toObject<List <Boolean >>(api)
60+ })
61+ }
62+
63+ /* *
64+ * Get the current user’s followed artists.
65+ *
66+ * @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)
67+ * with full [Artist] objects
68+ */
2369 fun getFollowedArtists (): SpotifyRestAction <CursorBasedPagingObject <Artist >> {
2470 return toAction(Supplier {
2571 get(" https://api.spotify.com/v1/me/following?type=artist" ).toCursorBasedPagingObject<Artist >(" artists" , api)
2672 })
2773 }
2874
75+ fun getFollowedUsers (): SpotifyRestAction <SpotifyPublicUser >
76+ = throw NotImplementedError (" Though Spotify will implement this in the future, it is not currently supported." )
77+
78+ /* *
79+ * Add the current user as a follower of another user
80+ *
81+ * @throws BadRequestException if an invalid id is provided
82+ */
83+ fun followUser (userId : String ): SpotifyRestAction <Unit > {
84+ return toAction(Supplier {
85+ followUsers(userId).complete()
86+ })
87+ }
88+
89+ /* *
90+ * Add the current user as a follower of other users
91+ *
92+ * @throws BadRequestException if an invalid id is provided
93+ */
2994 fun followUsers (vararg userIds : String ): SpotifyRestAction <Unit > {
3095 return toAction(Supplier {
3196 put(" https://api.spotify.com/v1/me/following?type=user&ids=${userIds.joinToString(" ," ) { it.encode() }} " )
3297 Unit
3398 })
3499 }
35100
101+ /* *
102+ * Add the current user as a follower of an artist
103+ *
104+ * @throws BadRequestException if an invalid id is provided
105+ */
106+ fun followArtist (artistId : String ): SpotifyRestAction <Unit > {
107+ return toAction(Supplier {
108+ followArtists(artistId).complete()
109+ })
110+ }
111+
112+ /* *
113+ * Add the current user as a follower of other artists
114+ *
115+ * @throws BadRequestException if an invalid id is provided
116+ */
36117 fun followArtists (vararg artistIds : String ): SpotifyRestAction <Unit > {
37118 return toAction(Supplier {
38119 put(" https://api.spotify.com/v1/me/following?type=artist&ids=${artistIds.joinToString(" ," )} " )
39120 Unit
40121 })
41122 }
42123
124+
43125 fun followPlaylist (ownerId : String , playlistId : String , followPublicly : Boolean = true): SpotifyRestAction <Unit > {
44126 return toAction(Supplier {
45127 put(" https://api.spotify.com/v1/users/$ownerId /playlists/$playlistId /followers" , " {\" public\" : $followPublicly }" )
0 commit comments