mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Add routes for fetching category info from titles
This commit is contained in:
parent
0fad413202
commit
d59adcd588
2 changed files with 33 additions and 0 deletions
|
|
@ -78,6 +78,24 @@ class CategoryClient
|
|||
),
|
||||
)
|
||||
|
||||
/**
|
||||
* Fetches categories belonging to an image (P18 of some wikidata entity).
|
||||
*
|
||||
* @param image P18 of some wikidata entity
|
||||
* @param itemLimit How many categories to return
|
||||
* @return Single Observable emitting the list of categories
|
||||
*/
|
||||
fun getCategoriesOfImage(
|
||||
image: String,
|
||||
itemLimit: Int,
|
||||
): Single<List<CategoryItem>> =
|
||||
responseMapper(
|
||||
categoryInterface.getCategoriesByTitles(
|
||||
"File:${image}",
|
||||
itemLimit,
|
||||
),
|
||||
)
|
||||
|
||||
/**
|
||||
* The method takes categoryName as input and returns a List of Subcategories
|
||||
* It uses the generator query API to get the subcategories in a category, 500 at a time.
|
||||
|
|
|
|||
|
|
@ -61,6 +61,21 @@ interface CategoryInterface {
|
|||
@Query("gacoffset") offset: Int,
|
||||
): Single<MwQueryResponse>
|
||||
|
||||
/**
|
||||
* Fetches non-hidden categories by titles.
|
||||
*
|
||||
* @param titles titles to fetch categories for (e.g. File:<P18 of a wikidata entity>)
|
||||
* @param itemLimit How many categories to return
|
||||
* @return MwQueryResponse
|
||||
*/
|
||||
@GET(
|
||||
"w/api.php?action=query&format=json&formatversion=2&generator=categories&prop=categoryinfo|description|pageimages&piprop=thumbnail&pithumbsize=70&gclshow=!hidden",
|
||||
)
|
||||
fun getCategoriesByTitles(
|
||||
@Query("titles") titles: String?,
|
||||
@Query("gcllimit") itemLimit: Int,
|
||||
): Single<MwQueryResponse>
|
||||
|
||||
@GET("w/api.php?action=query&format=json&formatversion=2&generator=categorymembers&gcmtype=subcat&prop=info&gcmlimit=50")
|
||||
fun getSubCategoryList(
|
||||
@Query("gcmtitle") categoryName: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue