@@ -27,13 +27,12 @@ fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) =
27
27
28
28
@Deprecated(" Builder methods are now found in SpotifyBuilder" , ReplaceWith (" SpotifyBuilder.spotifyClientApi" ))
29
29
fun spotifyAppApi (clientId : String , clientSecret : String , redirectUri : String , block : SpotifyClientApiBuilder .() -> Unit = {}) =
30
- SpotifyBuilder .spotifyClientApi(clientId, clientSecret,redirectUri, block)
30
+ SpotifyBuilder .spotifyClientApi(clientId, clientSecret, redirectUri, block)
31
31
32
32
@Deprecated(" Builder methods are now found in SpotifyBuilder" , ReplaceWith (" SpotifyBuilder.spotifyClientApi" ))
33
33
fun spotifyAppApi (block : SpotifyClientApiBuilder .() -> Unit ) =
34
34
SpotifyBuilder .spotifyClientApi(block)
35
35
36
-
37
36
/* *
38
37
* Contains static methods to instantiate [SpotifyAppApi] and [SpotifyClientApi] instances
39
38
*/
@@ -91,10 +90,10 @@ class SpotifyBuilder {
91
90
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
92
91
*/
93
92
fun spotifyClientApi (
94
- clientId : String ,
95
- clientSecret : String ,
96
- redirectUri : String ,
97
- block : SpotifyClientApiBuilder .() -> Unit
93
+ clientId : String ,
94
+ clientSecret : String ,
95
+ redirectUri : String ,
96
+ block : SpotifyClientApiBuilder .() -> Unit
98
97
) = SpotifyClientApiBuilder ().apply (block).apply {
99
98
credentials {
100
99
this .clientId = clientId
@@ -117,7 +116,6 @@ class SpotifyBuilder {
117
116
}
118
117
}
119
118
120
-
121
119
/* *
122
120
* Spotify API builder
123
121
*/
@@ -126,7 +124,15 @@ class SpotifyApiBuilder(
126
124
private var clientSecret : String? ,
127
125
private var redirectUri : String?
128
126
) {
127
+ /* *
128
+ * Allows you to authenticate a [SpotifyClientApi] with an authorization code
129
+ * or build [SpotifyApi] using a refresh token
130
+ */
129
131
var authorization: SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build()
132
+
133
+ /* *
134
+ * Allows you to override default values for caching, token refresh, and logging
135
+ */
130
136
var options: SpotifyApiOptions = SpotifyApiOptionsBuilder ().build()
131
137
132
138
/* *
@@ -237,14 +243,48 @@ class SpotifyApiBuilder(
237
243
}.build()
238
244
}
239
245
246
+ /* *
247
+ * The type of Spotify authorization used to build an Api instance
248
+ */
240
249
enum class AuthorizationType {
250
+ /* *
251
+ * Authorization through explicit affirmative action taken by a client (user) allowing the application to access a/multiple [SpotifyScope]
252
+ *
253
+ * [Spotify application settings page](https://developer.spotify.com/documentation/general/guides/app-settings/)
254
+ */
241
255
CLIENT ,
256
+
257
+ /* *
258
+ * Authorization through application client id and secret, allowing access only to public endpoints and data
259
+ *
260
+ * [Spotify application settings page](https://developer.spotify.com/documentation/general/guides/app-settings/)
261
+ */
242
262
APPLICATION ;
243
263
}
244
264
265
+ /* *
266
+ * Spotify Api builder interface
267
+ *
268
+ * @property T The type of [SpotifyApi] to be built
269
+ * @property B The associated Api builder for [T]
270
+ */
245
271
interface ISpotifyApiBuilder <T : SpotifyApi <T , B >, B : ISpotifyApiBuilder <T , B >> {
272
+ /* *
273
+ * A block in which Spotify application credentials (accessible via the Spotify [dashboard](https://developer.spotify.com/dashboard/applications))
274
+ * should be put
275
+ */
246
276
var credentials: SpotifyCredentials
277
+
278
+ /* *
279
+ * Allows you to authenticate a [SpotifyClientApi] with an authorization code
280
+ * or build [SpotifyApi] using a refresh token
281
+ */
247
282
var authorization: SpotifyUserAuthorization
283
+
284
+
285
+ /* *
286
+ * Allows you to override default values for caching, token refresh, and logging
287
+ */
248
288
var options: SpotifyApiOptions
249
289
250
290
/* *
@@ -276,13 +316,15 @@ interface ISpotifyApiBuilder<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>
276
316
/* *
277
317
* Allows you to override default values for caching, token refresh, and logging
278
318
*/
319
+ @Deprecated(" Succeeded by the options method" , ReplaceWith (" options" ))
279
320
fun utilities (block : SpotifyApiOptionsBuilder .() -> Unit ) {
280
321
options = SpotifyApiOptionsBuilder ().apply (block).build()
281
322
}
282
323
283
324
/* *
284
325
* Allows you to override default values for caching, token refresh, and logging
285
326
*/
327
+ @Deprecated(" Succeeded by the options method" , ReplaceWith (" options" ))
286
328
fun config (block : SpotifyApiOptionsBuilder .() -> Unit ) {
287
329
options = SpotifyApiOptionsBuilder ().apply (block).build()
288
330
}
@@ -294,6 +336,9 @@ interface ISpotifyApiBuilder<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>
294
336
options = SpotifyApiOptionsBuilder ().apply (block).build()
295
337
}
296
338
339
+ /* *
340
+ * Allows you to override default values for caching, token refresh, and logging
341
+ */
297
342
fun options (options : SpotifyApiOptions ) = apply { this .options = options }
298
343
299
344
/* *
@@ -323,6 +368,9 @@ interface ISpotifyApiBuilder<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>
323
368
}
324
369
}
325
370
371
+ /* *
372
+ * Client interface exposing [getAuthorizationUrl]
373
+ */
326
374
interface ISpotifyClientApiBuilder : ISpotifyApiBuilder <SpotifyClientApi , SpotifyClientApiBuilder > {
327
375
/* *
328
376
* Create a Spotify authorization URL from which API access can be obtained
@@ -333,6 +381,9 @@ interface ISpotifyClientApiBuilder : ISpotifyApiBuilder<SpotifyClientApi, Spotif
333
381
fun getAuthorizationUrl (vararg scopes : SpotifyScope ): String
334
382
}
335
383
384
+ /* *
385
+ * [SpotifyClientApi] builder for api creation using client authorization
386
+ */
336
387
class SpotifyClientApiBuilder (
337
388
override var credentials : SpotifyCredentials = SpotifyCredentialsBuilder ().build(),
338
389
override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
@@ -348,6 +399,7 @@ class SpotifyClientApiBuilder(
348
399
val clientSecret = credentials.clientSecret
349
400
val redirectUri = credentials.redirectUri
350
401
402
+ // either application credentials, or a token is required
351
403
require((clientId != null && clientSecret != null && redirectUri != null ) || authorization.token != null || authorization.tokenString != null ) { " You need to specify a valid clientId, clientSecret, and redirectUri in the credentials block!" }
352
404
return when {
353
405
authorization.authorizationCode != null -> try {
@@ -427,8 +479,16 @@ class SpotifyClientApiBuilder(
427
479
}
428
480
}
429
481
482
+
483
+ /* *
484
+ * App Api builder interface
485
+ */
430
486
interface ISpotifyAppApiBuilder : ISpotifyApiBuilder <SpotifyAppApi , SpotifyAppApiBuilder >
431
487
488
+
489
+ /* *
490
+ * [SpotifyAppApi] builder for api creation using client authorization
491
+ */
432
492
class SpotifyAppApiBuilder (
433
493
override var credentials : SpotifyCredentials = SpotifyCredentialsBuilder ().build(),
434
494
override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
@@ -547,6 +607,17 @@ class SpotifyUserAuthorizationBuilder(
547
607
fun build () = SpotifyUserAuthorization (authorizationCode, tokenString, token, refreshTokenString)
548
608
}
549
609
610
+ /* *
611
+ * User-defined authorization parameters
612
+ *
613
+ * @property authorizationCode Only available when building [SpotifyClientApi]. Spotify auth code
614
+ * @property token Build the API using an existing token. If you're building [SpotifyClientApi], this
615
+ * will be your **access** token. If you're building [SpotifyApi], it will be your **refresh** token
616
+ * @property tokenString Build the API using an existing token (string). If you're building [SpotifyClientApi], this
617
+ * will be your **access** token. If you're building [SpotifyApi], it will be your **refresh** token. There is a *very*
618
+ * limited time constraint on these before the API automatically refreshes them
619
+ * @property refreshTokenString Refresh token, given as a string, to be exchanged to Spotify for a new token
620
+ */
550
621
data class SpotifyUserAuthorization (
551
622
var authorizationCode : String? ,
552
623
var tokenString : String? ,
@@ -598,6 +669,18 @@ class SpotifyApiOptionsBuilder(
598
669
)
599
670
}
600
671
672
+ /* *
673
+ * API Utilities
674
+ *
675
+ * @property useCache Set whether to cache requests. Default: true
676
+ * @property cacheLimit The maximum amount of cached requests allowed at one time. Null means no limit
677
+ * @property automaticRefresh Enable or disable automatic refresh of the Spotify access token
678
+ * @property retryWhenRateLimited Set whether to block the current thread and wait until the API can retry the request
679
+ * @property enableLogger Set whether to enable to the exception logger
680
+ * @property testTokenValidity After API creation, test whether the token is valid by performing a lightweight request
681
+ * @property enableAllOptions Whether to enable all provided utilities
682
+ */
683
+
601
684
data class SpotifyApiOptions (
602
685
var useCache : Boolean ,
603
686
var cacheLimit : Int? ,
0 commit comments