aboutsummaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt10
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt10
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt11
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt7
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt11
-rw-r--r--shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt16
6 files changed, 45 insertions, 20 deletions
diff --git a/shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt b/shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
new file mode 100644
index 0000000..8b43d20
--- /dev/null
+++ b/shared/src/androidMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
@@ -0,0 +1,10 @@
+package mx.trackermap.TrackerMap.client.infrastructure
+
+import io.ktor.client.*
+import io.ktor.client.engine.cio.*
+
+actual class HttpClientProvider {
+ actual fun getHttpClient(): HttpClient {
+ return HttpClient(CIO)
+ }
+} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt
index a5a893e..6d9dbea 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/apis/SessionApi.kt
@@ -11,13 +11,9 @@
*/
package mx.trackermap.TrackerMap.client.apis
-import com.russhwolf.settings.Settings
import mx.trackermap.TrackerMap.client.models.User
import mx.trackermap.TrackerMap.client.infrastructure.*
-const val SERVER_URL_KEY = "server_url"
-const val ACCESS_TOKEN_KEY = "access_token"
-
class SessionApi(sessionManager: SessionManager) : ApiClient(sessionManager) {
/**
@@ -36,8 +32,7 @@ class SessionApi(sessionManager: SessionManager) : ApiClient(sessionManager) {
return when (response.responseType) {
ResponseType.Success -> {
- val settings = Settings()
- settings.remove(ACCESS_TOKEN_KEY)
+ sessionManager.clearSession()
}
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
@@ -102,14 +97,13 @@ class SessionApi(sessionManager: SessionManager) : ApiClient(sessionManager) {
return when (response.responseType) {
ResponseType.Success -> {
+ print("Response headers = ${response.headers.values}\n")
val cookie = response.headers
.values
.flatten()
.find { it.contains("JSESSIONID") }!!
.replace("; Path=/", "")
this.sessionManager.token = cookie
- val settings = Settings()
- settings.putString(ACCESS_TOKEN_KEY, cookie)
(response as Success<*>).data as User
}
ResponseType.Informational -> TODO()
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
index 385ece4..78bcf3b 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/ApiClient.kt
@@ -17,7 +17,6 @@
*/
package mx.trackermap.TrackerMap.client.infrastructure
-import com.russhwolf.settings.Settings
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.features.*
@@ -32,8 +31,6 @@ import io.ktor.client.request.forms.FormDataContent
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.util.*
-import mx.trackermap.TrackerMap.client.apis.ACCESS_TOKEN_KEY
-import mx.trackermap.TrackerMap.client.apis.SERVER_URL_KEY
import kotlinx.serialization.json.Json as KotlinJson
open class ApiClient(
@@ -47,7 +44,7 @@ open class ApiClient(
protected const val ApiFormURLType = "application/x-www-form-urlencoded"
protected const val ApiXmlMediaType = "application/xml"
- val client: HttpClient = HttpClient {
+ val client: HttpClient = HttpClientProvider().getHttpClient().config {
install(HttpTimeout) {
connectTimeoutMillis = 20_000
requestTimeoutMillis = 20_000
@@ -71,12 +68,6 @@ open class ApiClient(
ApiContentType to ApiJsonMediaType,
ApiAccept to ApiJsonMediaType
)
-
- val jsonHeaders: Map<String, String> =
- mapOf(
- ApiContentType to ApiJsonMediaType,
- ApiAccept to ApiJsonMediaType
- )
}
protected inline fun <reified T> fillRequest(
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
new file mode 100644
index 0000000..873722f
--- /dev/null
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
@@ -0,0 +1,7 @@
+package mx.trackermap.TrackerMap.client.infrastructure
+
+import io.ktor.client.*
+
+expect class HttpClientProvider() {
+ fun getHttpClient(): HttpClient
+} \ No newline at end of file
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt
index 306533c..6287b0c 100644
--- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt
+++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/SessionManager.kt
@@ -3,13 +3,16 @@ package mx.trackermap.TrackerMap.client.infrastructure
import com.russhwolf.settings.Settings
import com.russhwolf.settings.get
import com.russhwolf.settings.set
-import mx.trackermap.TrackerMap.client.apis.ACCESS_TOKEN_KEY
-import mx.trackermap.TrackerMap.client.apis.SERVER_URL_KEY
class SessionManager(
private val defaultBaseUrl: String
) {
+ companion object {
+ const val SERVER_URL_KEY = "server_url"
+ const val ACCESS_TOKEN_KEY = "access_token"
+ }
+
private val settings = Settings()
var baseUrl: String
@@ -24,4 +27,8 @@ class SessionManager(
settings[ACCESS_TOKEN_KEY] = token
}
+ fun clearSession() {
+ settings.remove(ACCESS_TOKEN_KEY)
+ settings.remove(SERVER_URL_KEY)
+ }
} \ No newline at end of file
diff --git a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
new file mode 100644
index 0000000..1ccb2e6
--- /dev/null
+++ b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/client/infrastructure/HttpClientProvider.kt
@@ -0,0 +1,16 @@
+package mx.trackermap.TrackerMap.client.infrastructure
+
+import io.ktor.client.*
+import io.ktor.client.engine.ios.*
+
+actual class HttpClientProvider {
+ actual fun getHttpClient(): HttpClient {
+ return HttpClient(Ios) {
+ engine {
+ configureSession {
+ HTTPCookieStorage = null
+ }
+ }
+ }
+ }
+} \ No newline at end of file