@@ -13,8 +13,57 @@ import java.util.concurrent.TimeUnit
1313
1414internal val base = " https://api.spotify.com/v1"
1515
16+ // Kotlin DSL builder
1617fun spotifyApi (block : SpotifyApiBuilder .() -> Unit ) = SpotifyApiBuilder ().apply (block)
1718
19+ // Java-friendly builder
20+ class SpotifyApiBuilderJava (val clientId : String , val clientSecret : String ) {
21+ var redirectUri: String? = null
22+ var authorizationCode: String? = null
23+ var tokenString: String? = null
24+ var token: Token ? = null
25+
26+ fun redirectUri (redirectUri : String? ): SpotifyApiBuilderJava {
27+ this .redirectUri = redirectUri
28+ return this
29+ }
30+
31+ fun authorizationCode (authorizationCode : String? ): SpotifyApiBuilderJava {
32+ this .authorizationCode = authorizationCode
33+ return this
34+ }
35+
36+ fun tokenString (tokenString : String? ): SpotifyApiBuilderJava {
37+ this .tokenString = tokenString
38+ return this
39+ }
40+
41+ fun token (token : Token ? ): SpotifyApiBuilderJava {
42+ this .token = token
43+ return this
44+ }
45+
46+ fun buildCredentialed () = spotifyApi {
47+ credentials {
48+ clientId = this @SpotifyApiBuilderJava.clientId
49+ clientSecret = this @SpotifyApiBuilderJava.clientSecret
50+ }
51+ }.buildCredentialed()
52+
53+ fun buildClient (automaticRefresh : Boolean =false) = spotifyApi {
54+ credentials{
55+ clientId = this @SpotifyApiBuilderJava.clientId
56+ clientSecret = this @SpotifyApiBuilderJava.clientSecret
57+ redirectUri = this @SpotifyApiBuilderJava.redirectUri
58+ }
59+ clientAuthentication {
60+ authorizationCode = this @SpotifyApiBuilderJava.authorizationCode
61+ tokenString = this @SpotifyApiBuilderJava.tokenString
62+ token = this @SpotifyApiBuilderJava.token
63+ }
64+ }.buildClient(automaticRefresh)
65+ }
66+
1867/* *
1968 * @property clientId the client id of your Spotify application
2069 * @property clientSecret the client secret of your Spotify application
0 commit comments