Skip to content

Commit a36ee08

Browse files
authored
Merge pull request #272 from adamint/dev
add ios/tvos targets
2 parents ac77c9e + 48003f9 commit a36ee08

File tree

13 files changed

+141
-54
lines changed

13 files changed

+141
-54
lines changed

build.gradle.kts

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.jetbrains.dokka.gradle.DokkaTask
22
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
3+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
34
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
45

56
plugins {
@@ -169,14 +170,48 @@ kotlin {
169170
setupPom(artifactId)
170171
}
171172
}
173+
ios {
174+
binaries {
175+
framework {
176+
baseName = "spotify"
177+
}
178+
}
179+
180+
mavenPublication {
181+
setupPom(artifactId)
182+
}
183+
}
184+
tvos {
185+
binaries {
186+
framework {
187+
baseName = "spotify"
188+
}
189+
}
190+
191+
mavenPublication {
192+
setupPom(artifactId)
193+
}
194+
}
195+
// disabled due to lack of coroutine/serialization library support (yet)
196+
/*watchos {
197+
binaries {
198+
framework {
199+
baseName = "spotify"
200+
}
201+
}
202+
203+
mavenPublication {
204+
setupPom(artifactId)
205+
}
206+
}*/
172207

173208
publishing {
174209
if ("local" !in (version as String)) registerPublishing()
175210
}
176211

177212
targets {
178213
sourceSets {
179-
val serializationVersion = "1.0.1"
214+
val serializationVersion = "1.1.0"
180215
val ktorVersion = "1.5.1"
181216
val korlibsVersion = "2.0.6"
182217
val sparkVersion = "2.9.3"
@@ -188,7 +223,7 @@ kotlin {
188223
dependencies {
189224
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
190225
implementation("io.ktor:ktor-client-core:$ktorVersion")
191-
implementation("com.soywiz.korlibs.klock:klock:$korlibsVersion")
226+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.1.1")
192227
implementation("com.soywiz.korlibs.krypto:krypto:$korlibsVersion")
193228
implementation("com.soywiz.korlibs.korim:korim:$korlibsVersion")
194229

@@ -313,6 +348,47 @@ kotlin {
313348
dependsOn(desktopTest)
314349
}
315350

351+
val nativeDarwinMain by creating {
352+
dependsOn(commonMain)
353+
354+
dependencies {
355+
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineMTVersion") {
356+
version {
357+
strictly(coroutineMTVersion)
358+
}
359+
}
360+
implementation("io.ktor:ktor-client-ios:$ktorVersion")
361+
}
362+
}
363+
364+
val nativeDarwinTest by creating {
365+
dependsOn(commonTest)
366+
}
367+
368+
val iosMain by getting {
369+
dependsOn(nativeDarwinMain)
370+
}
371+
372+
val iosTest by getting {
373+
dependsOn(nativeDarwinTest)
374+
}
375+
376+
val tvosMain by getting {
377+
dependsOn(nativeDarwinMain)
378+
}
379+
380+
val tvosTest by getting {
381+
dependsOn(nativeDarwinTest)
382+
}
383+
384+
/* val watchosMain by getting {
385+
dependsOn(nativeDarwinMain)
386+
}
387+
388+
val watchosTest by getting {
389+
dependsOn(nativeDarwinTest)
390+
}*/
391+
316392
all {
317393
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
318394
}
@@ -452,3 +528,18 @@ fun PublishingExtension.registerPublishing() {
452528
}
453529
}
454530
}
531+
532+
533+
val packForXcode by tasks.creating(Sync::class) {
534+
group = "build"
535+
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
536+
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
537+
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
538+
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
539+
inputs.property("mode", mode)
540+
dependsOn(framework.linkTask)
541+
val targetDir = File(buildDir, "xcode-frameworks")
542+
from({ framework.outputDirectory })
543+
into(targetDir)
544+
}
545+
tasks.getByName("build").dependsOn(packForXcode)

src/androidMain/kotlin/com/adamratzman/spotify/utils/PlatformUtils.kt

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

4-
import android.annotation.SuppressLint
54
import android.app.Activity
65
import android.content.Context
76
import android.util.Log
87
import android.widget.Toast
98
import java.net.URLEncoder
10-
import java.text.SimpleDateFormat
11-
import java.util.Date
129

1310
internal actual fun String.encodeUrl() = URLEncoder.encode(this, "UTF-8")!!
1411

15-
@SuppressLint("SimpleDateFormat")
16-
internal actual fun formatDate(format: String, date: Long): String {
17-
return SimpleDateFormat(format).format(Date(date))
18-
}
19-
2012
/**
2113
* Actual platform that this program is run on.
2214
*/

src/commonJvmLikeMain/kotlin/com/adamratzman/spotify/javainterop/SpotifyContinuation.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import kotlin.coroutines.EmptyCoroutineContext
1111
* on JVM via traditional continuations. **Please use this class as a callback anytime you are using Java code with this library.**
1212
*
1313
*/
14-
abstract class SpotifyContinuation<in T> : Continuation<T> {
14+
public abstract class SpotifyContinuation<in T> : Continuation<T> {
1515
/**
1616
* Invoke a function with the callback [value]
1717
*
1818
* @param value The value retrieved from the Spotify API.
1919
*/
20-
abstract fun onSuccess(value: T)
20+
public abstract fun onSuccess(value: T)
2121

2222
/**
2323
* Handle exceptions during this API call.
2424
*
2525
* @param exception The exception that was thrown during the call.
2626
*/
27-
abstract fun onFailure(exception: Throwable)
27+
public abstract fun onFailure(exception: Throwable)
2828

2929
override fun resumeWith(result: Result<T>) {
3030
result.fold(::onSuccess, ::onFailure)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class BrowseApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
101101
endpointBuilder("/browse/featured-playlists").with("limit", limit).with("offset", offset).with(
102102
"market",
103103
market?.name
104-
).with("locale", locale).with("timestamp", timestamp?.let { formatDate("yyyy-MM-dd'T'HH:mm:ss", it) }).toString()
104+
).with("locale", locale).with("timestamp", timestamp?.let { formatDate(it) }).toString()
105105
).toObject(FeaturedPlaylists.serializer(), api, json)
106106

107107
/**

src/commonMain/kotlin/com.adamratzman.spotify/utils/Utils.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package com.adamratzman.spotify.utils
33

44
import com.adamratzman.spotify.SpotifyException
55
import com.adamratzman.spotify.models.ResultEnum
6-
import com.soywiz.klock.DateTime
6+
import kotlinx.datetime.Clock
7+
import kotlinx.datetime.Instant
78
import kotlinx.serialization.json.JsonElement
89

910
/**
1011
* The current time in milliseconds since UNIX epoch.
1112
*/
12-
public fun getCurrentTimeMs(): Long = DateTime.nowUnixLong()
13+
public fun getCurrentTimeMs(): Long = Clock.System.now().toEpochMilliseconds()
1314

1415
internal fun jsonMap(vararg pairs: Pair<String, JsonElement>) = pairs.toMap().toMutableMap()
1516

@@ -26,4 +27,9 @@ internal suspend inline fun <T> catch(crossinline function: suspend () -> T): T?
2627
internal fun <T : ResultEnum> Array<T>.match(identifier: String) =
2728
firstOrNull { it.retrieveIdentifier().toString().equals(identifier, true) }
2829

29-
internal expect fun formatDate(format: String, date: Long): String
30+
/**
31+
* Format date to ISO 8601 format
32+
*/
33+
internal fun formatDate(date: Long): String {
34+
return Instant.fromEpochMilliseconds(date).toString()
35+
}

src/commonTest/kotlin/com.adamratzman/spotify/pub/BrowseApiTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.adamratzman.spotify.GenericSpotifyApi
55
import com.adamratzman.spotify.SpotifyException
66
import com.adamratzman.spotify.assertFailsWithSuspend
77
import com.adamratzman.spotify.buildSpotifyApi
8+
import com.adamratzman.spotify.clientId
89
import com.adamratzman.spotify.endpoints.public.TuneableTrackAttribute
910
import com.adamratzman.spotify.runBlockingTest
1011
import com.adamratzman.spotify.utils.Locale

src/jsMain/kotlin/com/adamratzman/spotify/utils/PlatformUtils.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
package com.adamratzman.spotify.utils
33

44
import io.ktor.http.encodeURLQueryComponent
5-
import kotlin.js.Date
65

76
internal actual fun String.encodeUrl() = encodeURLQueryComponent()
87

9-
internal actual fun formatDate(format: String, date: Long): String {
10-
return Date(date).toISOString()
11-
}
12-
138
/**
149
* Actual platform that this program is run on.
1510
*/

src/jvmMain/kotlin/com/adamratzman/spotify/utils/PlatformUtils.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
package com.adamratzman.spotify.utils
33

44
import java.net.URLEncoder
5-
import java.text.SimpleDateFormat
6-
import java.time.Instant
7-
import java.util.Date
8-
import java.util.Locale
95

106
internal actual fun String.encodeUrl() = URLEncoder.encode(this, "UTF-8")!!
117

12-
internal actual fun formatDate(format: String, date: Long): String {
13-
return SimpleDateFormat(format, Locale.getDefault()).format(Date.from(Instant.ofEpochMilli(date)))
14-
}
15-
168
/**
179
* The actual platform that this program is running on.
1810
*/

src/linuxX64Main/kotlin/com.adamratzman.spotify.utils/DesktopPlatformUtils.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/macosX64Main/kotlin/com.adamratzman.spotify.utils/DesktopPlatformUtils.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/mingwX64Main/kotlin/com.adamratzman.spotify.utils/DesktopPlatformUtils.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
2+
package com.adamratzman.spotify.utils
3+
4+
import io.ktor.http.encodeURLQueryComponent
5+
6+
internal actual fun String.encodeUrl() = encodeURLQueryComponent()
7+
8+
/**
9+
* Actual platform that this program is run on.
10+
*/
11+
public actual val currentApiPlatform: Platform = Platform.NATIVE
12+
13+
public actual typealias ConcurrentHashMap<K, V> = HashMap<K, V>
14+
15+
public actual fun <K, V> ConcurrentHashMap<K, V>.asList(): List<Pair<K, V>> = toList()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
2+
package com.adamratzman.spotify
3+
4+
import kotlin.coroutines.CoroutineContext
5+
import kotlinx.cinterop.toKString
6+
import kotlinx.coroutines.CoroutineScope
7+
import kotlinx.coroutines.MainScope
8+
import kotlinx.coroutines.runBlocking
9+
import platform.posix.getenv
10+
11+
actual fun getEnvironmentVariable(name: String): String? {
12+
return getenv(name)?.toKString()
13+
}
14+
15+
actual fun Exception.stackTrace() = printStackTrace()
16+
17+
actual val testCoroutineContext: CoroutineContext = MainScope().coroutineContext
18+
actual fun runBlockingTest(block: suspend CoroutineScope.() -> Unit) =
19+
runBlocking { this.block() }

0 commit comments

Comments
 (0)