@@ -30,26 +30,37 @@ import java.util.function.Supplier
3030class ClientPlayerAPI (api : SpotifyAPI ) : SpotifyEndpoint(api) {
3131 fun getDevices (): SpotifyRestAction <List <Device >> {
3232 return toAction(Supplier {
33- get(EndpointBuilder (" /me/player/devices" ).toString()).toInnerObject(" devices" , api, Device ::class .java)
33+ get(EndpointBuilder (" /me/player/devices" ).toString()).toInnerObject(
34+ " devices" ,
35+ api,
36+ mutableListOf<Device >().javaClass
37+ ).toList()
3438 })
3539 }
3640
3741 fun getCurrentContext (): SpotifyRestAction <CurrentlyPlayingContext ?> {
3842 return toAction(Supplier {
39- val obj: CurrentlyPlayingContext ? = get(EndpointBuilder (" /me/player" ).toString()).toObject(api, CurrentlyPlayingContext ::class .java)
43+ val obj: CurrentlyPlayingContext ? =
44+ get(EndpointBuilder (" /me/player" ).toString()).toObject(api, CurrentlyPlayingContext ::class .java)
4045 if (obj?.timestamp == null ) null else obj
4146 })
4247 }
4348
4449 fun getRecentlyPlayed (): SpotifyRestPagingAction <PlayHistory , CursorBasedPagingObject <PlayHistory >> {
4550 return toPagingObjectAction(Supplier {
46- get(EndpointBuilder (" /me/player/recently-played" ).toString()).toCursorBasedPagingObject(endpoint = this , tClazz = PlayHistory ::class .java)
51+ get(EndpointBuilder (" /me/player/recently-played" ).toString()).toCursorBasedPagingObject(
52+ endpoint = this ,
53+ tClazz = PlayHistory ::class .java
54+ )
4755 })
4856 }
4957
5058 fun getCurrentlyPlaying (): SpotifyRestAction <CurrentlyPlayingObject ?> {
5159 return toAction(Supplier {
52- val obj: CurrentlyPlayingObject ? = get(EndpointBuilder (" /me/player/currently-playing" ).toString()).toObject(api, CurrentlyPlayingObject ::class .java)
60+ val obj: CurrentlyPlayingObject ? = get(EndpointBuilder (" /me/player/currently-playing" ).toString()).toObject(
61+ api,
62+ CurrentlyPlayingObject ::class .java
63+ )
5364 if (obj?.timestamp == null ) null else obj
5465 })
5566 }
@@ -64,22 +75,37 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
6475 fun seekPosition (positionMs : Long , deviceId : String? = null): SpotifyRestAction <Unit > {
6576 return toAction(Supplier {
6677 if (positionMs < 0 ) throw IllegalArgumentException (" Position must not be negative!" )
67- put(EndpointBuilder (" /me/player/seek" ).with (" position_ms" , positionMs).with (" device_id" , deviceId).toString())
78+ put(
79+ EndpointBuilder (" /me/player/seek" ).with (" position_ms" , positionMs).with (
80+ " device_id" ,
81+ deviceId
82+ ).toString()
83+ )
6884 Unit
6985 })
7086 }
7187
7288 fun setRepeatMode (state : PlayerRepeatState , deviceId : String? = null): SpotifyRestAction <Unit > {
7389 return toAction(Supplier {
74- put(EndpointBuilder (" /me/player/repeat" ).with (" state" , state.toString().toLowerCase()).with (" device_id" , deviceId).toString())
90+ put(
91+ EndpointBuilder (" /me/player/repeat" ).with (" state" , state.toString().toLowerCase()).with (
92+ " device_id" ,
93+ deviceId
94+ ).toString()
95+ )
7596 Unit
7697 })
7798 }
7899
79100 fun setVolume (volume : Int , deviceId : String? = null): SpotifyRestAction <Unit > {
80101 if (volume !in 0 .. 100 ) throw IllegalArgumentException (" Volume must be within 0 to 100 inclusive. Provided: $volume " )
81102 return toAction(Supplier {
82- put(EndpointBuilder (" /me/player/volume" ).with (" volume_percent" , volume).with (" device_id" , deviceId).toString())
103+ put(
104+ EndpointBuilder (" /me/player/volume" ).with (" volume_percent" , volume).with (
105+ " device_id" ,
106+ deviceId
107+ ).toString()
108+ )
83109 Unit
84110 })
85111 }
@@ -162,8 +188,10 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
162188 fun transferPlayback (vararg deviceId : String , play : Boolean = true): SpotifyRestAction <Unit > {
163189 if (deviceId.size > 1 ) throw IllegalArgumentException (" Although an array is accepted, only a single device_id is currently supported. Supplying more than one will 400 Bad Request" )
164190 return toAction(Supplier {
165- put(EndpointBuilder (" /me/player" ).with (" device_ids" , deviceId.joinToString(" ," ) { it.encode() })
166- .with (" play" , play).toString())
191+ put(
192+ EndpointBuilder (" /me/player" ).with (" device_ids" , deviceId.joinToString(" ," ) { it.encode() })
193+ .with (" play" , play).toString()
194+ )
167195 Unit
168196 })
169197 }
0 commit comments