Move api client creation function within api class
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
davidoskky 2023-09-10 21:33:28 +02:00
parent 4482234e1a
commit a029d8a7dc

View File

@ -35,10 +35,10 @@ import kotlinx.serialization.json.Json
expect fun setupInsecureHTTPEngine(config: CIOEngineConfig)
fun createHttpClient(
appSettingsService: AppSettingsService,
api: SelfossApi
) =
class SelfossApi(private val appSettingsService: AppSettingsService) {
var client = createHttpClient()
fun createHttpClient() =
HttpClient(CIO) {
if (appSettingsService.getSelfSigned()) {
engine {
@ -68,13 +68,13 @@ fun createHttpClient(
install(HttpRequestRetry) {
maxRetries = 2
retryIf { _, response ->
response.status == HttpStatusCode.Forbidden && api.shouldHavePostLogin() && api.hasLoginInfo()
response.status == HttpStatusCode.Forbidden && shouldHavePostLogin() && hasLoginInfo()
}
modifyRequest {
Napier.i("Will modify", tag = "HttpSend")
CoroutineScope(Dispatchers.Main).launch {
Napier.i("Will login", tag = "HttpSend")
api.login()
login()
Napier.i("Did login", tag = "HttpSend")
}
}
@ -82,16 +82,12 @@ fun createHttpClient(
expectSuccess = false
}
class SelfossApi(private val appSettingsService: AppSettingsService) {
var client = createHttpClient(appSettingsService, this)
fun url(path: String) =
"${appSettingsService.getBaseUrl()}$path"
fun refreshLoginInformation() {
appSettingsService.refreshApiSettings()
client = createHttpClient(appSettingsService, this)
client = createHttpClient()
}
fun constructBasicAuthValue(credentials: BasicAuthCredentials): String {