Skip to content

Commit 731fb78

Browse files
authored
Merge pull request #124 from adamint/dev
Split dsl builder into two distinct builders, fix cache concurrency problems
2 parents e239e72 + 05e6ce9 commit 731fb78

File tree

13 files changed

+553
-438
lines changed

13 files changed

+553
-438
lines changed

README.md

Lines changed: 11 additions & 10 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.08'
31+
compile group: 'com.adamratzman', name: 'spotify-api-kotlin', version: '3.0.0'
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.08</version>
53+
<version>3.0.0</version>
5454
</dependency>
5555
5656
<repository>
@@ -79,12 +79,12 @@ To build a new `SpotifyAPI`, you must pass the application id and secret.
7979
import com.adamratzman.spotify.SpotifyScope
8080
import com.adamratzman.spotify.spotifyApi
8181

82-
spotifyApi {
82+
val spotifyApi: SpotifyAPI = spotifyAppApi {
8383
credentials {
8484
clientId = "YOUR_CLIENT_ID"
8585
clientSecret = "YOUR_CLIENT_SECRET"
8686
}
87-
}.buildCredentialed()
87+
}.build()
8888
```
8989
*Note:* You are **unable** to use any client endpoint without authenticating with the methods below.
9090

@@ -97,7 +97,7 @@ an authorization code or a `Token` object. Otherwise, it will expire `Token.expi
9797
You have two options when building the Client API.
9898
1. You can use [Implicit Grant access tokens](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow) by
9999
setting the value of `tokenString` in the builder `authentication` block. However, this is a one-time token that cannot be refreshed.
100-
2. You can use the [Authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) by
100+
2. You can use the [Authorization code flow](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow) by
101101
setting the value of `authorizationCode` in a builder. You may generate an authentication flow url allowing you to request specific
102102
Spotify scopes using the `getAuthorizationUrl` method in any builder. This library does not provide a method to retrieve the code from your
103103
callback URL; you must implement that with a web server.
@@ -156,18 +156,18 @@ the synchronous format is also shown.
156156
import com.adamratzman.spotify.SpotifyScope
157157
import com.adamratzman.spotify.spotifyApi
158158

159-
val api = spotifyApi {
159+
val api: SpotifyAPI = spotifyAppApi {
160160
credentials {
161161
clientId = "YOUR_CLIENT_ID"
162162
clientSecret = "YOUR_CLIENT_SECRET"
163163
}
164-
}.buildCredentialed()
164+
}.build()
165165

166166
// block and print out the names of the twenty most similar songs to the search
167-
println(api.search.searchTrack("Début de la Suite").complete().map { it.name }.joinToString())
167+
println(api.search.searchTrack("Début de la Suite").complete().joinToString { it.name })
168168

169169
// now, let's do it asynchronously
170-
api.search.searchTrack("Début de la Suite").queue { println(it.map { it.name }.joinToString()) }
170+
api.search.searchTrack("Début de la Suite").queue { tracks -> println(tracks.joinToString { track -> track.name }) }
171171

172172
// simple, right? what about if we want to print out the featured playlists message from the "Overview" tab?
173173
println(api.browse.getFeaturedPlaylists().complete().message)
@@ -176,6 +176,7 @@ println(api.browse.getFeaturedPlaylists().complete().message)
176176
// let's find out Bénabar's Spotify ID, find his top tracks, and print them out
177177

178178
val benabarId = api.search.searchArtist("Bénabar").complete()[0].id
179+
// this works, but a better way would be: api.artists.getArtist("spotify:artist:6xoAWsIOZxJVPpo7Qvqaqv").complete().id
179180

