-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
217 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
composeApp/src/androidMain/res/xml/network_security_config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<network-security-config> | ||
<domain-config cleartextTrafficPermitted="true"> | ||
<domain includeSubdomains="true">0.0.0.0</domain> | ||
</domain-config> | ||
</network-security-config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
shared/src/androidMain/kotlin/dev/rivu/courses/indiaconferences/remote/KtorClient.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.rivu.courses.indiaconferences.remote | ||
|
||
import android.util.Log | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.okhttp.OkHttp | ||
import io.ktor.client.plugins.HttpRequestRetry | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import isDebug | ||
import okhttp3.internal.platform.android.AndroidLogHandler.setLevel | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
|
||
actual val KtorClient: HttpClient by lazy { | ||
Log.d("SDK","KtorClient Android") | ||
|
||
HttpClient(OkHttp) { | ||
// default validation to throw exceptions for non-2xx responses | ||
expectSuccess = true | ||
|
||
engine { | ||
// add logging interceptor | ||
if (isDebug()) { | ||
addInterceptor( | ||
HttpLoggingInterceptor().apply { | ||
setLevel( | ||
HttpLoggingInterceptor.Level.BODY, | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
install(ContentNegotiation) { | ||
json | ||
} | ||
|
||
install(HttpRequestRetry) { | ||
retryConfig() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import dev.rivu.courses.indiaconferences.remote.KtorClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.get | ||
import io.ktor.client.statement.bodyAsText | ||
|
||
class Greeting { | ||
private val platform = getPlatform() | ||
|
||
fun greet(): String { | ||
return "Hello, ${platform.name}!" | ||
} | ||
|
||
suspend fun getResponseFromServer(): String { | ||
val response = KtorClient.get("http://0.0.0.0:8080") | ||
return response.bodyAsText() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
shared/src/commonMain/kotlin/dev/rivu/courses/indiaconferences/remote/KtorClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.rivu.courses.indiaconferences.remote | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.plugins.HttpRequestRetry.Configuration | ||
import kotlinx.serialization.json.Json | ||
|
||
|
||
expect val KtorClient: HttpClient | ||
|
||
|
||
val json = Json { | ||
ignoreUnknownKeys = true | ||
isLenient = true | ||
} | ||
|
||
fun Configuration.retryConfig() { | ||
retryOnServerErrors(maxRetries = 3) | ||
exponentialDelay() | ||
} |
6 changes: 6 additions & 0 deletions
6
shared/src/jvmMain/kotlin/dev/rivu/courses/indiaconferences/remote/KtorClient.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.rivu.courses.indiaconferences.remote | ||
|
||
import io.ktor.client.HttpClient | ||
|
||
actual val KtorClient: HttpClient | ||
get() = HttpClient() |
37 changes: 37 additions & 0 deletions
37
shared/src/nativeMain/kotlin/dev/rivu/courses/indiaconferences/remote/KtorClient.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dev.rivu.courses.indiaconferences.remote | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.darwin.Darwin | ||
import io.ktor.client.plugins.HttpRequestRetry | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logging | ||
import isDebug | ||
|
||
actual val KtorClient: HttpClient by lazy { | ||
HttpClient(Darwin) { | ||
// default validation to throw exceptions for non-2xx responses | ||
expectSuccess = true | ||
|
||
if (isDebug()) { | ||
install(Logging) { | ||
level = LogLevel.ALL | ||
} | ||
} | ||
|
||
engine { | ||
configureRequest { | ||
setAllowsCellularAccess(true) | ||
setAllowsExpensiveNetworkAccess(true) | ||
} | ||
} | ||
|
||
install(ContentNegotiation) { | ||
json | ||
} | ||
|
||
install(HttpRequestRetry) { | ||
retryConfig() | ||
} | ||
} | ||
} |