Skip to content

Commit b0d44bf

Browse files
committed
create typealias GenericSpotifyApi <-> SpotifyApi<*, *>
1 parent b1c4499 commit b0d44bf

25 files changed

+341
-335
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/Builder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class SpotifyApiBuilder(
319319
* Create a [SpotifyApi] instance with the given [SpotifyApiBuilder] parameters and the type -
320320
* [AuthorizationType.CLIENT] for client authentication, or otherwise [AuthorizationType.APPLICATION]
321321
*/
322-
fun build(type: AuthorizationType): SpotifyApi<*, *> {
322+
fun build(type: AuthorizationType): GenericSpotifyApi {
323323
return if (type == AuthorizationType.CLIENT) buildClient()
324324
else buildCredentialed()
325325
}

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ sealed class SpotifyApi<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>(
265265
* @param api The Spotify Api instance, or null if one doesn't exist yet
266266
* @param json The json instance that will deserialize the response. If [api] is not null, [SpotifyApi.json] can be used
267267
*/
268-
suspend fun getCredentialedToken(clientId: String, clientSecret: String, api: SpotifyApi<*, *>?, json: Json): Token {
268+
suspend fun getCredentialedToken(clientId: String, clientSecret: String, api: GenericSpotifyApi?, json: Json): Token {
269269
val response = executeTokenRequest(
270270
HttpConnection(
271271
"https://accounts.spotify.com/api/token",
@@ -418,7 +418,7 @@ open class SpotifyClientApi internal constructor(
418418
allowBulkRequests: Boolean,
419419
requestTimeoutMillis: Long?,
420420
json: Json,
421-
refreshTokenProducer: (suspend (SpotifyApi<*, *>) -> Token)?
421+
refreshTokenProducer: (suspend (GenericSpotifyApi) -> Token)?
422422
) : SpotifyApi<SpotifyClientApi, SpotifyClientApiBuilder>(
423423
clientId,
424424
clientSecret,
@@ -698,7 +698,7 @@ typealias GenericSpotifyApi = SpotifyApi<*, *>
698698
* @param json The json instance that will deserialize the response. If [api] is not null, [SpotifyApi.json] can be used
699699
*/
700700
@Deprecated("Moved", ReplaceWith("SpotifyApi.getCredentialedToken"))
701-
suspend fun getCredentialedToken(clientId: String, clientSecret: String, api: SpotifyApi<*, *>?, json: Json): Token = SpotifyApi.getCredentialedToken(clientId, clientSecret, api, json)
701+
suspend fun getCredentialedToken(clientId: String, clientSecret: String, api: GenericSpotifyApi?, json: Json): Token = SpotifyApi.getCredentialedToken(clientId, clientSecret, api, json)
702702

703703
internal suspend fun executeTokenRequest(
704704
httpConnection: HttpConnection,

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyRestAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import kotlinx.coroutines.withContext
2929
/**
3030
* Provides a uniform interface to retrieve, whether synchronously or asynchronously, [T] from Spotify
3131
*/
32-
open class SpotifyRestAction<T> internal constructor(protected val api: SpotifyApi<*, *>, val supplier: suspend () -> T) {
32+
open class SpotifyRestAction<T> internal constructor(protected val api: GenericSpotifyApi, val supplier: suspend () -> T) {
3333
private var hasRunBacking: Boolean = false
3434
private var hasCompletedBacking: Boolean = false
3535

@@ -131,7 +131,7 @@ open class SpotifyRestAction<T> internal constructor(protected val api: SpotifyA
131131
override fun toString() = complete().toString()
132132
}
133133

134-
class SpotifyRestActionPaging<Z : Any, T : PagingObjectBase<Z>>(api: SpotifyApi<*, *>, supplier: suspend () -> T) :
134+
class SpotifyRestActionPaging<Z : Any, T : PagingObjectBase<Z>>(api: GenericSpotifyApi, supplier: suspend () -> T) :
135135
SpotifyRestAction<T>(api, supplier) {
136136

137137
/**

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientFollowingApi.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.SpotifyApi
4+
import com.adamratzman.spotify.GenericSpotifyApi
55
import com.adamratzman.spotify.SpotifyClientApi
66
import com.adamratzman.spotify.SpotifyException.BadRequestException
77
import com.adamratzman.spotify.SpotifyRestAction
@@ -28,7 +28,7 @@ typealias ClientFollowingAPI = ClientFollowingApi
2828
*
2929
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/follow/)**
3030
*/
31-
class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
31+
class ClientFollowingApi(api: GenericSpotifyApi) : FollowingApi(api) {
3232
/**
3333
* Check to see if the current user is following another Spotify user.
3434
*
@@ -151,8 +151,8 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
151151
* with full [Artist] objects
152152
*/
153153
fun getFollowedArtists(
154-
limit: Int? = api.defaultLimit,
155-
after: String? = null
154+
limit: Int? = api.defaultLimit,
155+
after: String? = null
156156
): SpotifyRestActionPaging<Artist, CursorBasedPagingObject<Artist>> {
157157
return toActionPaging {
158158
get(

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientLibraryApi.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.SpotifyApi
4+
import com.adamratzman.spotify.GenericSpotifyApi
55
import com.adamratzman.spotify.SpotifyException.BadRequestException
66
import com.adamratzman.spotify.SpotifyRestAction
77
import com.adamratzman.spotify.SpotifyRestActionPaging
@@ -28,7 +28,7 @@ typealias ClientLibraryAPI = ClientLibraryApi
2828
*
2929
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/library/)**
3030
*/
31-
class ClientLibraryApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
31+
class ClientLibraryApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
3232
/**
3333
* Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library.
3434
*
@@ -44,14 +44,14 @@ class ClientLibraryApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
4444
* @return [PagingObject] of [SavedTrack] ordered by position in library
4545
*/
4646
fun getSavedTracks(
47-
limit: Int? = api.defaultLimit,
48-
offset: Int? = null,
49-
market: Market? = null
47+
limit: Int? = api.defaultLimit,
48+
offset: Int? = null,
49+
market: Market? = null
5050
): SpotifyRestActionPaging<SavedTrack, PagingObject<SavedTrack>> {
5151
return toActionPaging {
5252
get(
53-
EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.name)
54-
.toString()
53+
EndpointBuilder("/me/tracks").with("limit", limit).with("offset", offset).with("market", market?.name)
54+
.toString()
5555
).toPagingObject(SavedTrack.serializer(), endpoint = this, json = json)
5656
}
5757
}
@@ -71,14 +71,14 @@ class ClientLibraryApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
7171
* @return Paging Object of [SavedAlbum] ordered by position in library
7272
*/
7373
fun getSavedAlbums(
74-
limit: Int? = api.defaultLimit,
75-
offset: Int? = null,
76-
market: Market? = null
74+
limit: Int? = api.defaultLimit,
75+
offset: Int? = null,
76+
market: Market? = null
7777
): SpotifyRestActionPaging<SavedAlbum, PagingObject<SavedAlbum>> {
7878
return toActionPaging {
7979
get(
80-
EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.name)
81-
.toString()
80+
EndpointBuilder("/me/albums").with("limit", limit).with("offset", offset).with("market", market?.name)
81+
.toString()
8282
).toPagingObject(SavedAlbum.serializer(), endpoint = this, json = json)
8383
}
8484
}

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientPersonalizationApi.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.SpotifyApi
4+
import com.adamratzman.spotify.GenericSpotifyApi
55
import com.adamratzman.spotify.SpotifyRestActionPaging
66
import com.adamratzman.spotify.SpotifyScope
77
import com.adamratzman.spotify.http.EndpointBuilder
@@ -19,7 +19,7 @@ typealias ClientPersonalizationAPI = ClientPersonalizationApi
1919
*
2020
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/personalization/)**
2121
*/
22-
class ClientPersonalizationApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
22+
class ClientPersonalizationApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
2323
/**
2424
* The time frame for which attribute affinities are computed.
2525
*
@@ -32,6 +32,7 @@ class ClientPersonalizationApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
3232
* Calculated from several years of data and including all new data as it becomes available
3333
*/
3434
LONG_TERM("long_term"),
35+
3536
/**
3637
* Approximately last 6 months
3738
*/
@@ -67,14 +68,14 @@ class ClientPersonalizationApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
6768
* @return [PagingObject] of full [Artist] objects sorted by affinity
6869
*/
6970
fun getTopArtists(
70-
limit: Int? = api.defaultLimit,
71-
offset: Int? = null,
72-
timeRange: TimeRange? = null
71+
limit: Int? = api.defaultLimit,
72+
offset: Int? = null,
73+
timeRange: TimeRange? = null
7374
): SpotifyRestActionPaging<Artist, PagingObject<Artist>> {
7475
return toActionPaging {
7576
get(
76-
EndpointBuilder("/me/top/artists").with("limit", limit).with("offset", offset)
77-
.with("time_range", timeRange).toString()
77+
EndpointBuilder("/me/top/artists").with("limit", limit).with("offset", offset)
78+
.with("time_range", timeRange).toString()
7879
).toPagingObject(Artist.serializer(), endpoint = this, json = json)
7980
}
8081
}
@@ -101,14 +102,14 @@ class ClientPersonalizationApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
101102
* @return [PagingObject] of full [Track] objects sorted by affinity
102103
*/
103104
fun getTopTracks(
104-
limit: Int? = api.defaultLimit,
105-
offset: Int? = null,
106-
timeRange: TimeRange? = null
105+
limit: Int? = api.defaultLimit,
106+
offset: Int? = null,
107+
timeRange: TimeRange? = null
107108
): SpotifyRestActionPaging<Track, PagingObject<Track>> {
108109
return toActionPaging {
109110
get(
110-
EndpointBuilder("/me/top/tracks").with("limit", limit).with("offset", offset)
111-
.with("time_range", timeRange).toString()
111+
EndpointBuilder("/me/top/tracks").with("limit", limit).with("offset", offset)
112+
.with("time_range", timeRange).toString()
112113
).toPagingObject(Track.serializer(), endpoint = this, json = json)
113114
}
114115
}

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientPlayerApi.kt

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.endpoints.client
33

4-
import com.adamratzman.spotify.SpotifyApi
4+
import com.adamratzman.spotify.GenericSpotifyApi
55
import com.adamratzman.spotify.SpotifyException.BadRequestException
66
import com.adamratzman.spotify.SpotifyRestAction
77
import com.adamratzman.spotify.SpotifyRestActionPaging
@@ -36,7 +36,7 @@ typealias ClientPlayerAPI = ClientPlayerApi
3636
*
3737
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/player/)**
3838
*/
39-
class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
39+
class ClientPlayerApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
4040
/**
4141
* Get information about a user’s available devices.
4242
*
@@ -61,7 +61,7 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
6161
return toAction {
6262
val obj = catch {
6363
get(EndpointBuilder("/me/player").toString())
64-
.toObject(CurrentlyPlayingContext.serializer(), api, json)
64+
.toObject(CurrentlyPlayingContext.serializer(), api, json)
6565
}
6666
if (obj?.timestamp == null) null else obj
6767
}
@@ -80,14 +80,14 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
8080
*
8181
*/
8282
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
8686
): SpotifyRestActionPaging<PlayHistory, CursorBasedPagingObject<PlayHistory>> {
8787
return toActionPaging {
8888
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()
9191
).toCursorBasedPagingObject(PlayHistory.serializer(), endpoint = this, json = json)
9292
}
9393
}
@@ -102,10 +102,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
102102
fun getCurrentlyPlaying(): SpotifyRestAction<CurrentlyPlayingObject?> {
103103
return toAction {
104104
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+
}
109109
if (obj?.timestamp == null) null else obj
110110
}
111111
}
@@ -141,10 +141,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
141141
return toAction {
142142
require(positionMs >= 0) { "Position must not be negative!" }
143143
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()
148148
)
149149
Unit
150150
}
@@ -163,10 +163,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
163163
fun setRepeatMode(state: PlayerRepeatState, deviceId: String? = null): SpotifyRestAction<Unit> {
164164
return toAction {
165165
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()
170170
)
171171
Unit
172172
}
@@ -186,10 +186,10 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
186186
require(volume in 0..100) { "Volume must be within 0 to 100 inclusive. Provided: $volume" }
187187
return toAction {
188188
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()
193193
)
194194
Unit
195195
}
@@ -256,11 +256,11 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
256256
* @throws BadRequestException if more than one type of play type is specified or the offset is illegal.
257257
*/
258258
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()
264264
): SpotifyRestAction<Unit> {
265265
return toAction {
266266
val url = EndpointBuilder("/me/player/play").with("device_id", deviceId).toString()
@@ -269,7 +269,7 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
269269
collection != null -> body += json { "context_uri" to collection.uri }
270270
tracksToPlay.isNotEmpty() -> body += json {
271271
"uris" to JsonArray(
272-
tracksToPlay.map { it.uri }.map(::JsonPrimitive)
272+
tracksToPlay.map { it.uri }.map(::JsonPrimitive)
273273
)
274274
}
275275
}
@@ -324,7 +324,7 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
324324
*/
325325
@SpotifyExperimentalFunctionApi
326326
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" }
328328
return toAction {
329329
val json = jsonMap()
330330
play?.let { json += json { "play" to it } }
@@ -344,10 +344,12 @@ class ClientPlayerApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
344344
* Repeat the current track
345345
*/
346346
TRACK,
347+
347348
/**
348349
* Repeat the current context
349350
*/
350351
CONTEXT,
352+
351353
/**
352354
* Will turn repeat off
353355
*/

0 commit comments

Comments
 (0)