From f624a35fe260b9321cec40df33f05f7eb3300ab6 Mon Sep 17 00:00:00 2001 From: davide Date: Tue, 16 Aug 2022 11:18:13 +0200 Subject: [PATCH] Remove unused SelfossApi interface --- .../apps/readerforselfossv2/DI/modules.kt | 3 +- .../rest/{SelfossApiImpl.kt => SelfossApi.kt} | 90 ++++--------------- 2 files changed, 20 insertions(+), 73 deletions(-) rename shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/{SelfossApiImpl.kt => SelfossApi.kt} (76%) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt index c18e33d..2beba39 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/DI/modules.kt @@ -1,7 +1,6 @@ package bou.amine.apps.readerforselfossv2.DI import bou.amine.apps.readerforselfossv2.rest.SelfossApi -import bou.amine.apps.readerforselfossv2.rest.SelfossApiImpl import bou.amine.apps.readerforselfossv2.service.ApiDetailsService import bou.amine.apps.readerforselfossv2.service.ApiDetailsServiceImpl import org.kodein.di.DI @@ -11,5 +10,5 @@ import org.kodein.di.singleton val networkModule by DI.Module { bind() with singleton { ApiDetailsServiceImpl() } - bind() with singleton { SelfossApiImpl(instance()) } + bind() with singleton { SelfossApi(instance()) } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApiImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt similarity index 76% rename from shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApiImpl.kt rename to shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt index 1bfa932..90ba822 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApiImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/rest/SelfossApi.kt @@ -12,61 +12,9 @@ import io.ktor.client.plugins.logging.* import io.ktor.serialization.kotlinx.json.* import kotlinx.serialization.json.Json -interface SelfossApi { - val client: HttpClient - fun url(path: String): String +class SelfossApi(private val apiDetailsService: ApiDetailsService) { - fun refreshLoginInformation() - - suspend fun login(): SelfossModel.SuccessResponse? - - suspend fun getItems( - type: String, - items: Int, - offset: Int, - tag: String? = "", - source: Long? = null, - search: String? = "", - updatedSince: String? = "" - ): List? - - suspend fun stats(): SelfossModel.Stats? - - suspend fun tags(): List? - - suspend fun update(): SelfossModel.SuccessResponse? - - suspend fun spouts(): Map? - - suspend fun sources(): ArrayList? - - suspend fun version(): SelfossModel.ApiVersion? - - suspend fun markAsRead(id: String): SelfossModel.SuccessResponse? - - suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? - - suspend fun starr(id: String): SelfossModel.SuccessResponse? - - suspend fun unstarr(id: String): SelfossModel.SuccessResponse? - - suspend fun markAllAsRead(ids: List): SelfossModel.SuccessResponse? - - suspend fun createSourceForVersion( - title: String, - url: String, - spout: String, - tags: String, - filter: String, - version: Int - ): SelfossModel.SuccessResponse? - - suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? -} - -class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : SelfossApi { - - override var client = createHttpClient() + var client = createHttpClient() private fun createHttpClient(): HttpClient { return HttpClient { @@ -104,21 +52,21 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss } } - override fun url(path: String) = + fun url(path: String) = "${apiDetailsService.getBaseUrl()}$path" - override fun refreshLoginInformation() { + fun refreshLoginInformation() { apiDetailsService.refresh() client = createHttpClient() } - override suspend fun login(): SelfossModel.SuccessResponse? = + suspend fun login(): SelfossModel.SuccessResponse? = client.get(url("/login")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun getItems( + suspend fun getItems( type: String, items: Int, offset: Int, @@ -139,64 +87,64 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss parameter("offset", offset) }.body() - override suspend fun stats(): SelfossModel.Stats? = + suspend fun stats(): SelfossModel.Stats? = client.get(url("/stats")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun tags(): List? = + suspend fun tags(): List? = client.get(url("/tags")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun update(): SelfossModel.SuccessResponse? = + suspend fun update(): SelfossModel.SuccessResponse? = client.get(url("/update")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun spouts(): Map? = + suspend fun spouts(): Map? = client.get(url("/sources/spouts")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun sources(): ArrayList? = + suspend fun sources(): ArrayList? = client.get(url("/sources/list")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun version(): SelfossModel.ApiVersion? = + suspend fun version(): SelfossModel.ApiVersion? = client.get(url("/api/about")).body() - override suspend fun markAsRead(id: String): SelfossModel.SuccessResponse? = + suspend fun markAsRead(id: String): SelfossModel.SuccessResponse? = client.post(url("/mark/$id")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? = + suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? = client.post(url("/unmark/$id")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun starr(id: String): SelfossModel.SuccessResponse? = + suspend fun starr(id: String): SelfossModel.SuccessResponse? = client.post(url("/starr/$id")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun unstarr(id: String): SelfossModel.SuccessResponse? = + suspend fun unstarr(id: String): SelfossModel.SuccessResponse? = client.post(url("/unstarr/$id")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword()) }.body() - override suspend fun markAllAsRead(ids: List): SelfossModel.SuccessResponse? = + suspend fun markAllAsRead(ids: List): SelfossModel.SuccessResponse? = client.submitForm( url = url("/mark"), formParameters = Parameters.build { @@ -206,7 +154,7 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss } ).body() - override suspend fun createSourceForVersion( + suspend fun createSourceForVersion( title: String, url: String, spout: String, @@ -256,7 +204,7 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss } ).body() - override suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? = + suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? = client.delete(url("/source/$id")) { parameter("username", apiDetailsService.getUserName()) parameter("password", apiDetailsService.getPassword())