@@ -16,8 +16,8 @@ fun spotifyApi(block: SpotifyApiBuilderDsl.() -> Unit) = SpotifyApiBuilderDsl().
16
16
* Spotify traditional Java style API builder
17
17
*/
18
18
class SpotifyApiBuilder (
19
- private var clientId : String ,
20
- private var clientSecret : String
19
+ private var clientId : String ,
20
+ private var clientSecret : String
21
21
) {
22
22
private var redirectUri: String? = null
23
23
private var authorizationCode: String? = null
@@ -190,17 +190,17 @@ data class SpotifyCredentials(val clientId: String?, val clientSecret: String?,
190
190
* limited time constraint on these before the API automatically refreshes them
191
191
*/
192
192
class SpotifyUserAuthorizationBuilder (
193
- var authorizationCode : String? = null ,
194
- var tokenString : String? = null ,
195
- var token : Token ? = null
193
+ var authorizationCode : String? = null ,
194
+ var tokenString : String? = null ,
195
+ var token : Token ? = null
196
196
) {
197
197
fun build () = SpotifyUserAuthorization (authorizationCode, tokenString, token)
198
198
}
199
199
200
200
data class SpotifyUserAuthorization (
201
- val authorizationCode : String? ,
202
- val tokenString : String? ,
203
- val token : Token ?
201
+ val authorizationCode : String? ,
202
+ val tokenString : String? ,
203
+ val token : Token ?
204
204
)
205
205
206
206
/* *
@@ -215,17 +215,18 @@ data class SpotifyUserAuthorization(
215
215
* @property enableAllUtilities Whether to enable all provided utilities
216
216
*/
217
217
class SpotifyUtilitiesBuilder (
218
- var useCache : Boolean = true ,
219
- var cacheLimit : Int? = 200 ,
220
- var automaticRefresh : Boolean = true ,
221
- var retryWhenRateLimited : Boolean = true ,
222
- var enableLogger : Boolean = true ,
223
- var testTokenValidity : Boolean = false ,
224
- var enableAllUtilities : Boolean = false
218
+ var useCache : Boolean = true ,
219
+ var cacheLimit : Int? = 200 ,
220
+ var automaticRefresh : Boolean = true ,
221
+ var retryWhenRateLimited : Boolean = true ,
222
+ var enableLogger : Boolean = true ,
223
+ var testTokenValidity : Boolean = false ,
224
+ var enableAllUtilities : Boolean = false
225
225
) {
226
226
fun build () =
227
227
if (enableAllUtilities)
228
- SpotifyUtilities (true ,
228
+ SpotifyUtilities (
229
+ true ,
229
230
200 ,
230
231
automaticRefresh = true ,
231
232
retryWhenRateLimited = true ,
@@ -244,12 +245,12 @@ class SpotifyUtilitiesBuilder(
244
245
}
245
246
246
247
data class SpotifyUtilities (
247
- val useCache : Boolean ,
248
- val cacheLimit : Int? ,
249
- val automaticRefresh : Boolean ,
250
- val retryWhenRateLimited : Boolean ,
251
- val enableLogger : Boolean ,
252
- val testTokenValidity : Boolean
248
+ val useCache : Boolean ,
249
+ val cacheLimit : Int? ,
250
+ val automaticRefresh : Boolean ,
251
+ val retryWhenRateLimited : Boolean ,
252
+ val enableLogger : Boolean ,
253
+ val testTokenValidity : Boolean
253
254
)
254
255
255
256
/* *
@@ -397,9 +398,9 @@ class SpotifyApiBuilderDsl {
397
398
* @param token [Token] object (useful if you already have exchanged an authorization code yourself
398
399
*/
399
400
private fun buildClient (
400
- authorizationCode : String? = null,
401
- tokenString : String? = null,
402
- token : Token ? = null
401
+ authorizationCode : String? = null,
402
+ tokenString : String? = null,
403
+ token : Token ? = null
403
404
): SpotifyClientAPI {
404
405
val clientId = credentials.clientId
405
406
val clientSecret = credentials.clientSecret
@@ -417,8 +418,12 @@ class SpotifyApiBuilderDsl {
417
418
val response = executeTokenRequest(HttpConnection (
418
419
url = " https://accounts.spotify.com/api/token" ,
419
420
method = HttpRequestMethod .POST ,
420
- bodyMap = null ,
421
- bodyString = " grant_type=authorization_code&code=$authorizationCode &redirect_uri=$redirectUri " ,
421
+ bodyMap = mapOf (
422
+ " grant_type" to " authorization_code" ,
423
+ " code" to authorizationCode,
424
+ " redirect_uri" to redirectUri
425
+ ),
426
+ bodyString = null ,
422
427
contentType = " application/x-www-form-urlencoded" ,
423
428
api = null
424
429
), clientId, clientSecret)
0 commit comments