Skip to content

Commit 90f0b31

Browse files
committed
move SpotifyBuilder methods and token retrieval methods into SpotifyApi
1 parent d29df93 commit 90f0b31

File tree

6 files changed

+320
-269
lines changed

6 files changed

+320
-269
lines changed

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

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +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
4+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyAppApi
5+
import com.adamratzman.spotify.SpotifyApi.Companion.spotifyClientApi
66
import com.adamratzman.spotify.http.HttpConnection
77
import com.adamratzman.spotify.http.HttpRequestMethod
88
import com.adamratzman.spotify.models.Token
@@ -17,104 +17,21 @@ import kotlinx.serialization.json.Json
1717

1818
// Kotlin DSL builders
1919

20-
@Deprecated("Builder methods are now found in SpotifyBuilder", ReplaceWith("SpotifyBuilder.spotifyAppApi"))
20+
@Deprecated("Builder methods are now found in SpotifyApi", ReplaceWith("SpotifyApi.spotifyAppApi"))
2121
fun spotifyAppApi(clientId: String, clientSecret: String, block: SpotifyAppApiBuilder.() -> Unit = {}) =
22-
SpotifyBuilder.spotifyAppApi(clientId, clientSecret, block)
22+
SpotifyApi.spotifyAppApi(clientId, clientSecret, block)
2323

24-
@Deprecated("Builder methods are now found in SpotifyBuilder", ReplaceWith("SpotifyBuilder.spotifyAppApi"))
24+
@Deprecated("Builder methods are now found in SpotifyApi", ReplaceWith("SpotifyApi.spotifyAppApi"))
2525
fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) =
26-
SpotifyBuilder.spotifyAppApi(block)
26+
SpotifyApi.spotifyAppApi(block)
2727

28-
@Deprecated("Builder methods are now found in SpotifyBuilder", ReplaceWith("SpotifyBuilder.spotifyClientApi"))
28+
@Deprecated("Builder methods are now found in SpotifyApi", ReplaceWith("SpotifyApi.spotifyClientApi"))
2929
fun spotifyAppApi(clientId: String, clientSecret: String, redirectUri: String, block: SpotifyClientApiBuilder.() -> Unit = {}) =
30-
SpotifyBuilder.spotifyClientApi(clientId, clientSecret, redirectUri, block)
30+
SpotifyApi.spotifyClientApi(clientId, clientSecret, redirectUri, block)
3131

32-
@Deprecated("Builder methods are now found in SpotifyBuilder", ReplaceWith("SpotifyBuilder.spotifyClientApi"))
32+
@Deprecated("Builder methods are now found in SpotifyApi", ReplaceWith("SpotifyApi.spotifyClientApi"))
3333
fun spotifyAppApi(block: SpotifyClientApiBuilder.() -> Unit) =
34-
SpotifyBuilder.spotifyClientApi(block)
35-
36-
/**
37-
* Contains static methods to instantiate [SpotifyAppApi] and [SpotifyClientApi] instances
38-
*/
39-
class SpotifyBuilder {
40-
companion object {
41-
/*
42-
App Api Builders
43-
*/
44-
45-
/**
46-
* Instantiate a new [SpotifyAppApiBuilder] using a Spotify [clientId] and [clientSecret], with the ability to configure
47-
* the api settings by providing a builder initialization [block]
48-
*
49-
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
50-
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
51-
* @param block Api settings block
52-
*
53-
* @return Configurable [SpotifyAppApiBuilder] that, when built, creates a new [SpotifyAppApi]
54-
*/
55-
fun spotifyAppApi(clientId: String, clientSecret: String, block: SpotifyAppApiBuilder.() -> Unit = {}) =
56-
SpotifyAppApiBuilder().apply(block).apply {
57-
credentials {
58-
this.clientId = clientId
59-
this.clientSecret = clientSecret
60-
}
61-
}
62-
63-
/**
64-
* Instantiate a new [SpotifyAppApiBuilder] by providing a builder initialization [block].
65-
*
66-
* **Note**: You **must** provide your app credentials in the [SpotifyAppApiBuilder.credentials] block
67-
*
68-
* @param block Api settings block
69-
*
70-
* @return Configurable [SpotifyAppApiBuilder] that, when built, creates a new [SpotifyAppApi]
71-
*/
72-
fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) = SpotifyAppApiBuilder().apply(block)
73-
74-
/*
75-
Client Api Builders
76-
*/
77-
78-
/**
79-
* Instantiate a new [SpotifyClientApiBuilder] using a Spotify [clientId], [clientSecret], and [redirectUri], with the ability to configure
80-
* the api settings by providing a builder initialization [block]
81-
*
82-
* **Note**: If trying to build [SpotifyClientApi], you **must** provide client authorization in the [SpotifyClientApiBuilder.authorization]
83-
* block
84-
*
85-
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
86-
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
87-
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
88-
* @param block Api settings block
89-
*
90-
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
91-
*/
92-
fun spotifyClientApi(
93-
clientId: String,
94-
clientSecret: String,
95-
redirectUri: String,
96-
block: SpotifyClientApiBuilder.() -> Unit
97-
) = SpotifyClientApiBuilder().apply(block).apply {
98-
credentials {
99-
this.clientId = clientId
100-
this.clientSecret = clientSecret
101-
this.redirectUri = redirectUri
102-
}
103-
}
104-
105-
/**
106-
* Instantiate a new [SpotifyClientApiBuilder] by providing a builder initialization [block]
107-
*
108-
* **Note**: If trying to build [SpotifyClientApi], you **must** provide client authorization in the [SpotifyClientApiBuilder.authorization]
109-
* block
110-
*
111-
* @param block Api settings block
112-
*
113-
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
114-
*/
115-
fun spotifyClientApi(block: SpotifyClientApiBuilder.() -> Unit) = SpotifyClientApiBuilder().apply(block)
116-
}
117-
}
34+
SpotifyApi.spotifyClientApi(block)
11835

11936
/**
12037
* Spotify API builder

0 commit comments

Comments
 (0)