Skip to content

Commit

Permalink
Remove deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso committed Dec 14, 2023
1 parent d8f123a commit 1cc97de
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CallConverterFactory : Converter.Factory {
val convertedBody = ktorfit.nextSuspendResponseConverter(
null,
typeData.typeArgs.first()
)?.convert(response)
)?.convert(KtorfitResult.Success(response))
?: response.body(typeData.typeArgs.first().typeInfo)
callBack.onResponse(convertedBody, response)
} catch (ex: Exception) {
Expand All @@ -42,9 +42,6 @@ public class CallConverterFactory : Converter.Factory {

private class CallSuspendResponseConverter(val typeData: TypeData, val ktorfit: Ktorfit) :
Converter.SuspendResponseConverter<HttpResponse, Call<Any?>> {
override suspend fun convert(response: HttpResponse): Call<Any?> {
return convert(KtorfitResult.Success(response))
}

override suspend fun convert(result: KtorfitResult): Call<Any?> {
return object : Call<Any?> {
Expand All @@ -57,7 +54,7 @@ public class CallConverterFactory : Converter.Factory {
val data = ktorfit.nextSuspendResponseConverter(
null,
typeData.typeArgs.first()
)?.convert(response)
)?.convert(result)
callBack.onResponse(data!!, response)
} catch (ex: Exception) {
callBack.onError(ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.jensklingenberg.ktorfit.converter.builtin

import de.jensklingenberg.ktorfit.Ktorfit
import de.jensklingenberg.ktorfit.converter.Converter
import de.jensklingenberg.ktorfit.converter.KtorfitResult
import de.jensklingenberg.ktorfit.converter.TypeData
import io.ktor.client.call.*
import io.ktor.client.statement.*
Expand Down Expand Up @@ -31,7 +32,7 @@ public class FlowConverterFactory : Converter.Factory {
val convertedBody = ktorfit.nextSuspendResponseConverter(
this@FlowConverterFactory,
typeData.typeArgs.first()
)?.convert(response)
)?.convert(KtorfitResult.Success(response))
?: response.body(typeData.typeArgs.first().typeInfo)
emit(convertedBody)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import io.ktor.client.statement.*

internal class DefaultResponseClassSuspendConverter(private val typeData: TypeData, private val ktorfit: Ktorfit) :
Converter.SuspendResponseConverter<HttpResponse, Response<Any?>> {
override suspend fun convert(response: HttpResponse): Response<Any?> {
return convert(KtorfitResult.Success(response))
}

override suspend fun convert(result: KtorfitResult): Response<Any?> {
return when (result) {
Expand All @@ -34,7 +31,7 @@ internal class DefaultResponseClassSuspendConverter(private val typeData: TypeDa
val convertedBody = ktorfit.nextSuspendResponseConverter(
null,
typeData.typeArgs.first()
)?.convert(rawResponse)
)?.convert(result)
?: rawResponse.body(typeInfo)
Response.success(convertedBody, rawResponse)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.kotlinpoet.ClassName
data class KtorfitClass(val name: String, val packageName: String, val objectName: String)

val ktorfitClass = KtorfitClass("Ktorfit", "de.jensklingenberg.ktorfit", "_ktorfit")
val typeDataClass = KtorfitClass("TypeData", "de.jensklingenberg.ktorfit.internal", "_typeData")
val typeDataClass = KtorfitClass("TypeData", "de.jensklingenberg.ktorfit.converter", "_typeData")
val extDataClass = KtorfitClass("HttpRequestBuilder.() -> Unit", "", "_ext")
val formParameters = KtorfitClass("", "", "__formParameters")
val converterHelper = KtorfitClass("KtorfitConverterHelper","de.jensklingenberg.ktorfit.internal", "_converter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,7 @@ public interface Converter<F, T> {
*
* @return the converted [HttpResponse]
*/
@Deprecated("Use convert(result: KtorfitResult)")
public suspend fun convert(response: HttpResponse): T

public suspend fun convert(result: KtorfitResult): T {
return when (result) {
is KtorfitResult.Failure -> {
throw result.throwable
}

is KtorfitResult.Success -> {
convert(result.response)
}
}
}
public suspend fun convert(result: KtorfitResult): T
}

public interface RequestParameterConverter : Converter<Any, Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ internal class DefaultSuspendResponseConverterFactory : Converter.Factory {

class DefaultSuspendResponseConverter(val typeData: TypeData) :
Converter.SuspendResponseConverter<HttpResponse, Any> {
override suspend fun convert(response: HttpResponse): Any {
return convert(KtorfitResult.Success(response))
}

override suspend fun convert(result: KtorfitResult): Any {
return when (result) {
Expand Down
7 changes: 1 addition & 6 deletions sandbox/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ kotlin {

}
}
val wasmJsMain by getting {
dependencies {
implementation(libs.ktor.client.wasm.json.js)
}
}

val iosX64Main by getting
val iosArm64Main by getting
val iosMain by getting {
Expand All @@ -145,7 +141,6 @@ dependencies {

// add("kspJvmTest", this)
add("kspJs", this)
add("kspWasmJs", this)
add("kspLinuxX64", this)
add("kspMingwX64", this)
}
Expand Down
3 changes: 0 additions & 3 deletions sandbox/src/commonMain/kotlin/com/example/UserFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class UserFactory : Converter.Factory {
): Converter.SuspendResponseConverter<HttpResponse, *>? {
if (typeData.typeInfo.type == User::class) {
return object : Converter.SuspendResponseConverter<HttpResponse, Any> {
override suspend fun convert(response: HttpResponse): Any {
return convert(KtorfitResult.Success(response))
}

override suspend fun convert(result: KtorfitResult): Any {
return when (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class MyOwnResponseConverterFactory : Converter.Factory {
if (typeData.typeInfo.type == MyOwnResponse::class) {

return object : Converter.SuspendResponseConverter<HttpResponse, Any> {
override suspend fun convert(response: HttpResponse): Any {
return convert(KtorfitResult.Success(response))
}

override suspend fun convert(result: KtorfitResult): Any {
return when (result) {
Expand Down

0 comments on commit 1cc97de

Please sign in to comment.