@@ -5,7 +5,7 @@ import com.adamratzman.spotify.endpoints.public.FollowingAPI
55import com.adamratzman.spotify.main.SpotifyAPI
66import com.adamratzman.spotify.main.SpotifyClientAPI
77import com.adamratzman.spotify.main.SpotifyRestAction
8- import com.adamratzman.spotify.main.SpotifyRestPagingAction
8+ import com.adamratzman.spotify.main.SpotifyRestActionPaging
99import com.adamratzman.spotify.utils.Artist
1010import com.adamratzman.spotify.utils.ArtistURI
1111import com.adamratzman.spotify.utils.CursorBasedPagingObject
@@ -14,8 +14,8 @@ import com.adamratzman.spotify.utils.PlaylistURI
1414import com.adamratzman.spotify.utils.SpotifyPublicUser
1515import com.adamratzman.spotify.utils.UserURI
1616import com.adamratzman.spotify.utils.encode
17+ import com.adamratzman.spotify.utils.toArray
1718import com.adamratzman.spotify.utils.toCursorBasedPagingObject
18- import com.adamratzman.spotify.utils.toObject
1919import java.util.function.Supplier
2020
2121/* *
@@ -46,7 +46,13 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
4646 * @throws [BadRequestException] if the playlist is not found
4747 */
4848 fun isFollowingPlaylist (playlistOwner : String , playlistId : String ): SpotifyRestAction <Boolean > {
49- return toAction(Supplier { isFollowingPlaylist(playlistOwner, playlistId, (api as SpotifyClientAPI ).userId).complete() })
49+ return toAction(Supplier {
50+ isFollowingPlaylist(
51+ playlistOwner,
52+ playlistId,
53+ (api as SpotifyClientAPI ).userId
54+ ).complete()
55+ })
5056 }
5157
5258 /* *
@@ -58,8 +64,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
5864 */
5965 fun isFollowingUsers (vararg users : String ): SpotifyRestAction <List <Boolean >> {
6066 return toAction(Supplier {
61- get(EndpointBuilder (" /me/following/contains" ).with (" type" , " user" )
62- .with (" ids" , users.joinToString(" ," ) { UserURI (it).id.encode() }).toString()).toObject(api, mutableListOf<Boolean >().javaClass).toList()
67+ get(
68+ EndpointBuilder (" /me/following/contains" ).with (" type" , " user" )
69+ .with (" ids" , users.joinToString(" ," ) { UserURI (it).id.encode() }).toString()
70+ ).toArray<Boolean >(api)
6371 })
6472 }
6573
@@ -85,8 +93,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
8593 */
8694 fun isFollowingArtists (vararg artists : String ): SpotifyRestAction <List <Boolean >> {
8795 return toAction(Supplier {
88- get(EndpointBuilder (" /me/following/contains" ).with (" type" , " artist" )
89- .with (" ids" , artists.joinToString(" ," ) { ArtistURI (it).id.encode() }).toString()).toObject(api, mutableListOf<Boolean >().javaClass).toList()
96+ get(
97+ EndpointBuilder (" /me/following/contains" ).with (" type" , " artist" )
98+ .with (" ids" , artists.joinToString(" ," ) { ArtistURI (it).id.encode() }).toString()
99+ ).toArray<Boolean >(api)
90100 })
91101 }
92102
@@ -96,14 +106,22 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
96106 * @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)
97107 * with full [Artist] objects
98108 */
99- fun getFollowedArtists (limit : Int? = null, after : String? = null): SpotifyRestPagingAction <Artist , CursorBasedPagingObject <Artist >> {
100- return toPagingObjectAction(Supplier {
101- get(EndpointBuilder (" /me/following" ).with (" type" , " artist" ).with (" limit" , limit).with (" after" , after).toString())
102- .toCursorBasedPagingObject(" artists" , this , Artist ::class .java)
109+ fun getFollowedArtists (
110+ limit : Int? = null,
111+ after : String? = null
112+ ): SpotifyRestActionPaging <Artist ,CursorBasedPagingObject <Artist >> {
113+ return toActionPaging(Supplier {
114+ get(
115+ EndpointBuilder (" /me/following" ).with (" type" , " artist" ).with (" limit" , limit).with (
116+ " after" ,
117+ after
118+ ).toString()
119+ ).toCursorBasedPagingObject<Artist >(" artists" , this )
103120 })
104121 }
105122
106- fun getFollowedUsers (): SpotifyRestAction <List <SpotifyPublicUser >> = throw NotImplementedError (" Though Spotify will implement this in the future, it is not currently supported." )
123+ fun getFollowedUsers (): SpotifyRestAction <List <SpotifyPublicUser >> =
124+ throw NotImplementedError (" Though Spotify will implement this in the future, it is not currently supported." )
107125
108126 /* *
109127 * Add the current user as a follower of another user
@@ -123,8 +141,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
123141 */
124142 fun followUsers (vararg users : String ): SpotifyRestAction <Unit > {
125143 return toAction(Supplier {
126- put(EndpointBuilder (" /me/following" ).with (" type" , " user" )
127- .with (" ids" , users.joinToString(" ," ) { UserURI (it).id.encode() }).toString())
144+ put(
145+ EndpointBuilder (" /me/following" ).with (" type" , " user" )
146+ .with (" ids" , users.joinToString(" ," ) { UserURI (it).id.encode() }).toString()
147+ )
128148 Unit
129149 })
130150 }
@@ -147,8 +167,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
147167 */
148168 fun followArtists (vararg artists : String ): SpotifyRestAction <Unit > {
149169 return toAction(Supplier {
150- put(EndpointBuilder (" /me/following" ).with (" type" , " artist" )
151- .with (" ids" , artists.joinToString(" ," ) { ArtistURI (it).id.encode() }).toString())
170+ put(
171+ EndpointBuilder (" /me/following" ).with (" type" , " artist" )
172+ .with (" ids" , artists.joinToString(" ," ) { ArtistURI (it).id.encode() }).toString()
173+ )
152174 Unit
153175 })
154176 }
@@ -165,7 +187,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
165187 */
166188 fun followPlaylist (playlist : String , followPublicly : Boolean = true): SpotifyRestAction <Unit > {
167189 return toAction(Supplier {
168- put(EndpointBuilder (" /playlists/${PlaylistURI (playlist).id} /followers" ).toString(), " {\" public\" : $followPublicly }" )
190+ put(
191+ EndpointBuilder (" /playlists/${PlaylistURI (playlist).id} /followers" ).toString(),
192+ " {\" public\" : $followPublicly }"
193+ )
169194 Unit
170195 })
171196 }
@@ -192,8 +217,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
192217 */
193218 fun unfollowUsers (vararg users : String ): SpotifyRestAction <Unit > {
194219 return toAction(Supplier {
195- delete(EndpointBuilder (" /me/following" ).with (" type" , " user" )
196- .with (" ids" , users.joinToString(" ," ) { UserURI (it).id.encode() }).toString())
220+ delete(
221+ EndpointBuilder (" /me/following" ).with (" type" , " user" )
222+ .with (" ids" , users.joinToString(" ," ) { UserURI (it).id.encode() }).toString()
223+ )
197224 Unit
198225 })
199226 }
@@ -220,8 +247,10 @@ class ClientFollowingAPI(api: SpotifyAPI) : FollowingAPI(api) {
220247 */
221248 fun unfollowArtists (vararg artists : String ): SpotifyRestAction <Unit > {
222249 return toAction(Supplier {
223- delete(EndpointBuilder (" /me/following" ).with (" type" , " artist" )
224- .with (" ids" , artists.joinToString(" ," ) { ArtistURI (it).id.encode() }).toString())
250+ delete(
251+ EndpointBuilder (" /me/following" ).with (" type" , " artist" )
252+ .with (" ids" , artists.joinToString(" ," ) { ArtistURI (it).id.encode() }).toString()
253+ )
225254 Unit
226255 })
227256 }
0 commit comments