|
| 1 | +package fr.free.nrw.commons.category |
| 2 | + |
| 3 | +import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse |
| 4 | +import io.reactivex.Single |
| 5 | +import retrofit2.http.GET |
| 6 | +import retrofit2.http.Query |
| 7 | +import retrofit2.http.QueryMap |
| 8 | + |
| 9 | +/** |
| 10 | + * Interface for interacting with Commons category related APIs |
| 11 | + */ |
| 12 | +interface CategoryInterface { |
| 13 | + /** |
| 14 | + * Searches for categories with the specified name. |
| 15 | + * |
| 16 | + * @param filter The string to be searched |
| 17 | + * @param itemLimit How many results are returned |
| 18 | + * @return |
| 19 | + */ |
| 20 | + @GET("w/api.php?action=query&format=json&formatversion=2&generator=search&prop=description|pageimages&piprop=thumbnail&pithumbsize=70&gsrnamespace=14") |
| 21 | + fun searchCategories( |
| 22 | + @Query("gsrsearch") filter: String?, |
| 23 | + @Query("gsrlimit") itemLimit: Int, |
| 24 | + @Query("gsroffset") offset: Int |
| 25 | + ): Single<MwQueryResponse> |
| 26 | + |
| 27 | + /** |
| 28 | + * Searches for categories starting with the specified prefix. |
| 29 | + * |
| 30 | + * @param prefix The string to be searched |
| 31 | + * @param itemLimit How many results are returned |
| 32 | + * @return |
| 33 | + */ |
| 34 | + @GET("w/api.php?action=query&format=json&formatversion=2&generator=allcategories&prop=categoryinfo|description|pageimages&piprop=thumbnail&pithumbsize=70") |
| 35 | + fun searchCategoriesForPrefix( |
| 36 | + @Query("gacprefix") prefix: String?, |
| 37 | + @Query("gaclimit") itemLimit: Int, |
| 38 | + @Query("gacoffset") offset: Int |
| 39 | + ): Single<MwQueryResponse> |
| 40 | + |
| 41 | + /** |
| 42 | + * Fetches categories starting and ending with a specified name. |
| 43 | + * |
| 44 | + * @param startingCategory Name of the category to start |
| 45 | + * @param endingCategory Name of the category to end |
| 46 | + * @param itemLimit How many categories to return |
| 47 | + * @param offset offset |
| 48 | + * @return MwQueryResponse |
| 49 | + */ |
| 50 | + @GET("w/api.php?action=query&format=json&formatversion=2&generator=allcategories&prop=categoryinfo|description|pageimages&piprop=thumbnail&pithumbsize=70") |
| 51 | + fun getCategoriesByName( |
| 52 | + @Query("gacfrom") startingCategory: String?, |
| 53 | + @Query("gacto") endingCategory: String?, |
| 54 | + @Query("gaclimit") itemLimit: Int, |
| 55 | + @Query("gacoffset") offset: Int |
| 56 | + ): Single<MwQueryResponse> |
| 57 | + |
| 58 | + @GET("w/api.php?action=query&format=json&formatversion=2&generator=categorymembers&gcmtype=subcat&prop=info&gcmlimit=50") |
| 59 | + fun getSubCategoryList( |
| 60 | + @Query("gcmtitle") categoryName: String, |
| 61 | + @QueryMap(encoded = true) continuation: Map<String, String> |
| 62 | + ): Single<MwQueryResponse> |
| 63 | + |
| 64 | + @GET("w/api.php?action=query&format=json&formatversion=2&generator=categories&prop=info&gcllimit=50") |
| 65 | + fun getParentCategoryList( |
| 66 | + @Query("titles") categoryName: String?, |
| 67 | + @QueryMap(encoded = true) continuation: Map<String, String> |
| 68 | + ): Single<MwQueryResponse> |
| 69 | +} |
0 commit comments