Skip to content

Commit 7a7ce43

Browse files
committed
Consolidate builders and DSLs to use common interface bases #122 #116
- Disable automatic token refresh by default - Split spotifyApi(block) function into spotifyAppApi(..) and spotifyClientApi(..) - Remove redundant logic shared between DSL builders and SpotifyApiBuilder
1 parent 8be17ad commit 7a7ce43

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ To build a new `SpotifyAPI`, you must pass the application id and secret.
8080
import com.adamratzman.spotify.SpotifyScope
8181
import com.adamratzman.spotify.spotifyApi
8282

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

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

160-
val api = spotifyApi {
160+
val api: SpotifyAPI = spotifyAppApi {
161161
credentials {
162162
clientId = "YOUR_CLIENT_ID"
163163
clientSecret = "YOUR_CLIENT_SECRET"
164164
}
165-
}.buildCredentialed()
165+
}.build()
166166

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

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

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

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

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

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

196197
### Contributing

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)