Consistent api interfaces (#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
This commit is contained in:
Paul Hawke 2024-02-08 22:43:01 -06:00 committed by GitHub
parent c6cb97e199
commit f9090b0c2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 535 additions and 524 deletions

View file

@ -1,51 +0,0 @@
package fr.free.nrw.commons.media;
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
import fr.free.nrw.commons.wikidata.model.Entities;
import io.reactivex.Observable;
import io.reactivex.Single;
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
import retrofit2.http.GET;
import retrofit2.http.Query;
/**
* Interface for interacting with Commons Structured Data related APIs
*/
public interface MediaDetailInterface {
/**
* Fetches entity using file name
*
* @param filename name of the file to be used for fetching captions
*/
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
Observable<Entities> fetchEntitiesByFileName(@Query("languages") String language, @Query("titles") String filename);
/**
* Gets labels for Depictions using Entity Id from MediaWikiAPI
* @param entityId EntityId (Ex: Q81566) of the depict entity
*
*/
@GET("/w/api.php?format=json&action=wbgetentities&props=labels&languagefallback=1")
Single<Entities> getEntity(@Query("ids") String entityId);
/**
* Fetches caption using wikibaseIdentifier
*
* @param wikibaseIdentifier pageId for the media
*/
@GET("/w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
Observable<Entities> getEntityForImage(@Query("languages") String language, @Query("ids") String wikibaseIdentifier);
/**
* Fetches current wikitext
* @param title file name
* @return Single<MwQueryResponse>
*/
@GET(MW_API_PREFIX + "action=query&prop=revisions&rvprop=content|timestamp&rvlimit=1&converttitles=")
Single<MwQueryResponse> getWikiText(
@Query("titles") String title
);
}

View file

@ -0,0 +1,53 @@
package fr.free.nrw.commons.media
import fr.free.nrw.commons.wikidata.WikidataConstants
import fr.free.nrw.commons.wikidata.model.Entities
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
import io.reactivex.Observable
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Query
/**
* Interface for interacting with Commons Structured Data related APIs
*/
interface MediaDetailInterface {
/**
* Fetches entity using file name
*
* @param filename name of the file to be used for fetching captions
*/
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
fun fetchEntitiesByFileName(
@Query("languages") language: String?,
@Query("titles") filename: String?
): Observable<Entities>
/**
* Gets labels for Depictions using Entity Id from MediaWikiAPI
* @param entityId EntityId (Ex: Q81566) of the depict entity
*/
@GET("/w/api.php?format=json&action=wbgetentities&props=labels&languagefallback=1")
fun getEntity(@Query("ids") entityId: String?): Single<Entities>
/**
* Fetches caption using wikibaseIdentifier
*
* @param wikibaseIdentifier pageId for the media
*/
@GET("/w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1&sites=commonswiki")
fun getEntityForImage(
@Query("languages") language: String?,
@Query("ids") wikibaseIdentifier: String?
): Observable<Entities>
/**
* Fetches current wikitext
* @param title file name
* @return Single<MwQueryResponse>
</MwQueryResponse> */
@GET(WikidataConstants.MW_API_PREFIX + "action=query&prop=revisions&rvprop=content|timestamp&rvlimit=1&converttitles=")
fun getWikiText(
@Query("titles") title: String?
): Single<MwQueryResponse>
}

View file

@ -1,166 +0,0 @@
package fr.free.nrw.commons.media;
import static fr.free.nrw.commons.OkHttpConnectionFactory.UnsuccessfulResponseInterceptor.SUPPRESS_ERROR_LOG_HEADER;
import io.reactivex.Single;
import java.util.Map;
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
/**
* Interface for interacting with Commons media related APIs
*/
public interface MediaInterface {
String MEDIA_PARAMS="&prop=imageinfo|coordinates&iiprop=url|extmetadata|user&&iiurlwidth=640" +
"&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal" +
"|Artist|LicenseShortName|LicenseUrl";
/**
* fetches category detail(title, hidden) for each category along with File information
*/
String MEDIA_PARAMS_WITH_CATEGORY_DETAILS ="&clprop=hidden&prop=categories|imageinfo&iiprop=url|extmetadata|user&&iiurlwidth=640" +
"&iiextmetadatafilter=DateTime|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal" +
"|Artist|LicenseShortName|LicenseUrl";
/**
* Checks if a page exists or not.
*
* @param title the title of the page to be checked
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2")
Single<MwQueryResponse> checkPageExistsUsingTitle(@Query("titles") String title);
/**
* Check if file exists
*
* @param aisha1 the SHA of the media file to be checked
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2&list=allimages")
Single<MwQueryResponse> checkFileExistsUsingSha(@Query("aisha1") String aisha1);
/**
* This method retrieves a list of Media objects filtered using image generator query
*
* @param category the category name. Must start with "Category:"
* @param itemLimit how many images are returned
* @param continuation the continuation string from the previous query or empty map
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=categorymembers&gcmtype=file&gcmsort=timestamp&gcmdir=desc" + //Category parameters
MEDIA_PARAMS)
Single<MwQueryResponse> getMediaListFromCategory(@Query("gcmtitle") String category, @Query("gcmlimit") int itemLimit, @QueryMap Map<String, String> continuation);
/**
* This method retrieves a list of Media objects for a given user name
*
* @param username user's Wikimedia Commons username.
* @param itemLimit how many images are returned
* @param continuation the continuation string from the previous query or empty map
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=allimages&gaisort=timestamp&gaidir=older" + MEDIA_PARAMS)
Single<MwQueryResponse> getMediaListForUser(@Query("gaiuser") String username,
@Query("gailimit") int itemLimit, @QueryMap(encoded = true) Map<String, String> continuation);
/**
* This method retrieves a list of Media objects filtered using image generator query
*
* @param keyword the searched keyword
* @param itemLimit how many images are returned
* @param offset the offset in the result set
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrwhat=text&gsrnamespace=6" + //Search parameters
MEDIA_PARAMS)
Single<MwQueryResponse> getMediaListFromSearch(@Query("gsrsearch") String keyword,
@Query("gsrlimit") int itemLimit, @Query("gsroffset") int offset);
/**
* This method retrieves a list of Media objects filtered using list geosearch query. Example: https://commons.wikimedia.org/w/api.php?action=query&format=json&formatversion=2&generator=geosearch&ggsnamespace=6&prop=imageinfo|coordinates&iiprop=url|extmetadata|user&&iiurlwidth=640&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl&ggscoord=37.45579%7C-122.31369&ggslimit=30&ggsradius=10000
*
* @param location the search location
* @param itemLimit how many images are returned
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=geosearch&ggsnamespace=6" + //Search parameters
MEDIA_PARAMS)
Single<MwQueryResponse> getMediaListFromGeoSearch(@Query("ggscoord") String location, @Query("ggslimit") int itemLimit, @Query("ggsradius") int radius);
/**
* Fetches Media object from the imageInfo API
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" +
MEDIA_PARAMS_WITH_CATEGORY_DETAILS)
Single<MwQueryResponse> getMedia(@Query("titles") String title);
/**
* Fetches Media object from the imageInfo API but suppress (known) errors
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" +
MEDIA_PARAMS_WITH_CATEGORY_DETAILS)
@Headers(SUPPRESS_ERROR_LOG_HEADER)
Single<MwQueryResponse> getMediaSuppressingErrors(@Query("titles") String title);
/**
* Fetches Media object from the imageInfo API
*
* @param pageIds the ids to be searched for
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" +
MEDIA_PARAMS)
@Headers(SUPPRESS_ERROR_LOG_HEADER)
Single<MwQueryResponse> getMediaById(@Query("pageids") String pageIds);
/**
* Fetches Media object from the imageInfo API
* Passes an image generator parameter
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2&generator=images" +
MEDIA_PARAMS)
Single<MwQueryResponse> getMediaWithGenerator(@Query("titles") String title);
@GET("w/api.php?format=json&action=parse&prop=text")
@Headers(SUPPRESS_ERROR_LOG_HEADER)
Single<MwParseResponse> getPageHtml(@Query("page") String title);
/**
* Fetches caption using file name
*
* @param filename name of the file to be used for fetching captions
* */
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1")
Single<MwQueryResponse> fetchCaptionByFilename(@Query("language") String language, @Query("titles") String filename);
/**
* Fetches list of images from a depiction entity
* @param query depictionEntityId
* @param srlimit the number of items to fetch
* @param sroffset number od depictions already fetched, this is useful in implementing pagination
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrnamespace=6" + //Search parameters
MEDIA_PARAMS)
Single<MwQueryResponse> fetchImagesForDepictedItem(@Query("gsrsearch") String query,
@Query("gsrlimit")String srlimit, @Query("gsroffset") String sroffset);
}

View file

@ -0,0 +1,182 @@
package fr.free.nrw.commons.media
import fr.free.nrw.commons.OkHttpConnectionFactory.UnsuccessfulResponseInterceptor.SUPPRESS_ERROR_LOG_HEADER
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.Query
import retrofit2.http.QueryMap
/**
* Interface for interacting with Commons media related APIs
*/
interface MediaInterface {
/**
* Checks if a page exists or not.
*
* @param title the title of the page to be checked
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2")
fun checkPageExistsUsingTitle(@Query("titles") title: String?): Single<MwQueryResponse>
/**
* Check if file exists
*
* @param aisha1 the SHA of the media file to be checked
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2&list=allimages")
fun checkFileExistsUsingSha(@Query("aisha1") aisha1: String?): Single<MwQueryResponse>
/**
* This method retrieves a list of Media objects filtered using image generator query
*
* @param category the category name. Must start with "Category:"
* @param itemLimit how many images are returned
* @param continuation the continuation string from the previous query or empty map
* @return
*/
@GET(
"w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=categorymembers&gcmtype=file&gcmsort=timestamp&gcmdir=desc$MEDIA_PARAMS" //Category parameters
)
fun getMediaListFromCategory(
@Query("gcmtitle") category: String?,
@Query("gcmlimit") itemLimit: Int,
@QueryMap continuation: Map<String, String>
): Single<MwQueryResponse>
/**
* This method retrieves a list of Media objects for a given user name
*
* @param username user's Wikimedia Commons username.
* @param itemLimit how many images are returned
* @param continuation the continuation string from the previous query or empty map
* @return
*/
@GET(
"w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=allimages&gaisort=timestamp&gaidir=older$MEDIA_PARAMS"
)
fun getMediaListForUser(
@Query("gaiuser") username: String?,
@Query("gailimit") itemLimit: Int,
@QueryMap(encoded = true) continuation: Map<String, String>
): Single<MwQueryResponse>
/**
* This method retrieves a list of Media objects filtered using image generator query
*
* @param keyword the searched keyword
* @param itemLimit how many images are returned
* @param offset the offset in the result set
* @return
*/
@GET(
"w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrwhat=text&gsrnamespace=6$MEDIA_PARAMS" //Search parameters
)
fun getMediaListFromSearch(
@Query("gsrsearch") keyword: String?,
@Query("gsrlimit") itemLimit: Int, @Query("gsroffset") offset: Int
): Single<MwQueryResponse>
/**
* This method retrieves a list of Media objects filtered using list geosearch query. Example: https://commons.wikimedia.org/w/api.php?action=query&format=json&formatversion=2&generator=geosearch&ggsnamespace=6&prop=imageinfo|coordinates&iiprop=url|extmetadata|user&&iiurlwidth=640&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl&ggscoord=37.45579%7C-122.31369&ggslimit=30&ggsradius=10000
*
* @param location the search location
* @param itemLimit how many images are returned
* @return
*/
@GET(
"w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=geosearch&ggsnamespace=6$MEDIA_PARAMS" //Search parameters
)
fun getMediaListFromGeoSearch(
@Query("ggscoord") location: String?,
@Query("ggslimit") itemLimit: Int,
@Query("ggsradius") radius: Int
): Single<MwQueryResponse>
/**
* Fetches Media object from the imageInfo API
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2$MEDIA_PARAMS_WITH_CATEGORY_DETAILS")
fun getMedia(@Query("titles") title: String?): Single<MwQueryResponse>
/**
* Fetches Media object from the imageInfo API but suppress (known) errors
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2$MEDIA_PARAMS_WITH_CATEGORY_DETAILS")
@Headers(SUPPRESS_ERROR_LOG_HEADER)
fun getMediaSuppressingErrors(@Query("titles") title: String?): Single<MwQueryResponse>
/**
* Fetches Media object from the imageInfo API
*
* @param pageIds the ids to be searched for
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2$MEDIA_PARAMS")
@Headers(SUPPRESS_ERROR_LOG_HEADER)
fun getMediaById(@Query("pageids") pageIds: String?): Single<MwQueryResponse>
/**
* Fetches Media object from the imageInfo API
* Passes an image generator parameter
*
* @param title the tiles to be searched for. Can be filename or template name
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2&generator=images$MEDIA_PARAMS")
fun getMediaWithGenerator(@Query("titles") title: String?): Single<MwQueryResponse>
@GET("w/api.php?format=json&action=parse&prop=text")
@Headers(SUPPRESS_ERROR_LOG_HEADER)
fun getPageHtml(@Query("page") title: String?): Single<MwParseResponse>
/**
* Fetches caption using file name
*
* @param filename name of the file to be used for fetching captions
*/
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1")
fun fetchCaptionByFilename(
@Query("language") language: String?,
@Query("titles") filename: String?
): Single<MwQueryResponse>
/**
* Fetches list of images from a depiction entity
* @param query depictionEntityId
* @param srlimit the number of items to fetch
* @param sroffset number od depictions already fetched, this is useful in implementing pagination
*/
@GET(
"w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrnamespace=6$MEDIA_PARAMS" //Search parameters
)
fun fetchImagesForDepictedItem(
@Query("gsrsearch") query: String?,
@Query("gsrlimit") srlimit: String?, @Query("gsroffset") sroffset: String?
): Single<MwQueryResponse>
companion object {
const val MEDIA_PARAMS =
"&prop=imageinfo|coordinates&iiprop=url|extmetadata|user&&iiurlwidth=640&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl"
/**
* fetches category detail(title, hidden) for each category along with File information
*/
const val MEDIA_PARAMS_WITH_CATEGORY_DETAILS =
"&clprop=hidden&prop=categories|imageinfo&iiprop=url|extmetadata|user&&iiurlwidth=640&iiextmetadatafilter=DateTime|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal|Artist|LicenseShortName|LicenseUrl"
}
}

View file

@ -1,29 +0,0 @@
package fr.free.nrw.commons.media;
import static fr.free.nrw.commons.media.MediaInterface.MEDIA_PARAMS;
import io.reactivex.Single;
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
import retrofit2.http.GET;
import retrofit2.http.Query;
/**
* Interface for getting Wikidata images from production server
*/
public interface WikidataMediaInterface {
/**
* Fetches list of images from a depiction entity
* @param query depictionEntityId ex. "haswbstatement:P180=Q9394"
* @param srlimit the number of items to fetch
* @param sroffset number of depictions already fetched,
* this is useful in implementing pagination
* @return Single<MwQueryResponse>
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrnamespace=6" + //Search parameters
MEDIA_PARAMS)
Single<MwQueryResponse> fetchImagesForDepictedItem(@Query("gsrsearch") String query,
@Query("gsrlimit")String srlimit, @Query("gsroffset") String sroffset);
}

View file

@ -0,0 +1,29 @@
package fr.free.nrw.commons.media
import fr.free.nrw.commons.media.MediaInterface.Companion.MEDIA_PARAMS
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Query
/**
* Interface for getting Wikidata images from production server
*/
interface WikidataMediaInterface {
/**
* Fetches list of images from a depiction entity
* @param query depictionEntityId ex. "haswbstatement:P180=Q9394"
* @param srlimit the number of items to fetch
* @param sroffset number of depictions already fetched,
* this is useful in implementing pagination
* @return Single<MwQueryResponse>
</MwQueryResponse> */
@GET(
"w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrnamespace=6$MEDIA_PARAMS" //Search parameters
)
fun fetchImagesForDepictedItem(
@Query("gsrsearch") query: String?,
@Query("gsrlimit") srlimit: String?, @Query("gsroffset") sroffset: String?
): Single<MwQueryResponse>
}