@@ -31,12 +31,12 @@ import kotlinx.serialization.json.Json
31
31
* @param state This provides protection against attacks such as cross-site request forgery.
32
32
*/
33
33
fun getSpotifyAuthorizationUrl (
34
- vararg scopes : SpotifyScope ,
35
- clientId : String ,
36
- redirectUri : String ,
37
- isImplicitGrantFlow : Boolean = false,
38
- shouldShowDialog : Boolean = false,
39
- state : String? = null
34
+ vararg scopes : SpotifyScope ,
35
+ clientId : String ,
36
+ redirectUri : String ,
37
+ isImplicitGrantFlow : Boolean = false,
38
+ shouldShowDialog : Boolean = false,
39
+ state : String? = null
40
40
): String {
41
41
return SpotifyApi .getAuthUrlFull(
42
42
* scopes,
@@ -60,11 +60,11 @@ fun getSpotifyAuthorizationUrl(
60
60
* Then, base64url encode the hash that you generated.
61
61
*/
62
62
fun getPkceAuthorizationUrl (
63
- vararg scopes : SpotifyScope ,
64
- clientId : String ,
65
- redirectUri : String ,
66
- codeChallenge : String ,
67
- state : String? = null
63
+ vararg scopes : SpotifyScope ,
64
+ clientId : String ,
65
+ redirectUri : String ,
66
+ codeChallenge : String ,
67
+ state : String? = null
68
68
): String {
69
69
return SpotifyApi .getPkceAuthUrlFull(
70
70
* scopes,
@@ -224,10 +224,10 @@ fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) = SpotifyAppApiBuilder
224
224
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
225
225
*/
226
226
fun spotifyClientApi (
227
- clientId : String ,
228
- clientSecret : String ,
229
- redirectUri : String ,
230
- block : SpotifyClientApiBuilder .() -> Unit
227
+ clientId : String ,
228
+ clientSecret : String ,
229
+ redirectUri : String ,
230
+ block : SpotifyClientApiBuilder .() -> Unit
231
231
) = SpotifyClientApiBuilder ().apply (block).apply {
232
232
credentials {
233
233
this .clientId = clientId
@@ -248,10 +248,10 @@ fun spotifyClientApi(
248
248
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
249
249
*/
250
250
fun spotifyClientApi (
251
- clientId : String? ,
252
- clientSecret : String? ,
253
- redirectUri : String? ,
254
- apiToken : Token
251
+ clientId : String? ,
252
+ clientSecret : String? ,
253
+ redirectUri : String? ,
254
+ apiToken : Token
255
255
) = SpotifyClientApiBuilder ().apply {
256
256
credentials {
257
257
this .clientId = clientId
@@ -276,10 +276,10 @@ fun spotifyClientApi(
276
276
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
277
277
*/
278
278
fun spotifyClientApi (
279
- clientId : String? ,
280
- clientSecret : String? ,
281
- redirectUri : String? ,
282
- authCode : String
279
+ clientId : String? ,
280
+ clientSecret : String? ,
281
+ redirectUri : String? ,
282
+ authCode : String
283
283
) = SpotifyClientApiBuilder ().apply {
284
284
credentials {
285
285
this .clientId = clientId
@@ -292,7 +292,6 @@ fun spotifyClientApi(
292
292
}
293
293
}
294
294
295
-
296
295
/* *
297
296
* Instantiate a new [SpotifyClientApiBuilder] using a Spotify [clientId], [clientSecret], and [redirectUri],
298
297
* with an existing [SpotifyUserAuthorization] and with the ability to configure the api settings by providing a
@@ -310,12 +309,12 @@ fun spotifyClientApi(
310
309
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
311
310
*/
312
311
fun spotifyClientApi (
313
- clientId : String ,
314
- clientSecret : String ,
315
- redirectUri : String ,
316
- authorization : SpotifyUserAuthorization ,
317
- options : SpotifyApiOptions ? = null,
318
- block : SpotifyClientApiBuilder .() -> Unit = {}
312
+ clientId : String ,
313
+ clientSecret : String ,
314
+ redirectUri : String ,
315
+ authorization : SpotifyUserAuthorization ,
316
+ options : SpotifyApiOptions ? = null,
317
+ block : SpotifyClientApiBuilder .() -> Unit = {}
319
318
) = SpotifyClientApiBuilder ().apply (block).apply {
320
319
credentials {
321
320
this .clientId = clientId
@@ -338,7 +337,6 @@ fun spotifyClientApi(
338
337
*/
339
338
fun spotifyClientApi (block : SpotifyClientApiBuilder .() -> Unit ) = SpotifyClientApiBuilder ().apply (block)
340
339
341
-
342
340
// PKCE Client Api Builders
343
341
/*
344
342
____________________________
@@ -365,10 +363,10 @@ fun spotifyClientApi(block: SpotifyClientApiBuilder.() -> Unit) = SpotifyClientA
365
363
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
366
364
*/
367
365
fun spotifyClientPkceApi (
368
- clientId : String? ,
369
- redirectUri : String? ,
370
- authCode : String ,
371
- codeVerifier : String
366
+ clientId : String? ,
367
+ redirectUri : String? ,
368
+ authCode : String ,
369
+ codeVerifier : String
372
370
) = SpotifyClientApiBuilder ().apply {
373
371
credentials {
374
372
this .clientId = clientId
@@ -395,11 +393,11 @@ fun spotifyClientPkceApi(
395
393
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
396
394
*/
397
395
fun spotifyClientPkceApi (
398
- clientId : String? ,
399
- redirectUri : String? ,
400
- authCode : String ,
401
- codeVerifier : String ,
402
- block : SpotifyClientApiBuilder .() -> Unit = {}
396
+ clientId : String? ,
397
+ redirectUri : String? ,
398
+ authCode : String ,
399
+ codeVerifier : String ,
400
+ block : SpotifyClientApiBuilder .() -> Unit = {}
403
401
) = SpotifyClientApiBuilder ().apply {
404
402
credentials {
405
403
this .clientId = clientId
@@ -412,15 +410,13 @@ fun spotifyClientPkceApi(
412
410
}
413
411
}.apply (block)
414
412
415
-
416
-
417
413
/* *
418
414
* Spotify API builder
419
415
*/
420
416
class SpotifyApiBuilder (
421
- private var clientId : String? ,
422
- private var clientSecret : String? ,
423
- private var redirectUri : String?
417
+ private var clientId : String? ,
418
+ private var clientSecret : String? ,
419
+ private var redirectUri : String?
424
420
) {
425
421
/* *
426
422
* Allows you to authenticate a [SpotifyClientApi] with an authorization code
@@ -698,9 +694,9 @@ interface ISpotifyClientApiBuilder : ISpotifyApiBuilder<SpotifyClientApi, Spotif
698
694
* [SpotifyClientApi] builder for api creation using client authorization
699
695
*/
700
696
class SpotifyClientApiBuilder (
701
- override var credentials : SpotifyCredentials = SpotifyCredentialsBuilder ().build(),
702
- override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
703
- override var options : SpotifyApiOptions = SpotifyApiOptionsBuilder ().build()
697
+ override var credentials : SpotifyCredentials = SpotifyCredentialsBuilder ().build(),
698
+ override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
699
+ override var options : SpotifyApiOptions = SpotifyApiOptionsBuilder ().build()
704
700
) : ISpotifyClientApiBuilder {
705
701
override fun getAuthorizationUrl (vararg scopes : SpotifyScope , state : String? ): String {
706
702
require(credentials.redirectUri != null && credentials.clientId != null ) { " You didn't specify a redirect uri or client id in the credentials block!" }
@@ -718,7 +714,7 @@ class SpotifyClientApiBuilder(
718
714
val redirectUri = credentials.redirectUri
719
715
720
716
// either application credentials, or a token is required
721
- require((clientId != null && clientSecret != null && redirectUri != null ) || (clientId != null && redirectUri != null && authorization.pkceCodeVerifier != null ) || authorization.token != null || authorization.tokenString != null ) { " You need to specify a valid clientId, clientSecret, and redirectUri in the credentials block!" }
717
+ require((clientId != null && clientSecret != null && redirectUri != null ) || (clientId != null && redirectUri != null && authorization.pkceCodeVerifier != null ) || authorization.token != null || authorization.tokenString != null ) { " You need to specify a valid clientId, clientSecret, and redirectUri in the credentials block!" }
722
718
return when {
723
719
authorization.authorizationCode != null && authorization.pkceCodeVerifier == null -> try {
724
720
require(clientId != null && clientSecret != null && redirectUri != null ) { " You need to specify a valid clientId, clientSecret, and redirectUri in the credentials block!" }
@@ -863,9 +859,9 @@ interface ISpotifyAppApiBuilder : ISpotifyApiBuilder<SpotifyAppApi, SpotifyAppAp
863
859
* [SpotifyAppApi] builder for api creation using client authorization
864
860
*/
865
861
class SpotifyAppApiBuilder (
866
- override var credentials : SpotifyCredentials = SpotifyCredentialsBuilder ().build(),
867
- override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
868
- override var options : SpotifyApiOptions = SpotifyApiOptionsBuilder ().build()
862
+ override var credentials : SpotifyCredentials = SpotifyCredentialsBuilder ().build(),
863
+ override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
864
+ override var options : SpotifyApiOptions = SpotifyApiOptionsBuilder ().build()
869
865
) : ISpotifyAppApiBuilder {
870
866
/* *
871
867
* Build a public [SpotifyAppApi] using the provided credentials
@@ -988,11 +984,11 @@ data class SpotifyCredentials(val clientId: String?, val clientSecret: String?,
988
984
* limited time constraint on these before the API automatically refreshes them
989
985
*/
990
986
class SpotifyUserAuthorizationBuilder (
991
- var authorizationCode : String? = null ,
992
- var tokenString : String? = null ,
993
- var token : Token ? = null ,
994
- var refreshTokenString : String? = null ,
995
- var pkceCodeVerifier : String? = null
987
+ var authorizationCode : String? = null ,
988
+ var tokenString : String? = null ,
989
+ var token : Token ? = null ,
990
+ var refreshTokenString : String? = null ,
991
+ var pkceCodeVerifier : String? = null
996
992
) {
997
993
fun build () = SpotifyUserAuthorization (authorizationCode, tokenString, token, refreshTokenString, pkceCodeVerifier)
998
994
}
@@ -1010,11 +1006,11 @@ class SpotifyUserAuthorizationBuilder(
1010
1006
* @property pkceCodeVerifier The code verifier generated that the client authenticated with (using its code challenge)
1011
1007
*/
1012
1008
data class SpotifyUserAuthorization (
1013
- var authorizationCode : String? = null ,
1014
- var tokenString : String? = null ,
1015
- var token : Token ? = null ,
1016
- var refreshTokenString : String? = null ,
1017
- var pkceCodeVerifier : String? = null
1009
+ var authorizationCode : String? = null ,
1010
+ var tokenString : String? = null ,
1011
+ var token : Token ? = null ,
1012
+ var refreshTokenString : String? = null ,
1013
+ var pkceCodeVerifier : String? = null
1018
1014
)
1019
1015
1020
1016
/* *
@@ -1035,18 +1031,18 @@ data class SpotifyUserAuthorization(
1035
1031
*
1036
1032
*/
1037
1033
class SpotifyApiOptionsBuilder (
1038
- var useCache : Boolean = true ,
1039
- var cacheLimit : Int? = 200 ,
1040
- var automaticRefresh : Boolean = true ,
1041
- var retryWhenRateLimited : Boolean = true ,
1042
- var enableLogger : Boolean = true ,
1043
- var testTokenValidity : Boolean = false ,
1044
- var enableAllOptions : Boolean = false ,
1045
- var defaultLimit : Int = 50 ,
1046
- var allowBulkRequests : Boolean = true ,
1047
- var requestTimeoutMillis : Long? = null ,
1048
- var json : Json = nonstrictJson,
1049
- var refreshTokenProducer : (suspend (SpotifyApi <* , * >) -> Token )? = null
1034
+ var useCache : Boolean = true ,
1035
+ var cacheLimit : Int? = 200 ,
1036
+ var automaticRefresh : Boolean = true ,
1037
+ var retryWhenRateLimited : Boolean = true ,
1038
+ var enableLogger : Boolean = true ,
1039
+ var testTokenValidity : Boolean = false ,
1040
+ var enableAllOptions : Boolean = false ,
1041
+ var defaultLimit : Int = 50 ,
1042
+ var allowBulkRequests : Boolean = true ,
1043
+ var requestTimeoutMillis : Long? = null ,
1044
+ var json : Json = nonstrictJson,
1045
+ var refreshTokenProducer : (suspend (SpotifyApi <* , * >) -> Token )? = null
1050
1046
) {
1051
1047
fun build () =
1052
1048
if (enableAllOptions)
@@ -1097,17 +1093,17 @@ class SpotifyApiOptionsBuilder(
1097
1093
*/
1098
1094
1099
1095
data class SpotifyApiOptions (
1100
- var useCache : Boolean ,
1101
- var cacheLimit : Int? ,
1102
- var automaticRefresh : Boolean ,
1103
- var retryWhenRateLimited : Boolean ,
1104
- var enableLogger : Boolean ,
1105
- var testTokenValidity : Boolean ,
1106
- var defaultLimit : Int ,
1107
- var allowBulkRequests : Boolean ,
1108
- var requestTimeoutMillis : Long? ,
1109
- var json : Json ,
1110
- var refreshTokenProducer : (suspend (SpotifyApi <* , * >) -> Token )?
1096
+ var useCache : Boolean ,
1097
+ var cacheLimit : Int? ,
1098
+ var automaticRefresh : Boolean ,
1099
+ var retryWhenRateLimited : Boolean ,
1100
+ var enableLogger : Boolean ,
1101
+ var testTokenValidity : Boolean ,
1102
+ var defaultLimit : Int ,
1103
+ var allowBulkRequests : Boolean ,
1104
+ var requestTimeoutMillis : Long? ,
1105
+ var json : Json ,
1106
+ var refreshTokenProducer : (suspend (SpotifyApi <* , * >) -> Token )?
1111
1107
)
1112
1108
1113
1109
@Deprecated(" Name has been replaced by `options`" , ReplaceWith (" SpotifyApiOptions" ))
0 commit comments