180181
println(api.artists.getArtistTopTracks(benabarId).complete().joinToString { it.name })
181182
```
@@ -189,7 +190,7 @@ In both Track and SimpleTrack objects in an endpoint response, there is a nullab
189190
If the track is unable to be played in the specified market and there is an alternative that *is* playable, this
190191
will be populated with the href, uri, and, most importantly, the id of the track.
191192

192-
You can then use this track in `SpotifyClientAPI` actions such as playing or saving the track, knowing that it will be playable
193+
You can then use this track in `SpotifyClientAPI` endpoints such as playing or saving the track, knowing that it will be playable
193194
in your market!
194195

195196
### Contributing

build.gradle

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.41'
3-
ext.dokka_version = '0.9.17'
2+
ext.kotlin_version = '1.3.50'
3+
ext.dokka_version = '0.10.0'
44
ext.junit_version = '5.5.1'
5+
ext.moshi_version = '1.8.0'
6+
ext.json_version = '20190722'
7+
ext.google_http_client_version = '1.32.1'
8+
ext.spek_version = '2.0.8'
59

610
repositories { jcenter() }
711

@@ -12,17 +16,17 @@ buildscript {
1216
}
1317

1418
plugins {
15-
id "com.diffplug.gradle.spotless" version "3.24.0"
19+
id "com.diffplug.gradle.spotless" version "3.25.0"
1620
id "base"
17-
id "io.codearte.nexus-staging" version "0.21.0"
21+
id "io.codearte.nexus-staging" version "0.21.1"
1822
id "com.bmuschko.nexus" version "2.3.1"
1923
}
2024

2125
apply plugin: 'kotlin'
2226
apply plugin: 'org.jetbrains.dokka'
2327

2428
group 'com.adamratzman'
25-
version '2.3.08'
29+
version '3.0.0-rc.2'
2630

2731
archivesBaseName = 'spotify-api-kotlin'
2832

@@ -32,50 +36,58 @@ repositories {
3236

3337
dependencies {
3438
// Actual library dependencies
35-
compile 'com.neovisionaries:nv-i18n:1.25'
39+
compile 'com.neovisionaries:nv-i18n:1.26'
3640

37-
compile "com.squareup.moshi:moshi:1.8.0"
38-
compile "com.squareup.moshi:moshi-kotlin:1.8.0"
39-
compile group: 'org.json', name: 'json', version: '20190722'
41+
compile "com.squareup.moshi:moshi:$moshi_version"
42+
compile "com.squareup.moshi:moshi-kotlin:$moshi_version"
43+
compile "org.json:json:$json_version"
4044

41-
compile "com.google.http-client:google-http-client:1.31.0"
45+
compile "com.google.http-client:google-http-client:$google_http_client_version"
4246

4347
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4448
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
45-
49+
4650
// Spek testing requirements
47-
testCompile('org.spekframework.spek2:spek-dsl-jvm:2.0.0') {
51+
testCompile("org.spekframework.spek2:spek-dsl-jvm:$spek_version") {
4852
exclude group: 'org.jetbrains.kotlin'
4953
}
50-
testRuntimeOnly('org.spekframework.spek2:spek-runner-junit5:2.0.0') {
54+
55+
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spek_version") {
5156
exclude group: 'org.junit.platform'
5257
exclude group: 'org.jetbrains.kotlin'
5358
}
54-
59+
5560
testCompile "org.junit.jupiter:junit-jupiter-api:$junit_version"
56-
testCompile "org.json:json:20180130"
61+
testCompile "com.google.code.gson:gson:2.8.5"
5762
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
5863
}
5964

6065
dokka {
6166
outputFormat = 'javadoc'
6267
outputDirectory = 'docs'
6368

64-
jdkVersion = 8
65-
includeNonPublic = false
66-
impliedPlatforms = ["JVM"]
69+
configuration {
70+
jdkVersion = 8
71+
includeNonPublic = false
72+
impliedPlatforms = ["JVM"]
6773

68-
linkMapping {
69-
dir = "src/main/kotlin"
70-
url = "https://github.com/adamint/spotify-web-api-kotlin/tree/master/src/main/kotlin"
71-
suffix = "#L"
74+
sourceLink {
75+
path = "src/main/kotlin"
76+
url = "https://github.com/adamint/spotify-web-api-kotlin/tree/master/src/main/kotlin"
77+
lineSuffix = "#L"
78+
}
79+
80+
externalDocumentationLink {
81+
url = new URL("https://adamint.github.io/spotify-web-api-kotlin/")
82+
}
7283
}
7384
}
7485

7586
spotless {
7687
kotlin {
7788
ktlint()
78-
licenseHeader '/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */' // License header
89+
licenseHeader '/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */'
90+
// License header
7991
}
8092
}
8193

docs/com/adamratzman/spotify/SpotifyApiBuilderDsl.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ <h3>Method Summary</h3>
189189
</tr>
190190
<tr id="i5" class="rowColor">
191191
<td class="colFirst"><code>void</code></td>
192-
<td class="colLast"><code><span class="memberNameLink"><a href="../../../com/adamratzman/spotify/SpotifyApiBuilderDsl.html#config-block-">config</a></span>(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyUtilitiesBuilder,kotlin.Unit&gt;&nbsp;block)</code>
192+
<td class="colLast"><code><span class="memberNameLink"><a href="../../../com/adamratzman/spotify/SpotifyApiBuilderDsl.html#config-block-">config</a></span>(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyApiOptionsBuilder,kotlin.Unit&gt;&nbsp;block)</code>
193193
<div class="block">Allows you to override default values for caching, token refresh, and logging</div>
194194
</td>
195195
</tr>
@@ -208,13 +208,13 @@ <h3>Method Summary</h3>
208208
</tr>
209209
<tr id="i8" class="altColor">
210210
<td class="colFirst"><code>void</code></td>
211-
<td class="colLast"><code><span class="memberNameLink"><a href="../../../com/adamratzman/spotify/SpotifyApiBuilderDsl.html#options-block-">options</a></span>(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyUtilitiesBuilder,kotlin.Unit&gt;&nbsp;block)</code>
211+
<td class="colLast"><code><span class="memberNameLink"><a href="../../../com/adamratzman/spotify/SpotifyApiBuilderDsl.html#options-block-">options</a></span>(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyApiOptionsBuilder,kotlin.Unit&gt;&nbsp;block)</code>
212212
<div class="block">Allows you to override default values for caching, token refresh, and logging</div>
213213
</td>
214214
</tr>
215215
<tr id="i9" class="rowColor">
216216
<td class="colFirst"><code>void</code></td>
217-
<td class="colLast"><code><span class="memberNameLink"><a href="../../../com/adamratzman/spotify/SpotifyApiBuilderDsl.html#utilities-block-">utilities</a></span>(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyUtilitiesBuilder,kotlin.Unit&gt;&nbsp;block)</code>
217+
<td class="colLast"><code><span class="memberNameLink"><a href="../../../com/adamratzman/spotify/SpotifyApiBuilderDsl.html#utilities-block-">utilities</a></span>(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyApiOptionsBuilder,kotlin.Unit&gt;&nbsp;block)</code>
218218
<div class="block">Allows you to override default values for caching, token refresh, and logging</div>
219219
</td>
220220
</tr>
@@ -288,7 +288,7 @@ <h4>authentication</h4>
288288
<ul class="blockList">
289289
<li class="blockList">
290290
<h4>utilities</h4>
291-
<pre>public&nbsp;void&nbsp;utilities(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyUtilitiesBuilder,kotlin.Unit&gt;&nbsp;block)</pre>
291+
<pre>public&nbsp;void&nbsp;utilities(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyApiOptionsBuilder,kotlin.Unit&gt;&nbsp;block)</pre>
292292
<div class="block"><p><p>Allows you to override default values for caching, token refresh, and logging</p></p></div>
293293
</li>
294294
</ul>
@@ -298,7 +298,7 @@ <h4>utilities</h4>
298298
<ul class="blockList">
299299
<li class="blockList">
300300
<h4>config</h4>
301-
<pre>public&nbsp;void&nbsp;config(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyUtilitiesBuilder,kotlin.Unit&gt;&nbsp;block)</pre>
301+
<pre>public&nbsp;void&nbsp;config(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyApiOptionsBuilder,kotlin.Unit&gt;&nbsp;block)</pre>
302302
<div class="block"><p><p>Allows you to override default values for caching, token refresh, and logging</p></p></div>
303303
</li>
304304
</ul>
@@ -308,7 +308,7 @@ <h4>config</h4>
308308
<ul class="blockList">
309309
<li class="blockList">
310310
<h4>options</h4>
311-
<pre>public&nbsp;void&nbsp;options(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyUtilitiesBuilder,kotlin.Unit&gt;&nbsp;block)</pre>
311+
<pre>public&nbsp;void&nbsp;options(kotlin.jvm.functions.Function1&lt;? super com.adamratzman.spotify.SpotifyApiOptionsBuilder,kotlin.Unit&gt;&nbsp;block)</pre>
312312
<div class="block"><p><p>Allows you to override default values for caching, token refresh, and logging</p></p></div>
313313
</li>
314314
</ul>

docs/com/adamratzman/spotify/SpotifyUtilities.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
77
<title>SpotifyUtilities</title>
88
<meta name="date" content="2019-08-13">
9-
<meta name="keywords" content="com.adamratzman.spotify.SpotifyUtilities class">
9+
<meta name="keywords" content="com.adamratzman.spotify.SpotifyApiOptions class">
1010
<meta name="keywords" content="getUseCache()">
1111
<meta name="keywords" content="getCacheLimit()">
1212
<meta name="keywords" content="getAutomaticRefresh()">
@@ -114,7 +114,7 @@ <h2 title="Class SpotifyUtilities" class="title">Class SpotifyUtilities</h2>
114114
</div>
115115
<div class="contentContainer">
116116
<ul class="inheritance">
117-
<li>com.adamratzman.spotify.SpotifyUtilities</li>
117+
<li>com.adamratzman.spotify.SpotifyApiOptions</li>
118118
</ul>
119119
<div class="description">
120120
<ul class="blockList">

docs/com/adamratzman/spotify/SpotifyUtilitiesBuilder.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
77
<title>SpotifyUtilitiesBuilder</title>
88
<meta name="date" content="2019-08-13">
9-
<meta name="keywords" content="com.adamratzman.spotify.SpotifyUtilitiesBuilder class">
9+
<meta name="keywords" content="com.adamratzman.spotify.SpotifyApiOptionsBuilder class">
1010
<meta name="keywords" content="build()">
1111
<meta name="keywords" content="getUseCache()">
1212
<meta name="keywords" content="setUseCache()">
@@ -113,7 +113,7 @@ <h2 title="Class SpotifyUtilitiesBuilder" class="title">Class SpotifyUtilitiesBu
113113
</div>
114114
<div class="contentContainer">
115115
<ul class="inheritance">
116-
<li>com.adamratzman.spotify.SpotifyUtilitiesBuilder</li>
116+
<li>com.adamratzman.spotify.SpotifyApiOptionsBuilder</li>
117117
</ul>
118118
<div class="description">
119119
<ul class="blockList">

0 commit comments

Comments
 (0)