mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
* Api call * added captions * final commit * some minor changes * sigular * test for captions * mock fetchCaptionbyFileName * corrected method name * * used ? instead of !! (unsafe call on nullable) * updated unit test for fetchCaptionByFilename()
This commit is contained in:
parent
047059c490
commit
3c9b7ba7a8
9 changed files with 137 additions and 6 deletions
|
|
@ -3,6 +3,7 @@ package fr.free.nrw.commons.mwapi;
|
|||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
|
|
@ -303,6 +304,26 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
.getString("/api/flow-parsoid-utils/@content"));
|
||||
}
|
||||
|
||||
/**
|
||||
* fetches the Caption of the file with a given name.
|
||||
* @param filename title of the file
|
||||
* @return a single with media caption
|
||||
*/
|
||||
@Override
|
||||
public Single<String> fetchCaptionByFilename(String filename) {
|
||||
return Single.fromCallable(() -> {
|
||||
CustomApiResult apiResult = api.action("wbgetentities")
|
||||
.param("sites", "commonswiki")
|
||||
.param("titles", filename)
|
||||
.param("props", "labels")
|
||||
.param("format", "xml")
|
||||
.param("languages", Locale.getDefault().getLanguage())
|
||||
.param("languagefallback", "1")
|
||||
.get();
|
||||
return apiResult.getString("/api/entities/entity/labels/label/@value");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Single<MediaResult> fetchMediaByFilename(String filename) {
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ public interface MediaWikiApi {
|
|||
|
||||
Single<String> parseWikicode(String source);
|
||||
|
||||
Single<String> fetchCaptionByFilename(String filename);
|
||||
|
||||
@NonNull
|
||||
Single<MediaResult> fetchMediaByFilename(String filename);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue