Remove unused SelfossApi interface

This commit is contained in:
davide 2022-08-16 11:18:13 +02:00
parent 38f1dbd34d
commit f624a35fe2
2 changed files with 20 additions and 73 deletions

View File

@ -1,7 +1,6 @@
package bou.amine.apps.readerforselfossv2.DI package bou.amine.apps.readerforselfossv2.DI
import bou.amine.apps.readerforselfossv2.rest.SelfossApi 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.ApiDetailsService
import bou.amine.apps.readerforselfossv2.service.ApiDetailsServiceImpl import bou.amine.apps.readerforselfossv2.service.ApiDetailsServiceImpl
import org.kodein.di.DI import org.kodein.di.DI
@ -11,5 +10,5 @@ import org.kodein.di.singleton
val networkModule by DI.Module { val networkModule by DI.Module {
bind<ApiDetailsService>() with singleton { ApiDetailsServiceImpl() } bind<ApiDetailsService>() with singleton { ApiDetailsServiceImpl() }
bind<SelfossApi>() with singleton { SelfossApiImpl(instance()) } bind<SelfossApi>() with singleton { SelfossApi(instance()) }
} }

View File

@ -12,61 +12,9 @@ import io.ktor.client.plugins.logging.*
import io.ktor.serialization.kotlinx.json.* import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
interface SelfossApi { class SelfossApi(private val apiDetailsService: ApiDetailsService) {
val client: HttpClient
fun url(path: String): String
fun refreshLoginInformation() var client = createHttpClient()
suspend fun login(): SelfossModel.SuccessResponse?
suspend fun getItems(
type: String,
items: Int,
offset: Int,
tag: String? = "",
source: Long? = null,
search: String? = "",
updatedSince: String? = ""
): List<SelfossModel.Item>?
suspend fun stats(): SelfossModel.Stats?
suspend fun tags(): List<SelfossModel.Tag>?
suspend fun update(): SelfossModel.SuccessResponse?
suspend fun spouts(): Map<String, SelfossModel.Spout>?
suspend fun sources(): ArrayList<SelfossModel.Source>?
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<String>): 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()
private fun createHttpClient(): HttpClient { private fun createHttpClient(): HttpClient {
return 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" "${apiDetailsService.getBaseUrl()}$path"
override fun refreshLoginInformation() { fun refreshLoginInformation() {
apiDetailsService.refresh() apiDetailsService.refresh()
client = createHttpClient() client = createHttpClient()
} }
override suspend fun login(): SelfossModel.SuccessResponse? = suspend fun login(): SelfossModel.SuccessResponse? =
client.get(url("/login")) { client.get(url("/login")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun getItems( suspend fun getItems(
type: String, type: String,
items: Int, items: Int,
offset: Int, offset: Int,
@ -139,64 +87,64 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss
parameter("offset", offset) parameter("offset", offset)
}.body() }.body()
override suspend fun stats(): SelfossModel.Stats? = suspend fun stats(): SelfossModel.Stats? =
client.get(url("/stats")) { client.get(url("/stats")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun tags(): List<SelfossModel.Tag>? = suspend fun tags(): List<SelfossModel.Tag>? =
client.get(url("/tags")) { client.get(url("/tags")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun update(): SelfossModel.SuccessResponse? = suspend fun update(): SelfossModel.SuccessResponse? =
client.get(url("/update")) { client.get(url("/update")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun spouts(): Map<String, SelfossModel.Spout>? = suspend fun spouts(): Map<String, SelfossModel.Spout>? =
client.get(url("/sources/spouts")) { client.get(url("/sources/spouts")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun sources(): ArrayList<SelfossModel.Source>? = suspend fun sources(): ArrayList<SelfossModel.Source>? =
client.get(url("/sources/list")) { client.get(url("/sources/list")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun version(): SelfossModel.ApiVersion? = suspend fun version(): SelfossModel.ApiVersion? =
client.get(url("/api/about")).body() 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")) { client.post(url("/mark/$id")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? = suspend fun unmarkAsRead(id: String): SelfossModel.SuccessResponse? =
client.post(url("/unmark/$id")) { client.post(url("/unmark/$id")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun starr(id: String): SelfossModel.SuccessResponse? = suspend fun starr(id: String): SelfossModel.SuccessResponse? =
client.post(url("/starr/$id")) { client.post(url("/starr/$id")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun unstarr(id: String): SelfossModel.SuccessResponse? = suspend fun unstarr(id: String): SelfossModel.SuccessResponse? =
client.post(url("/unstarr/$id")) { client.post(url("/unstarr/$id")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())
}.body() }.body()
override suspend fun markAllAsRead(ids: List<String>): SelfossModel.SuccessResponse? = suspend fun markAllAsRead(ids: List<String>): SelfossModel.SuccessResponse? =
client.submitForm( client.submitForm(
url = url("/mark"), url = url("/mark"),
formParameters = Parameters.build { formParameters = Parameters.build {
@ -206,7 +154,7 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss
} }
).body() ).body()
override suspend fun createSourceForVersion( suspend fun createSourceForVersion(
title: String, title: String,
url: String, url: String,
spout: String, spout: String,
@ -256,7 +204,7 @@ class SelfossApiImpl(private val apiDetailsService: ApiDetailsService) : Selfoss
} }
).body() ).body()
override suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? = suspend fun deleteSource(id: Int): SelfossModel.SuccessResponse? =
client.delete(url("/source/$id")) { client.delete(url("/source/$id")) {
parameter("username", apiDetailsService.getUserName()) parameter("username", apiDetailsService.getUserName())
parameter("password", apiDetailsService.getPassword()) parameter("password", apiDetailsService.getPassword())