Skip to content

Commit

Permalink
Merge pull request #147 from lhoracek/feature/ios_support
Browse files Browse the repository at this point in the history
Add iOS targets
  • Loading branch information
jillesvangurp authored Jul 11, 2024
2 parents 9641454 + 708fc2e commit 8165076
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 1 deletion.
19 changes: 18 additions & 1 deletion search-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ kotlin {
mingwX64()
macosX64()
macosArm64()
// iOS targets
iosArm64()
iosX64()
// Blocked on json-dsl and kotlinx-serialization-extensions support
// iosSimulatorArm64()
// Blocked on ktor-client support
// wasmJs {
// browser()
Expand Down Expand Up @@ -155,7 +160,19 @@ kotlin {
}
}

nativeMain {
iosMain {
dependencies {
implementation(Ktor.client.darwin)
}
}

macosMain {
dependencies {
implementation(Ktor.client.darwin)
}
}

mingwMain {
dependencies {
implementation(Ktor.client.curl)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.jillesvangurp.ktsearch

import com.jillesvangurp.serializationext.DEFAULT_JSON
import io.ktor.client.*
import io.ktor.client.plugins.auth.*
import io.ktor.client.plugins.auth.providers.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*


import io.ktor.client.*
import io.ktor.client.engine.darwin.*

actual fun defaultKtorHttpClient(
logging: Boolean,
user: String?,
password: String?,
elasticApiKey: String?
): HttpClient {
return HttpClient(Darwin) {
engine {
pipelining = true
configureRequest {
setAllowsCellularAccess(true)
}
}
if(!user.isNullOrBlank() && !password.isNullOrBlank()) {
install(Auth) {
basic {
credentials {
BasicAuthCredentials(user, password)
}
sendWithoutRequest {
true
}
}
}
}
if(!elasticApiKey.isNullOrBlank()) {
headers {
append("Authorization", "ApiKey $elasticApiKey")
}
}
install(ContentNegotiation) {
json(DEFAULT_JSON)
}
if (logging) {
install(Logging) {
level = LogLevel.ALL
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.jillesvangurp.ktsearch

import com.jillesvangurp.serializationext.DEFAULT_JSON
import io.ktor.client.*
import io.ktor.client.plugins.auth.*
import io.ktor.client.plugins.auth.providers.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*


import io.ktor.client.*
import io.ktor.client.engine.darwin.*

actual fun defaultKtorHttpClient(
logging: Boolean,
user: String?,
password: String?,
elasticApiKey: String?
): HttpClient {
return HttpClient(Darwin) {
engine {
pipelining = true
configureRequest {
setAllowsCellularAccess(true)
}
}
if(!user.isNullOrBlank() && !password.isNullOrBlank()) {
install(Auth) {
basic {
credentials {
BasicAuthCredentials(user, password)
}
sendWithoutRequest {
true
}
}
}
}
if(!elasticApiKey.isNullOrBlank()) {
headers {
append("Authorization", "ApiKey $elasticApiKey")
}
}
install(ContentNegotiation) {
json(DEFAULT_JSON)
}
if (logging) {
install(Logging) {
level = LogLevel.ALL
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jillesvangurp.ktsearch

actual fun simpleIndexProvider(initialIndex: Int): IndexProvider = object : IndexProvider {
private var index = 0

override fun get(): Int = index

override fun set(value: Int) {
index = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jillesvangurp.ktsearch

/**
* On JVM this will return the current thread name, otherwise this will return null and pick a random node
*/
actual fun threadId(): String? = null
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jillesvangurp.ktsearch

actual fun simpleIndexProvider(initialIndex: Int): IndexProvider = object : IndexProvider {
private var index = 0

override fun get(): Int = index

override fun set(value: Int) {
index = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jillesvangurp.ktsearch

/**
* On JVM this will return the current thread name, otherwise this will return null and pick a random node
*/
actual fun threadId(): String? = null
4 changes: 4 additions & 0 deletions search-dsls/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ kotlin {
mingwX64()
macosX64()
macosArm64()
iosArm64()
iosX64()
// Blocked on json-dsl and kotlinx-serialization-extensions support
// iosSimulatorArm64()
wasmJs {
browser()
nodejs()
Expand Down

0 comments on commit 8165076

Please sign in to comment.