|
|
|
@ -45,8 +45,8 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
setupInsecureHTTPEngine(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
install(HttpCache)
|
|
|
|
|
install(ContentNegotiation) {
|
|
|
|
|
install(HttpCache)
|
|
|
|
|
json(
|
|
|
|
|
Json {
|
|
|
|
|
prettyPrint = true
|
|
|
|
@ -105,8 +105,8 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
|
|
|
|
|
private fun hasLoginInfo() =
|
|
|
|
|
appSettingsService.getUserName().isNotEmpty() &&
|
|
|
|
|
appSettingsService.getPassword()
|
|
|
|
|
.isNotEmpty()
|
|
|
|
|
appSettingsService.getPassword()
|
|
|
|
|
.isNotEmpty()
|
|
|
|
|
|
|
|
|
|
suspend fun login(): SuccessResponse =
|
|
|
|
|
if (appSettingsService.getUserName().isNotEmpty() &&
|
|
|
|
@ -127,7 +127,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
client.tryToGet(url("/login")) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -148,7 +150,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
client.tryToPost(url("/login")) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -164,7 +168,8 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private fun shouldHaveNewLogout() = appSettingsService.getApiVersion() >= 5 // We are missing 4.1.0
|
|
|
|
|
private fun shouldHaveNewLogout() =
|
|
|
|
|
appSettingsService.getApiVersion() >= 5 // We are missing 4.1.0
|
|
|
|
|
|
|
|
|
|
suspend fun logout(): SuccessResponse =
|
|
|
|
|
if (shouldHaveNewLogout()) {
|
|
|
|
@ -176,7 +181,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
private suspend fun maybeLogoutIfAvailable() =
|
|
|
|
|
responseOrSuccessIf404(
|
|
|
|
|
client.tryToGet(url("/logout")) {
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -195,7 +202,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
private suspend fun doLogout() =
|
|
|
|
|
maybeResponse(
|
|
|
|
|
client.tryToDelete(url("/api/session/current")) {
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -233,7 +242,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("updatedsince", updatedSince)
|
|
|
|
|
parameter("items", items ?: appSettingsService.getItemsNumber())
|
|
|
|
|
parameter("offset", offset)
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -258,7 +269,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
}
|
|
|
|
|
parameter("type", "all")
|
|
|
|
|
parameter("items", 1)
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -281,7 +294,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -304,7 +319,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -327,7 +344,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -350,7 +369,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -373,7 +394,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -396,7 +419,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -415,7 +440,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
suspend fun apiInformation(): StatusAndData<SelfossModel.ApiInformation> =
|
|
|
|
|
bodyOrFailure(
|
|
|
|
|
client.tryToGet(url("/api/about")) {
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -438,7 +465,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -461,7 +490,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -484,7 +515,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -507,7 +540,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -528,15 +563,17 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
client.tryToSubmitForm(
|
|
|
|
|
url = url("/mark"),
|
|
|
|
|
formParameters =
|
|
|
|
|
Parameters.build {
|
|
|
|
|
if (!shouldHavePostLogin()) {
|
|
|
|
|
append("username", appSettingsService.getUserName())
|
|
|
|
|
append("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
ids.map { append("ids[]", it) }
|
|
|
|
|
},
|
|
|
|
|
Parameters.build {
|
|
|
|
|
if (!shouldHavePostLogin()) {
|
|
|
|
|
append("username", appSettingsService.getUserName())
|
|
|
|
|
append("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
ids.map { append("ids[]", it) }
|
|
|
|
|
},
|
|
|
|
|
block = {
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -577,18 +614,20 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
client.tryToSubmitForm(
|
|
|
|
|
url = url("/source"),
|
|
|
|
|
formParameters =
|
|
|
|
|
Parameters.build {
|
|
|
|
|
if (!shouldHavePostLogin()) {
|
|
|
|
|
append("username", appSettingsService.getUserName())
|
|
|
|
|
append("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
append("title", title)
|
|
|
|
|
append("url", url)
|
|
|
|
|
append("spout", spout)
|
|
|
|
|
append(tagsParamName, tags)
|
|
|
|
|
},
|
|
|
|
|
Parameters.build {
|
|
|
|
|
if (!shouldHavePostLogin()) {
|
|
|
|
|
append("username", appSettingsService.getUserName())
|
|
|
|
|
append("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
append("title", title)
|
|
|
|
|
append("url", url)
|
|
|
|
|
append("spout", spout)
|
|
|
|
|
append(tagsParamName, tags)
|
|
|
|
|
},
|
|
|
|
|
block = {
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -630,18 +669,20 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
client.tryToSubmitForm(
|
|
|
|
|
url = url("/source/$id"),
|
|
|
|
|
formParameters =
|
|
|
|
|
Parameters.build {
|
|
|
|
|
if (!shouldHavePostLogin()) {
|
|
|
|
|
append("username", appSettingsService.getUserName())
|
|
|
|
|
append("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
append("title", title)
|
|
|
|
|
append("url", url)
|
|
|
|
|
append("spout", spout)
|
|
|
|
|
append(tagsParamName, tags)
|
|
|
|
|
},
|
|
|
|
|
Parameters.build {
|
|
|
|
|
if (!shouldHavePostLogin()) {
|
|
|
|
|
append("username", appSettingsService.getUserName())
|
|
|
|
|
append("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
append("title", title)
|
|
|
|
|
append("url", url)
|
|
|
|
|
append("spout", spout)
|
|
|
|
|
append(tagsParamName, tags)
|
|
|
|
|
},
|
|
|
|
|
block = {
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -664,7 +705,9 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
parameter("username", appSettingsService.getUserName())
|
|
|
|
|
parameter("password", appSettingsService.getPassword())
|
|
|
|
|
}
|
|
|
|
|
if (appSettingsService.getBasicUserName().isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()) {
|
|
|
|
|
if (appSettingsService.getBasicUserName()
|
|
|
|
|
.isNotEmpty() && appSettingsService.getBasicPassword().isNotEmpty()
|
|
|
|
|
) {
|
|
|
|
|
headers {
|
|
|
|
|
append(
|
|
|
|
|
HttpHeaders.Authorization,
|
|
|
|
@ -679,4 +722,4 @@ class SelfossApi(private val appSettingsService: AppSettingsService) {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|