Skip to content

Commit a74219d

Browse files
authored
Merge pull request #112 from adamint/dev
Introduce a better way to create and read TuneableTrackAttributes
2 parents 68a176a + ef65731 commit a74219d

File tree

14 files changed

+231
-100
lines changed

14 files changed

+231
-100
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repositories {
2828
jcenter()
2929
}
3030
31-
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.3.03'
31+
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '2.3.06'
3232
```
3333

3434
To use the latest snapshot instead, you must add the Jitpack repository as well
@@ -50,7 +50,7 @@ dependencies {
5050
<dependency>
5151
<groupId>com.adamratzman</groupId>
5252
<artifactId>spotify-api-kotlin</artifactId>
53-
<version>2.3.03</version>
53+
<version>2.3.06</version>
5454
</dependency>
5555
5656
<repository>

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
buildscript {
22
ext.kotlin_version = '1.3.41'
33
ext.dokka_version = '0.9.17'
4+
ext.junit_version = '5.5.1'
45

56
repositories { jcenter() }
67

@@ -10,9 +11,8 @@ buildscript {
1011
}
1112
}
1213

13-
1414
plugins {
15-
id "com.diffplug.gradle.spotless" version "3.23.1"
15+
id "com.diffplug.gradle.spotless" version "3.24.0"
1616
id "base"
1717
id "io.codearte.nexus-staging" version "0.21.0"
1818
id "com.bmuschko.nexus" version "2.3.1"
@@ -22,7 +22,7 @@ apply plugin: 'kotlin'
2222
apply plugin: 'org.jetbrains.dokka'
2323

2424
group 'com.adamratzman'
25-
version '2.3.03'
25+
version '2.3.06'
2626

2727
archivesBaseName = 'spotify-api-kotlin'
2828

@@ -37,7 +37,7 @@ dependencies {
3737
compile "com.squareup.moshi:moshi:1.8.0"
3838
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
3939

40-
compile group: 'com.google.http-client', name: 'google-http-client', version: '1.30.2'
40+
compile "com.google.http-client:google-http-client:1.31.0"
4141

4242
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4343
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
@@ -51,9 +51,9 @@ dependencies {
5151
exclude group: 'org.jetbrains.kotlin'
5252
}
5353

54-
testCompile('org.junit.jupiter:junit-jupiter-api:5.4.2')
55-
testCompile(group: 'org.json', name: 'json', version: '20180130')
56-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
54+
testCompile "org.junit.jupiter:junit-jupiter-api:$junit_version"
55+
testCompile "org.json:json:20180130"
56+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
5757
}
5858

5959
dokka {

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

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ fun spotifyApi(block: SpotifyApiBuilderDsl.() -> Unit) = SpotifyApiBuilderDsl().
1616
* Spotify traditional Java style API builder
1717
*/
1818
class SpotifyApiBuilder(
19-
private var clientId: String,
20-
private var clientSecret: String
19+
private var clientId: String,
20+
private var clientSecret: String
2121
) {
2222
private var redirectUri: String? = null
2323
private var authorizationCode: String? = null
@@ -190,17 +190,17 @@ data class SpotifyCredentials(val clientId: String?, val clientSecret: String?,
190190
* limited time constraint on these before the API automatically refreshes them
191191
*/
192192
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
196196
) {
197197
fun build() = SpotifyUserAuthorization(authorizationCode, tokenString, token)
198198
}
199199

200200
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?
204204
)
205205

206206
/**
@@ -215,13 +215,13 @@ data class SpotifyUserAuthorization(
215215
* @property enableAllUtilities Whether to enable all provided utilities
216216
*/
217217
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
225225
) {
226226
fun build() =
227227
if (enableAllUtilities)
@@ -245,12 +245,12 @@ class SpotifyUtilitiesBuilder(
245245
}
246246

247247
data class SpotifyUtilities(
248-
val useCache: Boolean,
249-
val cacheLimit: Int?,
250-
val automaticRefresh: Boolean,
251-
val retryWhenRateLimited: Boolean,
252-
val enableLogger: Boolean,
253-
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
254254
)
255255

256256
/**
@@ -289,6 +289,20 @@ class SpotifyApiBuilderDsl {
289289
utilities = SpotifyUtilitiesBuilder().apply(block).build()
290290
}
291291

292+
/**
293+
* Allows you to override default values for caching, token refresh, and logging
294+
*/
295+
fun config(block: SpotifyUtilitiesBuilder.() -> Unit) {
296+
utilities = SpotifyUtilitiesBuilder().apply(block).build()
297+
}
298+
299+
/**
300+
* Allows you to override default values for caching, token refresh, and logging
301+
*/
302+
fun options(block: SpotifyUtilitiesBuilder.() -> Unit) {
303+
utilities = SpotifyUtilitiesBuilder().apply(block).build()
304+
}
305+
292306
/**
293307
* Create a Spotify authorization URL from which client access can be obtained
294308
*
@@ -398,9 +412,9 @@ class SpotifyApiBuilderDsl {
398412
* @param token [Token] object (useful if you already have exchanged an authorization code yourself
399413
*/
400414
private fun buildClient(
401-
authorizationCode: String? = null,
402-
tokenString: String? = null,
403-
token: Token? = null
415+
authorizationCode: String? = null,
416+
tokenString: String? = null,
417+
token: Token? = null
404418
): SpotifyClientAPI {
405419
val clientId = credentials.clientId
406420
val clientSecret = credentials.clientSecret
@@ -413,7 +427,7 @@ class SpotifyApiBuilderDsl {
413427
authorizationCode != null -> try {
414428
clientId ?: throw IllegalArgumentException()
415429
clientSecret ?: throw IllegalArgumentException()
416-
redirectUri ?: IllegalArgumentException()
430+
redirectUri ?: throw IllegalArgumentException()
417431

418432
val response = executeTokenRequest(HttpConnection(
419433
url = "https://accounts.spotify.com/api/token",
@@ -433,7 +447,7 @@ class SpotifyApiBuilderDsl {
433447
clientSecret,
434448
response.body.toObject(null),
435449
utilities.automaticRefresh,
436-
redirectUri ?: throw IllegalArgumentException("No redirect uri provided"),
450+
redirectUri,
437451
utilities.useCache,
438452
utilities.cacheLimit,
439453
utilities.retryWhenRateLimited,
@@ -482,5 +496,6 @@ class SpotifyApiBuilderDsl {
482496
}
483497

484498
enum class AuthorizationType {
485-
CLIENT, APPLICATION
499+
CLIENT,
500+
APPLICATION;
486501
}

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientLibraryAPI.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class ClientLibraryAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
185185
* @param id How to transform an id (or uri) input into its Spotify id
186186
*/
187187
enum class LibraryType(private val value: String, internal val id: (String) -> String) {
188-
TRACK("tracks", { TrackURI(it).id }), ALBUM("albums", { AlbumURI(it).id });
188+
TRACK("tracks", { TrackURI(it).id }),
189+
ALBUM("albums", { AlbumURI(it).id });
189190

190191
override fun toString() = value
191192
}

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPersonalizationAPI.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class ClientPersonalizationAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
2222
* @param id the Spotify id of the time frame
2323
*/
2424
enum class TimeRange(val id: String) {
25-
LONG_TERM("long_term"), MEDIUM_TERM("medium_term"), SHORT_TERM("short_term");
25+
LONG_TERM("long_term"),
26+
MEDIUM_TERM("medium_term"),
27+
SHORT_TERM("short_term");
2628

2729
override fun toString() = id
2830
}

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlayerAPI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,6 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
317317
/**
318318
* Will turn repeat off
319319
*/
320-
OFF
320+
OFF;
321321
}
322322
}

src/main/kotlin/com/adamratzman/spotify/endpoints/public/ArtistsAPI.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ class ArtistsAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
9595
* @param keyword The spotify id of the strategy
9696
*/
9797
enum class AlbumInclusionStrategy(val keyword: String) {
98-
ALBUM("album"), SINGLE("single"), APPEARS_ON("appears_on"), COMPILATION("compilation")
98+
ALBUM("album"),
99+
SINGLE("single"),
100+
APPEARS_ON("appears_on"),
101+
COMPILATION("compilation");
99102
}
100103

101104
/**

0 commit comments

Comments
 (0)