Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class SimpleApiCustom internal constructor(val config: Config) {

}

fun HttpClient.getAdapter(): RequestResponseAdapter? {
return feature(SimpleApiCustom)?.config?.adapter
fun getAdapter(client: HttpClient): RequestResponseAdapter? {
return client.feature(SimpleApiCustom)?.config?.adapter
}

val NoConfig = Config()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ApiGenerator(
""".trimMargin()

private fun SharedKtClass.makeClassDefinition() =
"class ${getApiImplementationName(name)}(val client: HttpClient, val baseUrl: String, val requestResponseAdapter: RequestResponseAdapter?) : $name"
"class ${getApiImplementationName(name)}(val client: HttpClient, val baseUrl: String) : $name"

private fun SharedKtClass.makeMainPathProperty(): String {

Expand Down Expand Up @@ -139,6 +139,7 @@ class ApiGenerator(
| ${parameters.map { it.toParameterInfo() }.joinToString(",\n ")}
| )
|)
|val requestResponseAdapter: RequestResponseAdapter? = SimpleApiCustom.getAdapter(client)
|return client.callApi(callInfo, if (requestResponseAdapter == null) ${if (pluginOptions.useFramework) "SimpleApiCustom.NoConfig.getArchitectureAdapter()" else "SimpleApiCustom.NoConfig.getApiAdapter()"} else requestResponseAdapter)
""".trimMargin()
}
Expand Down Expand Up @@ -243,7 +244,7 @@ class ApiGenerator(
import io.ktor.client.HttpClient
import kim.jeonghyeon.net.*

expect inline fun <reified T> HttpClient.create${pluginOptions.postFix.capitalize()}(baseUrl: String, requestResponseAdapter: RequestResponseAdapter? = SimpleApiCustom.run { getAdapter() }): T
expect inline fun <reified T> HttpClient.create${pluginOptions.postFix.capitalize()}(baseUrl: String): T

""".trimIndent()
)
Expand Down Expand Up @@ -272,10 +273,10 @@ class ApiGenerator(
|${joinToString("\n") { "import ${if (it.packageName.isEmpty()) "" else "${it.packageName}."}${it.name}" }}
|${joinToString("\n") { "import ${if (it.packageName.isEmpty()) "" else "${it.packageName}."}${it.name}Impl" }}
|
|${if (pluginOptions.isMultiplatform) "actual " else ""}inline fun <reified T> HttpClient.create${pluginOptions.postFix.capitalize()}(baseUrl: String, requestResponseAdapter: RequestResponseAdapter?${if (pluginOptions.isMultiplatform) "" else " = SimpleApiCustom.run { getAdapter() }"}): T {
|${if (pluginOptions.isMultiplatform) "actual " else ""}inline fun <reified T> HttpClient.create${pluginOptions.postFix.capitalize()}(baseUrl: String): T {
|
| return when (T::class) {
|${joinToString("\n") { "${it.name}::class -> ${it.name}Impl(this, baseUrl, requestResponseAdapter) as T" }.prependIndent(" ")}
|${joinToString("\n") { "${it.name}::class -> ${it.name}Impl(this, baseUrl) as T" }.prependIndent(" ")}
|
| else -> ${getElseStatement()}
| }
Expand Down Expand Up @@ -304,19 +305,19 @@ class ApiGenerator(

fun getElseStatement(): String {
//api -> error("can not create " + T::class.simpleName)
//architecture -> createSimple<T>(baseUrl, requestResponseAdapter)
//other with api -> createSimple<T>(baseUrl, requestResponseAdapter)
//other with architecture -> createSimpleFramework<T>(baseUrl, requestResponseAdapter)
//architecture -> createSimple<T>(baseUrl)
//other with api -> createSimple<T>(baseUrl)
//other with architecture -> createSimpleFramework<T>(baseUrl)
val isApi = pluginOptions.isInternal && !pluginOptions.useFramework
val isArchitecture = pluginOptions.isInternal && pluginOptions.useFramework
val isOtherWithApi = !pluginOptions.isInternal && !pluginOptions.useFramework

return if (isApi) {
"error(\"can not create \" + T::class.simpleName)"
} else if (isArchitecture || isOtherWithApi) {
"createSimple<T>(baseUrl, requestResponseAdapter)"
"createSimple<T>(baseUrl)"
} else {
"createSimpleFramework<T>(baseUrl, requestResponseAdapter)"
"createSimpleFramework<T>(baseUrl)"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/DependencyVersion.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object versions {
const val simpleArch = "1.4.51"
const val simpleArch = "1.4.52"

object kotlin {
const val version = "1.4.21"
Expand Down
4 changes: 2 additions & 2 deletions framework/kotlin-simple-architecture-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ kotlin {

api(deps.sqldelight.android)
api(deps.android.timber)
api(deps.android.accompanist.coil)
api(deps.android.accompanist.insets)
// api(deps.android.accompanist.coil)
// api(deps.android.accompanist.insets)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object versions {
const val simpleArch = "1.4.51"
const val simpleArch = "1.4.52"

object kotlin {
const val version = "1.4.20"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object versions {
const val simpleArch = "1.4.51"
const val simpleArch = "1.4.52"

object kotlin {
const val version = "1.4.20"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object versions {
const val simpleArch = "1.4.51"
const val simpleArch = "1.4.52"

object kotlin {
const val version = "1.4.20"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object versions {
const val simpleArch = "1.4.51"
const val simpleArch = "1.4.52"

object kotlin {
const val version = "1.4.20"
Expand Down
2 changes: 1 addition & 1 deletion sample/buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object versions {
const val simpleArch = "1.4.51"
const val simpleArch = "1.4.52"

object kotlin {
const val version = "1.4.20"
Expand Down