Skip to content

Commit f9090b0

Browse files
authored
Consistent api interfaces (commons-app#5530)
* Converted CategoryInterface to kotlin * Converted DepictsInterface to kotlin * Convert the MediaDetailInterface to kotlin * Convert MediaInterface to kotlin * Convert ReviewInterface to kotlin * Convert the UserInterface to kotlin * Convert the WikiBaseInterface to kotlin * Convert WikidataInterface to kotlin * Convert WikidataMediaInterface to kotlin * Convert UploadInterface to kotlin
1 parent c6cb97e commit f9090b0

20 files changed

+535
-524
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategoryInterface.java

-71
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}

app/src/main/java/fr/free/nrw/commons/media/MediaDetailInterface.java

-51
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package fr.free.nrw.commons.media
2+
3+
import fr.free.nrw.commons.wikidata.WikidataConstants
4+
import fr.free.nrw.commons.wikidata.model.Entities
5+
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
6+
import io.reactivex.Observable
7+
import io.reactivex.Single
8+
import retrofit2.http.GET
9+
import retrofit2.http.Query
10+
11+
/**
12+
* Interface for interacting with Commons Structured Data related APIs
13+
*/
14+
interface MediaDetailInterface {
15+
/**
16+
* Fetches entity using file name
17+
*
18+
* @param filename name of the file to be used for fetching captions
19+
*/
20+
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
21+
fun fetchEntitiesByFileName(
22+
@Query("languages") language: String?,
23+
@Query("titles") filename: String?
24+
): Observable<Entities>
25+
26+
/**
27+
* Gets labels for Depictions using Entity Id from MediaWikiAPI
28+
* @param entityId EntityId (Ex: Q81566) of the depict entity
29+
*/
30+
@GET("/w/api.php?format=json&action=wbgetentities&props=labels&languagefallback=1")
31+
fun getEntity(@Query("ids") entityId: String?): Single<Entities>
32+
33+
/**
34+
* Fetches caption using wikibaseIdentifier
35+
*
36+
* @param wikibaseIdentifier pageId for the media
37+
*/
38+
@GET("/w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
39+
fun getEntityForImage(
40+
@Query("languages") language: String?,
41+
@Query("ids") wikibaseIdentifier: String?
42+
): Observable<Entities>
43+
44+
/**
45+
* Fetches current wikitext
46+
* @param title file name
47+
* @return Single<MwQueryResponse>
48+
</MwQueryResponse> */
49+
@GET(WikidataConstants.MW_API_PREFIX + "action=query&prop=revisions&rvprop=content|timestamp&rvlimit=1&converttitles=")
50+
fun getWikiText(
51+
@Query("titles") title: String?
52+
): Single<MwQueryResponse>
53+
}

0 commit comments

Comments
 (0)