-
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.
[#18] Add Napier, fix network call on the wrong client
- Loading branch information
Showing
13 changed files
with
66 additions
and
32 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
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
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
35 changes: 24 additions & 11 deletions
35
shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/data/network/helpers/TargetType.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 |
---|---|---|
@@ -1,23 +1,36 @@ | ||
package co.nimblehq.blisskmmic.data.network.helpers | ||
|
||
import co.nimblehq.blisskmmic.BuildKonfig | ||
import io.ktor.client.request.* | ||
import io.ktor.http.* | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import kotlinx.serialization.json.jsonObject | ||
|
||
interface TargetType { | ||
interface TargetType<T> { | ||
|
||
val path: String | ||
val method: HttpMethod | ||
val body: Any? | ||
val headers: Map<String, String>? | ||
val body: T? | ||
} | ||
|
||
val requestBuilder: HttpRequestBuilder | ||
get() { | ||
val builder = HttpRequestBuilder() | ||
builder.url("$BuildKonfig.BASE_URL$API_VERSION$path") | ||
builder.method = method | ||
builder.contentType(ContentType.Application.Json) | ||
inline fun <reified T> TargetType<T>.requestBuilder(): HttpRequestBuilder { | ||
val builder = HttpRequestBuilder() | ||
builder.url("https://survey-api.nimblehq.co$API_VERSION$path") | ||
builder.method = method | ||
builder.contentType(ContentType.Application.Json) | ||
if (method == HttpMethod.Get) { | ||
builder.setQueryParameters(body) | ||
} else { | ||
builder.setBody(body) | ||
return builder | ||
} | ||
return builder | ||
} | ||
|
||
inline fun <reified T> HttpRequestBuilder.setQueryParameters(parameters: T?) { | ||
parameters?.run { | ||
val queryParameters = Json.encodeToJsonElement(this).jsonObject | ||
for ((key, value) in queryParameters) { | ||
parameter(key, value) | ||
} | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/di/koin/constants/Koin+Constants.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package co.nimblehq.blisskmmic.di.koin.constants | ||
|
||
const val TOKENIZED_NETWORK_CLIENT_KOIN = "TOKENIZED_NETWORK_CLIENT_KOIN" | ||
const val NETWORK_CLIENT_KOIN = "NETWORK_CLIENT_KOIN" |
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