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)
|
expect fun setupInsecureHTTPEngine(config: CIOEngineConfig)
|
||||||
|
|
||||||
fun createHttpClient(
|
class SelfossApi(private val appSettingsService: AppSettingsService) {
|
||||||
appSettingsService: AppSettingsService,
|
|
||||||
api: SelfossApi
|
var client = createHttpClient()
|
||||||
) =
|
fun createHttpClient() =
|
||||||
HttpClient(CIO) {
|
HttpClient(CIO) {
|
||||||
if (appSettingsService.getSelfSigned()) {
|
if (appSettingsService.getSelfSigned()) {
|
||||||
engine {
|
engine {
|
||||||
@ -68,13 +68,13 @@ fun createHttpClient(
|
|||||||
install(HttpRequestRetry) {
|
install(HttpRequestRetry) {
|
||||||
maxRetries = 2
|
maxRetries = 2
|
||||||
retryIf { _, response ->
|
retryIf { _, response ->
|
||||||
response.status == HttpStatusCode.Forbidden && api.shouldHavePostLogin() && api.hasLoginInfo()
|
response.status == HttpStatusCode.Forbidden && shouldHavePostLogin() && hasLoginInfo()
|
||||||
}
|
}
|
||||||
modifyRequest {
|
modifyRequest {
|
||||||
Napier.i("Will modify", tag = "HttpSend")
|
Napier.i("Will modify", tag = "HttpSend")
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
Napier.i("Will login", tag = "HttpSend")
|
Napier.i("Will login", tag = "HttpSend")
|
||||||
api.login()
|
login()
|
||||||
Napier.i("Did login", tag = "HttpSend")
|
Napier.i("Did login", tag = "HttpSend")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,16 +82,12 @@ fun createHttpClient(
|
|||||||
expectSuccess = false
|
expectSuccess = false
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
||||||
|
|
||||||
var client = createHttpClient(appSettingsService, this)
|
|
||||||
|
|
||||||
fun url(path: String) =
|
fun url(path: String) =
|
||||||
"${appSettingsService.getBaseUrl()}$path"
|
"${appSettingsService.getBaseUrl()}$path"
|
||||||
|
|
||||||
fun refreshLoginInformation() {
|
fun refreshLoginInformation() {
|
||||||
appSettingsService.refreshApiSettings()
|
appSettingsService.refreshApiSettings()
|
||||||
client = createHttpClient(appSettingsService, this)
|
client = createHttpClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun constructBasicAuthValue(credentials: BasicAuthCredentials): String {
|
fun constructBasicAuthValue(credentials: BasicAuthCredentials): String {
|
||||||
|
Loading…
Reference in New Issue
Block a user