@@ -63,6 +63,11 @@ class SpotifyApiBuilder(
63
63
*/
64
64
fun testTokenValidity (testTokenValidity : Boolean ) = apply { this .options.testTokenValidity = testTokenValidity }
65
65
66
+ /* *
67
+ * Allows you to set the default amount of objects to retrieve in one request
68
+ */
69
+ fun defaultLimit (defaultLimit : Int ) = apply { this .options.defaultLimit = defaultLimit }
70
+
66
71
/* *
67
72
* Set the application client id
68
73
*/
@@ -92,7 +97,7 @@ class SpotifyApiBuilder(
92
97
* Set a returned [authorization code](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
93
98
*/
94
99
fun authorizationCode (authorizationCode : String? ) =
95
- apply { this .authorization.authorizationCode = authorizationCode }
100
+ apply { this .authorization.authorizationCode = authorizationCode }
96
101
97
102
/* *
98
103
* If you only have an access token, the api can be instantiated with it
@@ -113,7 +118,7 @@ class SpotifyApiBuilder(
113
118
* Set whether to block the current thread and wait until the API can retry the request
114
119
*/
115
120
fun retryWhenRateLimited (retryWhenRateLimited : Boolean ) =
116
- apply { this .options.retryWhenRateLimited = retryWhenRateLimited }
121
+ apply { this .options.retryWhenRateLimited = retryWhenRateLimited }
117
122
118
123
/* *
119
124
* Set whether to enable to the exception logger
@@ -323,74 +328,77 @@ class SpotifyClientApiBuilder(
323
328
require(clientId != null && clientSecret != null && redirectUri != null ) { " You need to specify a valid clientId, clientSecret, and redirectUri in the credentials block!" }
324
329
325
330
val response = executeTokenRequest(
326
- HttpConnection (
327
- " https://accounts.spotify.com/api/token" ,
328
- HttpRequestMethod .POST ,
329
- mapOf (
330
- " grant_type" to " authorization_code" ,
331
- " code" to authorization.authorizationCode,
332
- " redirect_uri" to redirectUri
333
- ),
334
- null ,
335
- " application/x-www-form-urlencoded" ,
336
- listOf (),
337
- null
338
- ), clientId, clientSecret
331
+ HttpConnection (
332
+ " https://accounts.spotify.com/api/token" ,
333
+ HttpRequestMethod .POST ,
334
+ mapOf (
335
+ " grant_type" to " authorization_code" ,
336
+ " code" to authorization.authorizationCode,
337
+ " redirect_uri" to redirectUri
338
+ ),
339
+ null ,
340
+ " application/x-www-form-urlencoded" ,
341
+ listOf (),
342
+ null
343
+ ), clientId, clientSecret
339
344
)
340
345
341
346
SpotifyClientApi (
347
+ clientId,
348
+ clientSecret,
349
+ redirectUri,
350
+ response.body.toObject(Token .serializer(), null , options.json),
351
+ options.useCache,
352
+ options.cacheLimit,
353
+ options.automaticRefresh,
354
+ options.retryWhenRateLimited,
355
+ options.enableLogger,
356
+ options.testTokenValidity,
357
+ options.defaultLimit,
358
+ options.json
359
+ )
360
+ } catch (e: CancellationException ) {
361
+ throw e
362
+ } catch (e: Exception ) {
363
+ throw SpotifyException .AuthenticationException (" Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret , authCode=${authorization.authorizationCode} )" , e)
364
+ }
365
+ authorization.token != null -> SpotifyClientApi (
342
366
clientId,
343
367
clientSecret,
344
368
redirectUri,
345
- response.body.toObject( Token .serializer(), null , options.json) ,
369
+ authorization.token !! ,
346
370
options.useCache,
347
371
options.cacheLimit,
348
372
options.automaticRefresh,
349
373
options.retryWhenRateLimited,
350
374
options.enableLogger,
351
375
options.testTokenValidity,
376
+ options.defaultLimit,
352
377
options.json
353
- )
354
- } catch (e: CancellationException ) {
355
- throw e
356
- } catch (e: Exception ) {
357
- throw SpotifyException .AuthenticationException (" Invalid credentials provided in the login process (clientId=$clientId , clientSecret=$clientSecret , authCode=${authorization.authorizationCode} )" , e)
358
- }
359
- authorization.token != null -> SpotifyClientApi (
360
- clientId,
361
- clientSecret,
362
- redirectUri,
363
- authorization.token!! ,
364
- options.useCache,
365
- options.cacheLimit,
366
- options.automaticRefresh,
367
- options.retryWhenRateLimited,
368
- options.enableLogger,
369
- options.testTokenValidity,
370
- options.json
371
378
)
372
379
authorization.tokenString != null -> SpotifyClientApi (
373
- clientId,
374
- clientSecret,
375
- redirectUri,
376
- Token (
377
- authorization.tokenString!! ,
378
- " client_credentials" ,
379
- 1000 ,
380
- null ,
381
- null
382
- ),
383
- options.useCache,
384
- options.cacheLimit,
385
- false ,
386
- options.retryWhenRateLimited,
387
- options.enableLogger,
388
- options.testTokenValidity,
389
- options.json
380
+ clientId,
381
+ clientSecret,
382
+ redirectUri,
383
+ Token (
384
+ authorization.tokenString!! ,
385
+ " client_credentials" ,
386
+ 1000 ,
387
+ null ,
388
+ null
389
+ ),
390
+ options.useCache,
391
+ options.cacheLimit,
392
+ false ,
393
+ options.retryWhenRateLimited,
394
+ options.enableLogger,
395
+ options.testTokenValidity,
396
+ options.defaultLimit,
397
+ options.json
390
398
)
391
399
else -> throw IllegalArgumentException (
392
- " At least one of: authorizationCode, tokenString, or token must be provided " +
393
- " to build a SpotifyClientApi object"
400
+ " At least one of: authorizationCode, tokenString, or token must be provided " +
401
+ " to build a SpotifyClientApi object"
394
402
)
395
403
}
396
404
}
@@ -418,62 +426,66 @@ class SpotifyAppApiBuilder(
418
426
require((clientId != null && clientSecret != null ) || authorization.token != null || authorization.tokenString != null ) { " You didn't specify a client id or client secret in the credentials block!" }
419
427
return when {
420
428
authorization.token != null -> SpotifyAppApi (
421
- clientId,
422
- clientSecret,
423
- authorization.token!! ,
424
- options.useCache,
425
- options.cacheLimit,
426
- false ,
427
- options.retryWhenRateLimited,
428
- options.enableLogger,
429
- options.testTokenValidity,
430
- options.json
431
- )
432
- authorization.tokenString != null -> {
433
- SpotifyAppApi (
434
429
clientId,
435
430
clientSecret,
436
- Token (
437
- authorization.tokenString!! , " client_credentials" ,
438
- 60000 , null , null
439
- ),
431
+ authorization.token!! ,
440
432
options.useCache,
441
433
options.cacheLimit,
442
434
false ,
443
435
options.retryWhenRateLimited,
444
436
options.enableLogger,
445
437
options.testTokenValidity,
438
+ options.defaultLimit,
446
439
options.json
440
+ )
441
+ authorization.tokenString != null -> {
442
+ SpotifyAppApi (
443
+ clientId,
444
+ clientSecret,
445
+ Token (
446
+ authorization.tokenString!! , " client_credentials" ,
447
+ 60000 , null , null
448
+ ),
449
+ options.useCache,
450
+ options.cacheLimit,
451
+ false ,
452
+ options.retryWhenRateLimited,
453
+ options.enableLogger,
454
+ options.testTokenValidity,
455
+ options.defaultLimit,
456
+ options.json
447
457
)
448
458
}
449
459
authorization.refreshTokenString != null -> {
450
460
SpotifyAppApi (
451
- clientId,
452
- clientSecret,
453
- Token (" " , " " , 0 , authorization.refreshTokenString!! ),
454
- options.useCache,
455
- options.cacheLimit,
456
- false ,
457
- options.retryWhenRateLimited,
458
- options.enableLogger,
459
- options.testTokenValidity,
460
- options.json
461
+ clientId,
462
+ clientSecret,
463
+ Token (" " , " " , 0 , authorization.refreshTokenString!! ),
464
+ options.useCache,
465
+ options.cacheLimit,
466
+ false ,
467
+ options.retryWhenRateLimited,
468
+ options.enableLogger,
469
+ options.testTokenValidity,
470
+ options.defaultLimit,
471
+ options.json
461
472
)
462
473
}
463
474
else -> try {
464
475
require(clientId != null && clientSecret != null ) { " Illegal credentials provided" }
465
476
val token = getCredentialedToken(clientId, clientSecret, null , options.json)
466
477
SpotifyAppApi (
467
- clientId,
468
- clientSecret,
469
- token,
470
- options.useCache,
471
- options.cacheLimit,
472
- false ,
473
- options.retryWhenRateLimited,
474
- options.enableLogger,
475
- options.testTokenValidity,
476
- options.json
478
+ clientId,
479
+ clientSecret,
480
+ token,
481
+ options.useCache,
482
+ options.cacheLimit,
483
+ false ,
484
+ options.retryWhenRateLimited,
485
+ options.enableLogger,
486
+ options.testTokenValidity,
487
+ options.defaultLimit,
488
+ options.json
477
489
)
478
490
} catch (e: CancellationException ) {
479
491
throw e
@@ -497,8 +509,8 @@ class SpotifyCredentialsBuilder {
497
509
var redirectUri: String? = null
498
510
499
511
fun build () =
500
- if (clientId?.isNotEmpty() == false || clientSecret?.isNotEmpty() == false ) throw IllegalArgumentException (" clientId or clientSecret is empty" )
501
- else SpotifyCredentials (clientId, clientSecret, redirectUri)
512
+ if (clientId?.isNotEmpty() == false || clientSecret?.isNotEmpty() == false ) throw IllegalArgumentException (" clientId or clientSecret is empty" )
513
+ else SpotifyCredentials (clientId, clientSecret, redirectUri)
502
514
}
503
515
504
516
data class SpotifyCredentials (val clientId : String? , val clientSecret : String? , val redirectUri : String? )
@@ -549,6 +561,8 @@ data class SpotifyUserAuthorization(
549
561
* @property retryWhenRateLimited Set whether to block the current thread and wait until the API can retry the request
550
562
* @property enableLogger Set whether to enable to the exception logger
551
563
* @property testTokenValidity After API creation, test whether the token is valid by performing a lightweight request
564
+ * @property defaultLimit The default amount of objects to retrieve in one request
565
+ * @property json The Json serializer/deserializer instance
552
566
* @property enableAllOptions Whether to enable all provided utilities
553
567
*/
554
568
class SpotifyApiOptionsBuilder (
@@ -559,29 +573,32 @@ class SpotifyApiOptionsBuilder(
559
573
var enableLogger : Boolean = true ,
560
574
var testTokenValidity : Boolean = false ,
561
575
var enableAllOptions : Boolean = false ,
576
+ val defaultLimit : Int = 50 ,
562
577
var json : Json = stableJson
563
578
) {
564
579
fun build () =
565
- if (enableAllOptions)
566
- SpotifyApiOptions (
567
- true ,
568
- 200 ,
569
- automaticRefresh = false ,
570
- retryWhenRateLimited = true ,
571
- enableLogger = true ,
572
- testTokenValidity = true ,
573
- json = json
574
- )
575
- else
576
- SpotifyApiOptions (
577
- useCache,
578
- cacheLimit,
579
- automaticRefresh,
580
- retryWhenRateLimited,
581
- enableLogger,
582
- testTokenValidity,
583
- json
584
- )
580
+ if (enableAllOptions)
581
+ SpotifyApiOptions (
582
+ true ,
583
+ 200 ,
584
+ automaticRefresh = false ,
585
+ retryWhenRateLimited = true ,
586
+ enableLogger = true ,
587
+ testTokenValidity = true ,
588
+ defaultLimit = 50 ,
589
+ json = json
590
+ )
591
+ else
592
+ SpotifyApiOptions (
593
+ useCache,
594
+ cacheLimit,
595
+ automaticRefresh,
596
+ retryWhenRateLimited,
597
+ enableLogger,
598
+ testTokenValidity,
599
+ defaultLimit,
600
+ json
601
+ )
585
602
}
586
603
587
604
/* *
@@ -593,7 +610,8 @@ class SpotifyApiOptionsBuilder(
593
610
* @property retryWhenRateLimited Set whether to block the current thread and wait until the API can retry the request
594
611
* @property enableLogger Set whether to enable to the exception logger
595
612
* @property testTokenValidity After API creation, test whether the token is valid by performing a lightweight request
596
- * @property enableAllOptions Whether to enable all provided utilities
613
+ * @property defaultLimit The default amount of objects to retrieve in one request
614
+ * @property json The Json serializer/deserializer instance
597
615
*/
598
616
599
617
data class SpotifyApiOptions (
@@ -603,6 +621,7 @@ data class SpotifyApiOptions(
603
621
var retryWhenRateLimited : Boolean ,
604
622
var enableLogger : Boolean ,
605
623
var testTokenValidity : Boolean ,
624
+ var defaultLimit : Int ,
606
625
var json : Json
607
626
)
608
627
0 commit comments