Remove ktorfit (#4019)

This commit is contained in:
Phil Oliver
2025-12-16 16:52:29 -05:00
committed by GitHub
parent 3783a1e885
commit 4b3ae721a0
5 changed files with 53 additions and 55 deletions

View File

@@ -35,7 +35,6 @@ plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ktorfit) apply false
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.secrets) apply false
alias(libs.plugins.dependency.analysis)
@@ -108,11 +107,6 @@ dependencyAnalysis {
includeDependency("com.google.dagger:hilt-core")
includeDependency(libs.hilt.android)
}
bundle("ktorfit") {
includeDependency("de.jensklingenberg.ktorfit:ktorfit-lib")
includeDependency("de.jensklingenberg.ktorfit:ktorfit-annotations")
}
}
issues {

View File

@@ -22,7 +22,6 @@ plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.kover)
alias(libs.plugins.protobuf)
alias(libs.plugins.ktorfit)
}
android {
@@ -40,7 +39,6 @@ dependencies {
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.okhttp)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktorfit)
implementation(libs.okhttp3.logging.interceptor)
googleImplementation(libs.dd.sdk.android.okhttp)

View File

@@ -20,12 +20,12 @@ package org.meshtastic.core.network.di
import android.content.Context
import com.datadog.android.okhttp.DatadogEventListener
import com.datadog.android.okhttp.DatadogInterceptor
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import de.jensklingenberg.ktorfit.Ktorfit
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
@@ -36,55 +36,55 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.meshtastic.core.network.BuildConfig
import org.meshtastic.core.network.service.ApiService
import org.meshtastic.core.network.service.createApiService
import org.meshtastic.core.network.service.ApiServiceImpl
import java.io.File
import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
@Module
class GoogleNetworkModule {
interface GoogleNetworkModule {
@Provides
@Singleton
fun provideOkHttpClient(@ApplicationContext context: Context): OkHttpClient = OkHttpClient.Builder()
.cache(
cache =
Cache(
directory = File(context.applicationContext.cacheDir, "http_cache"),
maxSize = 50L * 1024L * 1024L, // 50 MiB
),
)
.addInterceptor(
interceptor =
HttpLoggingInterceptor().apply {
if (BuildConfig.DEBUG) {
setLevel(HttpLoggingInterceptor.Level.BODY)
}
},
)
.addInterceptor(interceptor = DatadogInterceptor.Builder(tracedHosts = listOf("meshtastic.org")).build())
.eventListenerFactory(eventListenerFactory = DatadogEventListener.Factory())
.build()
@Binds @Singleton
fun bindApiService(apiServiceImpl: ApiServiceImpl): ApiService
@Provides
@Singleton
fun provideHttpClient(okHttpClient: OkHttpClient): HttpClient = HttpClient(engineFactory = OkHttp) {
engine { preconfigured = okHttpClient }
install(plugin = ContentNegotiation) {
json(
Json {
isLenient = true
ignoreUnknownKeys = true
companion object {
@Provides
@Singleton
fun provideOkHttpClient(@ApplicationContext context: Context): OkHttpClient = OkHttpClient.Builder()
.cache(
cache =
Cache(
directory = File(context.applicationContext.cacheDir, "http_cache"),
maxSize = 50L * 1024L * 1024L, // 50 MiB
),
)
.addInterceptor(
interceptor =
HttpLoggingInterceptor().apply {
if (BuildConfig.DEBUG) {
setLevel(HttpLoggingInterceptor.Level.BODY)
}
},
)
.addInterceptor(
interceptor = DatadogInterceptor.Builder(tracedHosts = listOf("meshtastic.org")).build(),
)
.eventListenerFactory(eventListenerFactory = DatadogEventListener.Factory())
.build()
@Provides
@Singleton
fun provideHttpClient(okHttpClient: OkHttpClient): HttpClient = HttpClient(engineFactory = OkHttp) {
engine { preconfigured = okHttpClient }
install(plugin = ContentNegotiation) {
json(
Json {
isLenient = true
ignoreUnknownKeys = true
},
)
}
}
}
@Provides
@Singleton
fun provideApiService(httpClient: HttpClient): ApiService {
val ktorfit = Ktorfit.Builder().baseUrl(url = "https://api.meshtastic.org/").httpClient(httpClient).build()
return ktorfit.createApiService()
}
}

View File

@@ -17,14 +17,23 @@
package org.meshtastic.core.network.service
import de.jensklingenberg.ktorfit.http.GET
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import org.meshtastic.core.model.NetworkDeviceHardware
import org.meshtastic.core.model.NetworkFirmwareReleases
import javax.inject.Inject
interface ApiService {
@GET("resource/deviceHardware")
suspend fun getDeviceHardware(): List<NetworkDeviceHardware>
@GET("github/firmware/list")
suspend fun getFirmwareReleases(): NetworkFirmwareReleases
}
class ApiServiceImpl @Inject constructor(private val client: HttpClient) : ApiService {
override suspend fun getDeviceHardware(): List<NetworkDeviceHardware> =
client.get("https://api.meshtastic.org/resource/deviceHardware").body()
override suspend fun getFirmwareReleases(): NetworkFirmwareReleases =
client.get("https://api.meshtastic.org/github/firmware/list").body()
}

View File

@@ -26,7 +26,6 @@ maps-compose = "6.12.2"
# Networking
ktor = "3.3.3"
ktorfit = "2.7.1"
# Other
aboutlibraries = "13.1.0"
@@ -120,7 +119,6 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktorfit = { module = "de.jensklingenberg.ktorfit:ktorfit-lib", version.ref = "ktorfit" }
okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version = "5.3.2" }
# Testing
@@ -194,7 +192,6 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version = "0.9.4" }
ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" }
# Google
devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "devtools-ksp" }