Skip to content

Commit 4a6c59f

Browse files
committed
expose ktor and coroutines at compile time
1 parent 52dba8e commit 4a6c59f

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ kotlin {
6464
val commonMain by getting {
6565
dependencies {
6666
implementation(kotlin("stdlib-common"))
67-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutineVersion")
67+
api("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutineVersion")
6868
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion")
69-
implementation("io.ktor:ktor-client-core:$ktorVersion")
69+
api("io.ktor:ktor-client-core:$ktorVersion")
7070
}
7171
}
7272
val commonTest by getting {
@@ -84,9 +84,9 @@ kotlin {
8484
}
8585

8686
dependencies {
87-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
87+
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
8888
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializationVersion")
89-
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
89+
api("io.ktor:ktor-client-okhttp:$ktorVersion")
9090
implementation("commons-codec:commons-codec:1.14")
9191
implementation(kotlin("stdlib-jdk8"))
9292
}
@@ -106,9 +106,9 @@ kotlin {
106106
val jsMain by getting {
107107
dependencies {
108108
implementation(npm("text-encoding", "0.7.0"))
109-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutineVersion")
109+
api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutineVersion")
110110
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serializationVersion")
111-
implementation("io.ktor:ktor-client-js:$ktorVersion")
111+
api("io.ktor:ktor-client-js:$ktorVersion")
112112
implementation(npm("abort-controller", "3.0.0"))
113113
implementation(npm("node-fetch", "2.6.0"))
114114

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ typealias SpotifyClientAPI = SpotifyClientApi
687687
@Deprecated("API name has been updated for kotlin convention consistency", ReplaceWith("SpotifyAppApi"))
688688
typealias SpotifyAppAPI = SpotifyAppApi
689689

690+
/**
691+
* Represents a generic instance of the Spotify API client, with common functionality and information between
692+
* implementations of the API
693+
*/
690694
typealias GenericSpotifyApi = SpotifyApi<*, *>
691695

692696
/**

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/public/SearchApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typealias SearchAPI = SearchApi
3131

3232
/**
3333
* Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string.
34+
* It is possible to have 0 results and no exception thrown with these methods. Check the size of items returned.
3435
*
3536
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/search/search/)**
3637
*/

src/commonMain/kotlin/com.adamratzman.spotify/http/Endpoints.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ abstract class SpotifyEndpoint(val api: GenericSpotifyApi) {
6363
contentType: String? = null,
6464
attemptedRefresh: Boolean = false
6565
): String {
66-
if (getCurrentTimeMs() >= api.expireTime) {
66+
if (api.token.shouldRefresh()) {
6767
if (!api.automaticRefresh) throw SpotifyException.AuthenticationException("The access token has expired.")
6868
else api.refreshToken()
6969
}
@@ -94,6 +94,8 @@ abstract class SpotifyEndpoint(val api: GenericSpotifyApi) {
9494
)
9595
} catch (e: BadRequestException) {
9696
if (e.statusCode?.equals(401) == true && !attemptedRefresh) {
97+
api.refreshToken()
98+
9799
execute(
98100
url,
99101
body,

0 commit comments

Comments
 (0)