Move api client creation function within api class
This commit is contained in:
parent
4482234e1a
commit
a029d8a7dc
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user