1
1
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2
2
package com.adamratzman.spotify.endpoints.client
3
3
4
- import com.adamratzman.spotify.SpotifyApi
4
+ import com.adamratzman.spotify.GenericSpotifyApi
5
5
import com.adamratzman.spotify.SpotifyException.BadRequestException
6
6
import com.adamratzman.spotify.SpotifyRestAction
7
7
import com.adamratzman.spotify.SpotifyRestActionPaging
@@ -36,7 +36,7 @@ typealias ClientPlayerAPI = ClientPlayerApi
36
36
*
37
37
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/player/)**
38
38
*/
39
- class ClientPlayerApi (api : SpotifyApi < * , * > ) : SpotifyEndpoint(api) {
39
+ class ClientPlayerApi (api : GenericSpotifyApi ) : SpotifyEndpoint(api) {
40
40
/* *
41
41
* Get information about a user’s available devices.
42
42
*
@@ -61,7 +61,7 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
61
61
return toAction {
62
62
val obj = catch {
63
63
get(EndpointBuilder (" /me/player" ).toString())
64
- .toObject(CurrentlyPlayingContext .serializer(), api, json)
64
+ .toObject(CurrentlyPlayingContext .serializer(), api, json)
65
65
}
66
66
if (obj?.timestamp == null ) null else obj
67
67
}
@@ -80,14 +80,14 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
80
80
*
81
81
*/
82
82
fun getRecentlyPlayed (
83
- limit : Int? = api.defaultLimit,
84
- before : String? = null,
85
- after : String? = null
83
+ limit : Int? = api.defaultLimit,
84
+ before : String? = null,
85
+ after : String? = null
86
86
): SpotifyRestActionPaging <PlayHistory , CursorBasedPagingObject <PlayHistory >> {
87
87
return toActionPaging {
88
88
get(
89
- EndpointBuilder (" /me/player/recently-played" )
90
- .with (" limit" , limit).with (" before" , before).with (" after" , after).toString()
89
+ EndpointBuilder (" /me/player/recently-played" )
90
+ .with (" limit" , limit).with (" before" , before).with (" after" , after).toString()
91
91
).toCursorBasedPagingObject(PlayHistory .serializer(), endpoint = this , json = json)
92
92
}
93
93
}
@@ -102,10 +102,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
102
102
fun getCurrentlyPlaying (): SpotifyRestAction <CurrentlyPlayingObject ?> {
103
103
return toAction {
104
104
val obj =
105
- catch {
106
- get(EndpointBuilder (" /me/player/currently-playing" ).toString())
107
- .toObject(CurrentlyPlayingObject .serializer(), api, json)
108
- }
105
+ catch {
106
+ get(EndpointBuilder (" /me/player/currently-playing" ).toString())
107
+ .toObject(CurrentlyPlayingObject .serializer(), api, json)
108
+ }
109
109
if (obj?.timestamp == null ) null else obj
110
110
}
111
111
}
@@ -141,10 +141,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
141
141
return toAction {
142
142
require(positionMs >= 0 ) { " Position must not be negative!" }
143
143
put(
144
- EndpointBuilder (" /me/player/seek" ).with (" position_ms" , positionMs).with (
145
- " device_id" ,
146
- deviceId
147
- ).toString()
144
+ EndpointBuilder (" /me/player/seek" ).with (" position_ms" , positionMs).with (
145
+ " device_id" ,
146
+ deviceId
147
+ ).toString()
148
148
)
149
149
Unit
150
150
}
@@ -163,10 +163,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
163
163
fun setRepeatMode (state : PlayerRepeatState , deviceId : String? = null): SpotifyRestAction <Unit > {
164
164
return toAction {
165
165
put(
166
- EndpointBuilder (" /me/player/repeat" ).with (" state" , state.toString().toLowerCase()).with (
167
- " device_id" ,
168
- deviceId
169
- ).toString()
166
+ EndpointBuilder (" /me/player/repeat" ).with (" state" , state.toString().toLowerCase()).with (
167
+ " device_id" ,
168
+ deviceId
169
+ ).toString()
170
170
)
171
171
Unit
172
172
}
@@ -186,10 +186,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
186
186
require(volume in 0 .. 100 ) { " Volume must be within 0 to 100 inclusive. Provided: $volume " }
187
187
return toAction {
188
188
put(
189
- EndpointBuilder (" /me/player/volume" ).with (" volume_percent" , volume).with (
190
- " device_id" ,
191
- deviceId
192
- ).toString()
189
+ EndpointBuilder (" /me/player/volume" ).with (" volume_percent" , volume).with (
190
+ " device_id" ,
191
+ deviceId
192
+ ).toString()
193
193
)
194
194
Unit
195
195
}
@@ -256,11 +256,11 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
256
256
* @throws BadRequestException if more than one type of play type is specified or the offset is illegal.
257
257
*/
258
258
fun startPlayback (
259
- collection : CollectionUri ? = null,
260
- offsetNum : Int? = null,
261
- offsetPlayable : PlayableUri ? = null,
262
- deviceId : String? = null,
263
- tracksToPlay : List <PlayableUri > = emptyList()
259
+ collection : CollectionUri ? = null,
260
+ offsetNum : Int? = null,
261
+ offsetPlayable : PlayableUri ? = null,
262
+ deviceId : String? = null,
263
+ tracksToPlay : List <PlayableUri > = emptyList()
264
264
): SpotifyRestAction <Unit > {
265
265
return toAction {
266
266
val url = EndpointBuilder (" /me/player/play" ).with (" device_id" , deviceId).toString()
@@ -269,7 +269,7 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
269
269
collection != null -> body + = json { " context_uri" to collection.uri }
270
270
tracksToPlay.isNotEmpty() -> body + = json {
271
271
" uris" to JsonArray (
272
- tracksToPlay.map { it.uri }.map(::JsonPrimitive )
272
+ tracksToPlay.map { it.uri }.map(::JsonPrimitive )
273
273
)
274
274
}
275
275
}
@@ -324,7 +324,7 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
324
324
*/
325
325
@SpotifyExperimentalFunctionApi
326
326
fun transferPlayback (deviceId : String , play : Boolean? = null): SpotifyRestAction <Unit > {
327
- // require(deviceId.size <= 1) { "Although an array is accepted, only a single device_id is currently supported. Supplying more than one will 400 Bad Request" }
327
+ // require(deviceId.size <= 1) { "Although an array is accepted, only a single device_id is currently supported. Supplying more than one will 400 Bad Request" }
328
328
return toAction {
329
329
val json = jsonMap()
330
330
play?.let { json + = json { " play" to it } }
@@ -344,10 +344,12 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
344
344
* Repeat the current track
345
345
*/
346
346
TRACK ,
347
+
347
348
/* *
348
349
* Repeat the current context
349
350
*/
350
351
CONTEXT ,
352
+
351
353
/* *
352
354
* Will turn repeat off
353
355
*/
0 commit comments