Allow modifying source filters #198

Open
davidoskky wants to merge 3 commits from davidoskky/ReaderForSelfoss-multiplatform:filters into master
Showing only changes of commit 9e140aefa6 - Show all commits

View File

@ -642,14 +642,13 @@ class SelfossApi(
): SuccessResponse =
maybeResponse(
if (appSettingsService.getApiVersion() > 1) {
createSource("tags[]", title, url, spout, tags, filter)
createSource(title, url, spout, tags, filter)
} else {
createSource("tags", title, url, spout, tags, filter)
createSourceOld(title, url, spout, tags)
Review

There's no need to create a new method.

In the createSouce method, you could add an optional parameter filter and add it to the form parameters with something like

if (filter.notNull())                     append("filter", filter) 
There's no need to create a new method. In the `createSouce` method, you could add an optional parameter `filter` and add it to the form parameters with something like ``` if (filter.notNull()) append("filter", filter) ```
},
)
private suspend fun createSource(
tagsParamName: String,
title: String,
url: String,
spout: String,
@ -668,7 +667,47 @@ class SelfossApi(
append("url", url)
append("spout", spout)
append("filter", filter)
append(tagsParamName, tags)
append("tags[]", tags)
},
block = {
if (appSettingsService
.getBasicUserName()
.isNotEmpty() &&
appSettingsService.getBasicPassword().isNotEmpty()
) {
headers {
append(
HttpHeaders.Authorization,
constructBasicAuthValue(
BasicAuthCredentials(
username = appSettingsService.getBasicUserName(),
password = appSettingsService.getBasicPassword(),
),
),
)
}
}
},
)
private suspend fun createSourceOld(
title: String,
url: String,
spout: String,
tags: String,
): HttpResponse? =
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("tags", tags)
},
block = {
if (appSettingsService
@ -701,15 +740,14 @@ class SelfossApi(
): SuccessResponse =
maybeResponse(
if (appSettingsService.getApiVersion() > 1) {
updateSource(id, "tags[]", title, url, spout, tags, filter)
updateSource(id, title, url, spout, tags, filter)
} else {
updateSource(id, "tags", title, url, spout, tags, filter)
updateSourceOld(id, title, url, spout, tags)
Review

Same here.

Same here.
},
)
private suspend fun updateSource(
id: Int,
tagsParamName: String,
title: String,
url: String,
spout: String,
@ -727,7 +765,7 @@ class SelfossApi(
append("title", title)
append("url", url)
append("spout", spout)
append(tagsParamName, tags)
append("tags[]", tags)
append("filter", filter)
},
block = {
@ -751,6 +789,47 @@ class SelfossApi(
},
)
private suspend fun updateSourceOld(
id: Int,
title: String,
url: String,
spout: String,
tags: String,
): HttpResponse? =
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("tags", tags)
},
block = {
if (appSettingsService
.getBasicUserName()
.isNotEmpty() &&
appSettingsService.getBasicPassword().isNotEmpty()
) {
headers {
append(
HttpHeaders.Authorization,
constructBasicAuthValue(
BasicAuthCredentials(
username = appSettingsService.getBasicUserName(),
password = appSettingsService.getBasicPassword(),
),
),
)
}
}
},
)
suspend fun deleteSource(id: Int): SuccessResponse =
maybeResponse(
client.tryToDelete(url("/source/$id")) {