Skip to content

Commit 94c4110

Browse files
committed
move builder methods to SpotifyBuilder companion object
1 parent 469c281 commit 94c4110

File tree

1 file changed

+80
-18
lines changed
  • src/commonMain/kotlin/com.adamratzman.spotify

1 file changed

+80
-18
lines changed

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

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify
33

4+
import com.adamratzman.spotify.SpotifyBuilder.Companion.spotifyAppApi
5+
import com.adamratzman.spotify.SpotifyBuilder.Companion.spotifyClientApi
46
import com.adamratzman.spotify.http.HttpConnection
57
import com.adamratzman.spotify.http.HttpRequestMethod
68
import com.adamratzman.spotify.models.Token
@@ -15,29 +17,89 @@ import kotlinx.serialization.json.Json
1517

1618
// Kotlin DSL builders
1719

18-
fun spotifyAppApi(clientId: String, clientSecret: String, block: SpotifyAppApiBuilder.() -> Unit = {}) =
19-
SpotifyAppApiBuilder().apply(block).apply {
20-
credentials {
21-
this.clientId = clientId
22-
this.clientSecret = clientSecret
20+
/**
21+
* Contains static methods to instantiate [SpotifyAppApi] and [SpotifyClientApi] instances
22+
*/
23+
class SpotifyBuilder {
24+
companion object {
25+
/*
26+
App Api Builders
27+
*/
28+
29+
/**
30+
* Instantiate a new [SpotifyAppApiBuilder] using a Spotify [clientId] and [clientSecret], with the ability to configure
31+
* the api settings by providing a builder initialization [block]
32+
*
33+
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
34+
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
35+
* @param block Api settings block
36+
*
37+
* @return Configurable [SpotifyAppApiBuilder] that, when built, creates a new [SpotifyAppApi]
38+
*/
39+
fun spotifyAppApi(clientId: String, clientSecret: String, block: SpotifyAppApiBuilder.() -> Unit = {}) =
40+
SpotifyAppApiBuilder().apply(block).apply {
41+
credentials {
42+
this.clientId = clientId
43+
this.clientSecret = clientSecret
44+
}
45+
}
46+
47+
/**
48+
* Instantiate a new [SpotifyAppApiBuilder] by providing a builder initialization [block].
49+
*
50+
* **Note**: You **must** provide your app credentials in the [SpotifyAppApiBuilder.credentials] block
51+
*
52+
* @param block Api settings block
53+
*
54+
* @return Configurable [SpotifyAppApiBuilder] that, when built, creates a new [SpotifyAppApi]
55+
*/
56+
fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) = SpotifyAppApiBuilder().apply(block)
57+
58+
/*
59+
Client Api Builders
60+
*/
61+
62+
/**
63+
* Instantiate a new [SpotifyClientApiBuilder] using a Spotify [clientId], [clientSecret], and [redirectUri], with the ability to configure
64+
* the api settings by providing a builder initialization [block]
65+
*
66+
* **Note**: If trying to build [SpotifyClientApi], you **must** provide client authorization in the [SpotifyClientApiBuilder.authorization]
67+
* block
68+
*
69+
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
70+
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
71+
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
72+
* @param block Api settings block
73+
*
74+
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
75+
*/
76+
fun spotifyClientApi(
77+
clientId: String,
78+
clientSecret: String,
79+
redirectUri: String,
80+
block: SpotifyClientApiBuilder.() -> Unit
81+
) = SpotifyClientApiBuilder().apply(block).apply {
82+
credentials {
83+
this.clientId = clientId
84+
this.clientSecret = clientSecret
85+
this.redirectUri = redirectUri
86+
}
2387
}
24-
}
2588

26-
fun spotifyClientApi(
27-
clientId: String,
28-
clientSecret: String,
29-
redirectUri: String,
30-
block: SpotifyClientApiBuilder.() -> Unit
31-
) = SpotifyClientApiBuilder().apply(block).apply {
32-
credentials {
33-
this.clientId = clientId
34-
this.clientSecret = clientSecret
35-
this.redirectUri = redirectUri
89+
/**
90+
* Instantiate a new [SpotifyClientApiBuilder] by providing a builder initialization [block]
91+
*
92+
* **Note**: If trying to build [SpotifyClientApi], you **must** provide client authorization in the [SpotifyClientApiBuilder.authorization]
93+
* block
94+
*
95+
* @param block Api settings block
96+
*
97+
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
98+
*/
99+
fun spotifyClientApi(block: SpotifyClientApiBuilder.() -> Unit) = SpotifyClientApiBuilder().apply(block)
36100
}
37101
}
38102

39-
fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) = SpotifyAppApiBuilder().apply(block)
40-
fun spotifyClientApi(block: SpotifyClientApiBuilder.() -> Unit) = SpotifyClientApiBuilder().apply(block)
41103

42104
/**
43105
* Spotify API builder

0 commit comments

Comments
 (0)