1
1
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
2
2
package com.adamratzman.spotify
3
3
4
+ import com.adamratzman.spotify.SpotifyBuilder.Companion.spotifyAppApi
5
+ import com.adamratzman.spotify.SpotifyBuilder.Companion.spotifyClientApi
4
6
import com.adamratzman.spotify.http.HttpConnection
5
7
import com.adamratzman.spotify.http.HttpRequestMethod
6
8
import com.adamratzman.spotify.models.Token
@@ -15,29 +17,89 @@ import kotlinx.serialization.json.Json
15
17
16
18
// Kotlin DSL builders
17
19
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
+ }
23
87
}
24
- }
25
88
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)
36
100
}
37
101
}
38
102
39
- fun spotifyAppApi (block : SpotifyAppApiBuilder .() -> Unit ) = SpotifyAppApiBuilder ().apply (block)
40
- fun spotifyClientApi (block : SpotifyClientApiBuilder .() -> Unit ) = SpotifyClientApiBuilder ().apply (block)
41
103
42
104
/* *
43
105
* Spotify API builder
0 commit comments