mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
correct identation
This commit is contained in:
parent
e60037300a
commit
31e9d716e1
1 changed files with 77 additions and 77 deletions
|
|
@ -17,83 +17,83 @@ import javax.inject.Singleton
|
|||
*/
|
||||
@Singleton
|
||||
class WikiBaseClient
|
||||
@Inject
|
||||
constructor(
|
||||
private val wikiBaseInterface: WikiBaseInterface,
|
||||
@param:Named(NetworkingModule.NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||
) {
|
||||
fun postEditEntity(
|
||||
fileEntityId: String?,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postEditEntity(fileEntityId!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the server call for posting new depicts
|
||||
*
|
||||
* @param filename name of the file
|
||||
* @param data data of the depicts to be uploaded
|
||||
* @return Observable<Boolean>
|
||||
</Boolean> */
|
||||
fun postEditEntityByFilename(
|
||||
filename: String?,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postEditEntityByFilename(filename!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
fun getClaimIdsByProperty(
|
||||
fileEntityId: String,
|
||||
property: String,
|
||||
): Observable<List<String>> =
|
||||
wikiBaseInterface.getClaimsByProperty(fileEntityId, property).map { claimsResponse ->
|
||||
claimsResponse.claims[property]?.mapNotNull { claim -> claim.id } ?: emptyList()
|
||||
}
|
||||
|
||||
fun postDeleteClaims(
|
||||
entityId: String,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postDeleteClaims(editToken, entityId, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
fun getFileEntityId(uploadResult: UploadResult): Observable<Long> =
|
||||
wikiBaseInterface
|
||||
.getFileEntityId(uploadResult.createCanonicalFileName())
|
||||
.map { response: MwQueryResponse ->
|
||||
response
|
||||
.query()!!
|
||||
.pages()!![0]
|
||||
.pageId()
|
||||
.toLong()
|
||||
@Inject
|
||||
constructor(
|
||||
private val wikiBaseInterface: WikiBaseInterface,
|
||||
@param:Named(NetworkingModule.NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||
) {
|
||||
fun postEditEntity(
|
||||
fileEntityId: String?,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postEditEntity(fileEntityId!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
fun addLabelsToWikidata(
|
||||
fileEntityId: Long,
|
||||
languageCode: String?,
|
||||
captionValue: String?,
|
||||
): Observable<MwPostResponse> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.addLabelstoWikidata(
|
||||
PAGE_ID_PREFIX + fileEntityId,
|
||||
editToken,
|
||||
languageCode,
|
||||
captionValue,
|
||||
)
|
||||
}
|
||||
/**
|
||||
* Makes the server call for posting new depicts
|
||||
*
|
||||
* @param filename name of the file
|
||||
* @param data data of the depicts to be uploaded
|
||||
* @return Observable<Boolean>
|
||||
</Boolean> */
|
||||
fun postEditEntityByFilename(
|
||||
filename: String?,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postEditEntityByFilename(filename!!, editToken, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
private fun csrfToken(): Observable<String> =
|
||||
Observable.fromCallable {
|
||||
csrfTokenClient.getTokenBlocking()
|
||||
}
|
||||
}
|
||||
fun getClaimIdsByProperty(
|
||||
fileEntityId: String,
|
||||
property: String,
|
||||
): Observable<List<String>> =
|
||||
wikiBaseInterface.getClaimsByProperty(fileEntityId, property).map { claimsResponse ->
|
||||
claimsResponse.claims[property]?.mapNotNull { claim -> claim.id } ?: emptyList()
|
||||
}
|
||||
|
||||
fun postDeleteClaims(
|
||||
entityId: String,
|
||||
data: String?,
|
||||
): Observable<Boolean> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface
|
||||
.postDeleteClaims(editToken, entityId, data!!)
|
||||
.map { response: MwPostResponse -> response.successVal == 1 }
|
||||
}
|
||||
|
||||
fun getFileEntityId(uploadResult: UploadResult): Observable<Long> =
|
||||
wikiBaseInterface
|
||||
.getFileEntityId(uploadResult.createCanonicalFileName())
|
||||
.map { response: MwQueryResponse ->
|
||||
response
|
||||
.query()!!
|
||||
.pages()!![0]
|
||||
.pageId()
|
||||
.toLong()
|
||||
}
|
||||
|
||||
fun addLabelsToWikidata(
|
||||
fileEntityId: Long,
|
||||
languageCode: String?,
|
||||
captionValue: String?,
|
||||
): Observable<MwPostResponse> =
|
||||
csrfToken().switchMap { editToken ->
|
||||
wikiBaseInterface.addLabelstoWikidata(
|
||||
PAGE_ID_PREFIX + fileEntityId,
|
||||
editToken,
|
||||
languageCode,
|
||||
captionValue,
|
||||
)
|
||||
}
|
||||
|
||||
private fun csrfToken(): Observable<String> =
|
||||
Observable.fromCallable {
|
||||
csrfTokenClient.getTokenBlocking()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue