mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
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:
parent
c6cb97e199
commit
f9090b0c2c
20 changed files with 535 additions and 524 deletions
|
|
@ -1,71 +0,0 @@
|
||||||
package fr.free.nrw.commons.category;
|
|
||||||
|
|
||||||
import io.reactivex.Single;
|
|
||||||
import java.util.Map;
|
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
|
||||||
import retrofit2.http.GET;
|
|
||||||
import retrofit2.http.Query;
|
|
||||||
import retrofit2.http.QueryMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for interacting with Commons category related APIs
|
|
||||||
*/
|
|
||||||
public interface CategoryInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches for categories with the specified name.
|
|
||||||
*
|
|
||||||
* @param filter The string to be searched
|
|
||||||
* @param itemLimit How many results are returned
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2"
|
|
||||||
+ "&generator=search&prop=description|pageimages&piprop=thumbnail&pithumbsize=70"
|
|
||||||
+ "&gsrnamespace=14")
|
|
||||||
Single<MwQueryResponse> searchCategories(@Query("gsrsearch") String filter,
|
|
||||||
@Query("gsrlimit") int itemLimit,
|
|
||||||
@Query("gsroffset") int offset);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches for categories starting with the specified prefix.
|
|
||||||
*
|
|
||||||
* @param prefix The string to be searched
|
|
||||||
* @param itemLimit How many results are returned
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2"
|
|
||||||
+ "&generator=allcategories&prop=categoryinfo|description|pageimages&piprop=thumbnail"
|
|
||||||
+ "&pithumbsize=70")
|
|
||||||
Single<MwQueryResponse> searchCategoriesForPrefix(@Query("gacprefix") String prefix,
|
|
||||||
@Query("gaclimit") int itemLimit,
|
|
||||||
@Query("gacoffset") int offset);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches categories starting and ending with a specified name.
|
|
||||||
*
|
|
||||||
* @param startingCategory Name of the category to start
|
|
||||||
* @param endingCategory Name of the category to end
|
|
||||||
* @param itemLimit How many categories to return
|
|
||||||
* @param offset offset
|
|
||||||
* @return MwQueryResponse
|
|
||||||
*/
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2"
|
|
||||||
+ "&generator=allcategories&prop=categoryinfo|description|pageimages&piprop=thumbnail"
|
|
||||||
+ "&pithumbsize=70")
|
|
||||||
Single<MwQueryResponse> getCategoriesByName(@Query("gacfrom") String startingCategory,
|
|
||||||
@Query("gacto") String endingCategory,
|
|
||||||
@Query("gaclimit") int itemLimit,
|
|
||||||
@Query("gacoffset") int offset);
|
|
||||||
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2"
|
|
||||||
+ "&generator=categorymembers&gcmtype=subcat"
|
|
||||||
+ "&prop=info&gcmlimit=50")
|
|
||||||
Single<MwQueryResponse> getSubCategoryList(@Query("gcmtitle") String categoryName,
|
|
||||||
@QueryMap(encoded = true) Map<String, String> continuation);
|
|
||||||
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2"
|
|
||||||
+ "&generator=categories&prop=info&gcllimit=50")
|
|
||||||
Single<MwQueryResponse> getParentCategoryList(@Query("titles") String categoryName,
|
|
||||||
@QueryMap(encoded = true) Map<String, String> continuation);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package fr.free.nrw.commons.category
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
|
import io.reactivex.Single
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Query
|
||||||
|
import retrofit2.http.QueryMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for interacting with Commons category related APIs
|
||||||
|
*/
|
||||||
|
interface CategoryInterface {
|
||||||
|
/**
|
||||||
|
* Searches for categories with the specified name.
|
||||||
|
*
|
||||||
|
* @param filter The string to be searched
|
||||||
|
* @param itemLimit How many results are returned
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GET("w/api.php?action=query&format=json&formatversion=2&generator=search&prop=description|pageimages&piprop=thumbnail&pithumbsize=70&gsrnamespace=14")
|
||||||
|
fun searchCategories(
|
||||||
|
@Query("gsrsearch") filter: String?,
|
||||||
|
@Query("gsrlimit") itemLimit: Int,
|
||||||
|
@Query("gsroffset") offset: Int
|
||||||
|
): Single<MwQueryResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for categories starting with the specified prefix.
|
||||||
|
*
|
||||||
|
* @param prefix The string to be searched
|
||||||
|
* @param itemLimit How many results are returned
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GET("w/api.php?action=query&format=json&formatversion=2&generator=allcategories&prop=categoryinfo|description|pageimages&piprop=thumbnail&pithumbsize=70")
|
||||||
|
fun searchCategoriesForPrefix(
|
||||||
|
@Query("gacprefix") prefix: String?,
|
||||||
|
@Query("gaclimit") itemLimit: Int,
|
||||||
|
@Query("gacoffset") offset: Int
|
||||||
|
): Single<MwQueryResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches categories starting and ending with a specified name.
|
||||||
|
*
|
||||||
|
* @param startingCategory Name of the category to start
|
||||||
|
* @param endingCategory Name of the category to end
|
||||||
|
* @param itemLimit How many categories to return
|
||||||
|
* @param offset offset
|
||||||
|
* @return MwQueryResponse
|
||||||
|
*/
|
||||||
|
@GET("w/api.php?action=query&format=json&formatversion=2&generator=allcategories&prop=categoryinfo|description|pageimages&piprop=thumbnail&pithumbsize=70")
|
||||||
|
fun getCategoriesByName(
|
||||||
|
@Query("gacfrom") startingCategory: String?,
|
||||||
|
@Query("gacto") endingCategory: String?,
|
||||||
|
@Query("gaclimit") itemLimit: Int,
|
||||||
|
@Query("gacoffset") offset: 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,
|
||||||
|
@QueryMap(encoded = true) continuation: Map<String, String>
|
||||||
|
): Single<MwQueryResponse>
|
||||||
|
|
||||||
|
@GET("w/api.php?action=query&format=json&formatversion=2&generator=categories&prop=info&gcllimit=50")
|
||||||
|
fun getParentCategoryList(
|
||||||
|
@Query("titles") categoryName: String?,
|
||||||
|
@QueryMap(encoded = true) continuation: Map<String, String>
|
||||||
|
): Single<MwQueryResponse>
|
||||||
|
}
|
||||||
|
|
@ -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
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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>
|
||||||
|
}
|
||||||
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
182
app/src/main/java/fr/free/nrw/commons/media/MediaInterface.kt
Normal file
182
app/src/main/java/fr/free/nrw/commons/media/MediaInterface.kt
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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>
|
||||||
|
}
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
package fr.free.nrw.commons.mwapi;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import retrofit2.http.GET;
|
|
||||||
import retrofit2.http.Query;
|
|
||||||
import retrofit2.http.QueryMap;
|
|
||||||
|
|
||||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
|
||||||
|
|
||||||
public interface UserInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the log events of user
|
|
||||||
* @param user name of user without prefix
|
|
||||||
* @param continuation continuation params returned in previous query
|
|
||||||
* @return query response
|
|
||||||
*/
|
|
||||||
|
|
||||||
@GET(MW_API_PREFIX + "action=query&list=logevents&letype=upload&leprop=title|timestamp|ids&lelimit=500")
|
|
||||||
Observable<MwQueryResponse> getUserLogEvents(@Query("leuser") String user, @QueryMap Map<String, String> continuation);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if a user is currently blocked from Commons
|
|
||||||
*/
|
|
||||||
@GET(MW_API_PREFIX + "action=query&meta=userinfo&uiprop=blockinfo")
|
|
||||||
Observable<MwQueryResponse> getUserBlockInfo();
|
|
||||||
}
|
|
||||||
28
app/src/main/java/fr/free/nrw/commons/mwapi/UserInterface.kt
Normal file
28
app/src/main/java/fr/free/nrw/commons/mwapi/UserInterface.kt
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package fr.free.nrw.commons.mwapi
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.WikidataConstants
|
||||||
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Query
|
||||||
|
import retrofit2.http.QueryMap
|
||||||
|
|
||||||
|
interface UserInterface {
|
||||||
|
/**
|
||||||
|
* Gets the log events of user
|
||||||
|
* @param user name of user without prefix
|
||||||
|
* @param continuation continuation params returned in previous query
|
||||||
|
* @return query response
|
||||||
|
*/
|
||||||
|
@GET(WikidataConstants.MW_API_PREFIX + "action=query&list=logevents&letype=upload&leprop=title|timestamp|ids&lelimit=500")
|
||||||
|
fun getUserLogEvents(
|
||||||
|
@Query("leuser") user: String?,
|
||||||
|
@QueryMap continuation: Map<String?, String?>?
|
||||||
|
): Observable<MwQueryResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a user is currently blocked from Commons
|
||||||
|
*/
|
||||||
|
@GET(WikidataConstants.MW_API_PREFIX + "action=query&meta=userinfo&uiprop=blockinfo")
|
||||||
|
fun getUserBlockInfo(): Observable<MwQueryResponse>
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
package fr.free.nrw.commons.review;
|
package fr.free.nrw.commons.review
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Observable;
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.Query
|
||||||
import retrofit2.http.Query;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface class for peer review calls
|
* Interface class for peer review calls
|
||||||
*/
|
*/
|
||||||
public interface ReviewInterface {
|
interface ReviewInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch recent changes from MediaWiki API
|
* Fetch recent changes from MediaWiki API
|
||||||
* Calls the API for the latest 50 changes (the default limit is 10)
|
* Calls the API for the latest 50 changes (the default limit is 10)
|
||||||
|
|
@ -21,11 +19,11 @@ public interface ReviewInterface {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2&generator=categorymembers&gcmtype=file&gcmsort=timestamp&gcmdir=desc&gcmtitle=Category:Uploaded_with_Mobile/Android&gcmlimit=50")
|
@GET("w/api.php?action=query&format=json&formatversion=2&generator=categorymembers&gcmtype=file&gcmsort=timestamp&gcmdir=desc&gcmtitle=Category:Uploaded_with_Mobile/Android&gcmlimit=50")
|
||||||
Observable<MwQueryResponse> getRecentChanges();
|
fun getRecentChanges(): Observable<MwQueryResponse>
|
||||||
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2&prop=revisions&rvprop=timestamp|ids|user&rvdir=newer&rvlimit=1")
|
@GET("w/api.php?action=query&format=json&formatversion=2&prop=revisions&rvprop=timestamp|ids|user&rvdir=newer&rvlimit=1")
|
||||||
Observable<MwQueryResponse> getFirstRevisionOfFile(@Query("titles") String titles);
|
fun getFirstRevisionOfFile(@Query("titles") titles: String?): Observable<MwQueryResponse>
|
||||||
|
|
||||||
@GET("w/api.php?action=query&format=json&formatversion=2&prop=fileusage|globalusage")
|
@GET("w/api.php?action=query&format=json&formatversion=2&prop=fileusage|globalusage")
|
||||||
Observable<MwQueryResponse> getGlobalUsageInfo(@Query("titles") String title);
|
fun getGlobalUsageInfo(@Query("titles") title: String?): Observable<MwQueryResponse>
|
||||||
}
|
}
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
package fr.free.nrw.commons.upload;
|
|
||||||
|
|
||||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import okhttp3.MultipartBody;
|
|
||||||
import okhttp3.RequestBody;
|
|
||||||
import retrofit2.http.Field;
|
|
||||||
import retrofit2.http.FormUrlEncoded;
|
|
||||||
import retrofit2.http.Headers;
|
|
||||||
import retrofit2.http.Multipart;
|
|
||||||
import retrofit2.http.POST;
|
|
||||||
import retrofit2.http.Part;
|
|
||||||
|
|
||||||
public interface UploadInterface {
|
|
||||||
|
|
||||||
@Multipart
|
|
||||||
@POST(MW_API_PREFIX + "action=upload&stash=1&ignorewarnings=1")
|
|
||||||
Observable<UploadResponse> uploadFileToStash(@Part("filename") RequestBody filename,
|
|
||||||
@Part("filesize") RequestBody totalFileSize,
|
|
||||||
@Part("offset") RequestBody offset,
|
|
||||||
@Part("filekey") RequestBody fileKey,
|
|
||||||
@Part("token") RequestBody token,
|
|
||||||
@Part MultipartBody.Part filePart);
|
|
||||||
|
|
||||||
@Headers("Cache-Control: no-cache")
|
|
||||||
@POST(MW_API_PREFIX + "action=upload&ignorewarnings=1")
|
|
||||||
@FormUrlEncoded
|
|
||||||
@NonNull
|
|
||||||
Observable<JsonObject> uploadFileFromStash(@NonNull @Field("token") String token,
|
|
||||||
@NonNull @Field("text") String text,
|
|
||||||
@NonNull @Field("comment") String comment,
|
|
||||||
@NonNull @Field("filename") String filename,
|
|
||||||
@NonNull @Field("filekey") String filekey);
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import fr.free.nrw.commons.wikidata.WikidataConstants
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
import retrofit2.http.Field
|
||||||
|
import retrofit2.http.FormUrlEncoded
|
||||||
|
import retrofit2.http.Headers
|
||||||
|
import retrofit2.http.Multipart
|
||||||
|
import retrofit2.http.POST
|
||||||
|
import retrofit2.http.Part
|
||||||
|
import okhttp3.MultipartBody.Part as MultipartBodyPart
|
||||||
|
|
||||||
|
interface UploadInterface {
|
||||||
|
@Multipart
|
||||||
|
@POST(WikidataConstants.MW_API_PREFIX + "action=upload&stash=1&ignorewarnings=1")
|
||||||
|
fun uploadFileToStash(
|
||||||
|
@Part("filename") filename: RequestBody?,
|
||||||
|
@Part("filesize") totalFileSize: RequestBody?,
|
||||||
|
@Part("offset") offset: RequestBody?,
|
||||||
|
@Part("filekey") fileKey: RequestBody?,
|
||||||
|
@Part("token") token: RequestBody?,
|
||||||
|
@Part filePart: MultipartBodyPart
|
||||||
|
): Observable<UploadResponse>
|
||||||
|
|
||||||
|
@Headers("Cache-Control: no-cache")
|
||||||
|
@POST(WikidataConstants.MW_API_PREFIX + "action=upload&ignorewarnings=1")
|
||||||
|
@FormUrlEncoded
|
||||||
|
fun uploadFileFromStash(
|
||||||
|
@Field("token") token: String,
|
||||||
|
@Field("text") text: String,
|
||||||
|
@Field("comment") comment: String,
|
||||||
|
@Field("filename") filename: String,
|
||||||
|
@Field("filekey") filekey: String
|
||||||
|
): Observable<JsonObject>
|
||||||
|
}
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
package fr.free.nrw.commons.upload;
|
|
||||||
|
|
||||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse;
|
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
|
||||||
import retrofit2.http.Field;
|
|
||||||
import retrofit2.http.FormUrlEncoded;
|
|
||||||
import retrofit2.http.GET;
|
|
||||||
import retrofit2.http.Headers;
|
|
||||||
import retrofit2.http.POST;
|
|
||||||
import retrofit2.http.Query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrofit calls for managing responses network calls of entity ids required for uploading depictions
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface WikiBaseInterface {
|
|
||||||
|
|
||||||
@Headers("Cache-Control: no-cache")
|
|
||||||
@FormUrlEncoded
|
|
||||||
@POST(MW_API_PREFIX + "action=wbeditentity")
|
|
||||||
Observable<MwPostResponse> postEditEntity(@NonNull @Field("id") String fileEntityId,
|
|
||||||
@NonNull @Field("token") String editToken,
|
|
||||||
@NonNull @Field("data") String data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uploads depicts for a file in the server
|
|
||||||
*
|
|
||||||
* @param filename name of the file
|
|
||||||
* @param editToken editToken for the file
|
|
||||||
* @param data data of the depicts to be uploaded
|
|
||||||
* @return Observable<MwPostResponse>
|
|
||||||
*/
|
|
||||||
@Headers("Cache-Control: no-cache")
|
|
||||||
@FormUrlEncoded
|
|
||||||
@POST(MW_API_PREFIX + "action=wbeditentity&site=commonswiki&clear=1")
|
|
||||||
Observable<MwPostResponse> postEditEntityByFilename(@NonNull @Field("title") String filename,
|
|
||||||
@NonNull @Field("token") String editToken,
|
|
||||||
@NonNull @Field("data") String data);
|
|
||||||
|
|
||||||
@GET(MW_API_PREFIX + "action=query&prop=info")
|
|
||||||
Observable<MwQueryResponse> getFileEntityId(@Query("titles") String fileName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload Captions for the image when upload is successful
|
|
||||||
*
|
|
||||||
* @param fileEntityId enityId for the uploaded file
|
|
||||||
* @param editToken editToken for the file
|
|
||||||
* @param captionValue value of the caption to be uploaded
|
|
||||||
*/
|
|
||||||
@FormUrlEncoded
|
|
||||||
@POST(MW_API_PREFIX + "action=wbsetlabel")
|
|
||||||
Observable<MwPostResponse> addLabelstoWikidata(@Field("id") String fileEntityId,
|
|
||||||
@Field("token") String editToken,
|
|
||||||
@Field("language") String language,
|
|
||||||
@Field("value") String captionValue);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package fr.free.nrw.commons.upload
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.WikidataConstants
|
||||||
|
import fr.free.nrw.commons.wikidata.mwapi.MwPostResponse
|
||||||
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import retrofit2.http.Field
|
||||||
|
import retrofit2.http.FormUrlEncoded
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Headers
|
||||||
|
import retrofit2.http.POST
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrofit calls for managing responses network calls of entity ids required for uploading depictions
|
||||||
|
*/
|
||||||
|
interface WikiBaseInterface {
|
||||||
|
@Headers("Cache-Control: no-cache")
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST(WikidataConstants.MW_API_PREFIX + "action=wbeditentity")
|
||||||
|
fun postEditEntity(
|
||||||
|
@Field("id") fileEntityId: String,
|
||||||
|
@Field("token") editToken: String,
|
||||||
|
@Field("data") data: String
|
||||||
|
): Observable<MwPostResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads depicts for a file in the server
|
||||||
|
*
|
||||||
|
* @param filename name of the file
|
||||||
|
* @param editToken editToken for the file
|
||||||
|
* @param data data of the depicts to be uploaded
|
||||||
|
* @return Observable<MwPostResponse>
|
||||||
|
</MwPostResponse> */
|
||||||
|
@Headers("Cache-Control: no-cache")
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST(WikidataConstants.MW_API_PREFIX + "action=wbeditentity&site=commonswiki&clear=1")
|
||||||
|
fun postEditEntityByFilename(
|
||||||
|
@Field("title") filename: String,
|
||||||
|
@Field("token") editToken: String,
|
||||||
|
@Field("data") data: String
|
||||||
|
): Observable<MwPostResponse>
|
||||||
|
|
||||||
|
@GET(WikidataConstants.MW_API_PREFIX + "action=query&prop=info")
|
||||||
|
fun getFileEntityId(@Query("titles") fileName: String?): Observable<MwQueryResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload Captions for the image when upload is successful
|
||||||
|
*
|
||||||
|
* @param fileEntityId enityId for the uploaded file
|
||||||
|
* @param editToken editToken for the file
|
||||||
|
* @param captionValue value of the caption to be uploaded
|
||||||
|
*/
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST(WikidataConstants.MW_API_PREFIX + "action=wbsetlabel")
|
||||||
|
fun addLabelstoWikidata(
|
||||||
|
@Field("id") fileEntityId: String?,
|
||||||
|
@Field("token") editToken: String?,
|
||||||
|
@Field("language") language: String?,
|
||||||
|
@Field("value") captionValue: String?
|
||||||
|
): Observable<MwPostResponse>
|
||||||
|
}
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
package fr.free.nrw.commons.upload.depicts;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.model.DepictSearchResponse;
|
|
||||||
import fr.free.nrw.commons.wikidata.model.Entities;
|
|
||||||
import io.reactivex.Single;
|
|
||||||
import retrofit2.http.GET;
|
|
||||||
import retrofit2.http.Query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manges retrofit calls for Searching of depicts from DepictsFragment
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface DepictsInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search for depictions using the wbsearchentities API
|
|
||||||
* @param query search for depictions based on user query
|
|
||||||
* @param limit number of depictions to be retrieved
|
|
||||||
* @param language current locale of the phone
|
|
||||||
* @param uselang current locale of the phone
|
|
||||||
* @param offset number of depictions already fetched useful in implementing pagination
|
|
||||||
*/
|
|
||||||
@GET("/w/api.php?action=wbsearchentities&format=json&type=item&uselang=en")
|
|
||||||
Single<DepictSearchResponse> searchForDepicts(@Query("search") String query, @Query("limit") String limit, @Query("language") String language, @Query("uselang") String uselang, @Query("continue") String offset);
|
|
||||||
|
|
||||||
@GET("/w/api.php?format=json&action=wbgetentities")
|
|
||||||
Single<Entities> getEntities(@Query("ids") String ids);
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package fr.free.nrw.commons.upload.depicts
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.model.DepictSearchResponse
|
||||||
|
import fr.free.nrw.commons.wikidata.model.Entities
|
||||||
|
import io.reactivex.Single
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Query
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manges retrofit calls for Searching of depicts from DepictsFragment
|
||||||
|
*/
|
||||||
|
interface DepictsInterface {
|
||||||
|
/**
|
||||||
|
* Search for depictions using the wbsearchentities API
|
||||||
|
* @param query search for depictions based on user query
|
||||||
|
* @param limit number of depictions to be retrieved
|
||||||
|
* @param language current locale of the phone
|
||||||
|
* @param uselang current locale of the phone
|
||||||
|
* @param offset number of depictions already fetched useful in implementing pagination
|
||||||
|
*/
|
||||||
|
@GET("/w/api.php?action=wbsearchentities&format=json&type=item&uselang=en")
|
||||||
|
fun searchForDepicts(
|
||||||
|
@Query("search") query: String?,
|
||||||
|
@Query("limit") limit: String?,
|
||||||
|
@Query("language") language: String?,
|
||||||
|
@Query("uselang") uselang: String?,
|
||||||
|
@Query("continue") offset: String?
|
||||||
|
): Single<DepictSearchResponse>
|
||||||
|
|
||||||
|
@GET("/w/api.php?format=json&action=wbgetentities")
|
||||||
|
fun getEntities(@Query("ids") ids: String?): Single<Entities>
|
||||||
|
}
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package fr.free.nrw.commons.wikidata;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse;
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import retrofit2.http.Field;
|
|
||||||
import retrofit2.http.FormUrlEncoded;
|
|
||||||
import retrofit2.http.GET;
|
|
||||||
import retrofit2.http.Headers;
|
|
||||||
import retrofit2.http.POST;
|
|
||||||
|
|
||||||
import static fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX;
|
|
||||||
|
|
||||||
public interface WikidataInterface {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get edit token for wikidata wiki site
|
|
||||||
*/
|
|
||||||
@Headers("Cache-Control: no-cache")
|
|
||||||
@GET(MW_API_PREFIX + "action=query&meta=tokens&type=csrf")
|
|
||||||
@NonNull
|
|
||||||
Observable<MwQueryResponse> getCsrfToken();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wikidata create claim API. Posts a new claim for the given entity ID
|
|
||||||
*/
|
|
||||||
@Headers("Cache-Control: no-cache")
|
|
||||||
@POST("w/api.php?format=json&action=wbsetclaim")
|
|
||||||
@FormUrlEncoded
|
|
||||||
Observable<WbCreateClaimResponse> postSetClaim(@NonNull @Field("claim") String request,
|
|
||||||
@NonNull @Field("tags") String tags,
|
|
||||||
@NonNull @Field("token") String token);
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package fr.free.nrw.commons.wikidata
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.wikidata.model.WbCreateClaimResponse
|
||||||
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import retrofit2.http.Field
|
||||||
|
import retrofit2.http.FormUrlEncoded
|
||||||
|
import retrofit2.http.GET
|
||||||
|
import retrofit2.http.Headers
|
||||||
|
import retrofit2.http.POST
|
||||||
|
|
||||||
|
interface WikidataInterface {
|
||||||
|
/**
|
||||||
|
* Get edit token for wikidata wiki site
|
||||||
|
*/
|
||||||
|
@Headers("Cache-Control: no-cache")
|
||||||
|
@GET(WikidataConstants.MW_API_PREFIX + "action=query&meta=tokens&type=csrf")
|
||||||
|
fun getCsrfToken(): Observable<MwQueryResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wikidata create claim API. Posts a new claim for the given entity ID
|
||||||
|
*/
|
||||||
|
@Headers("Cache-Control: no-cache")
|
||||||
|
@POST("w/api.php?format=json&action=wbsetclaim")
|
||||||
|
@FormUrlEncoded
|
||||||
|
fun postSetClaim(
|
||||||
|
@Field("claim") request: String,
|
||||||
|
@Field("tags") tags: String,
|
||||||
|
@Field("token") token: String
|
||||||
|
): Observable<WbCreateClaimResponse>
|
||||||
|
}
|
||||||
|
|
@ -33,7 +33,7 @@ class UserClientTest{
|
||||||
Mockito.`when`(mwQueryResult.userInfo()).thenReturn(userInfo)
|
Mockito.`when`(mwQueryResult.userInfo()).thenReturn(userInfo)
|
||||||
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
||||||
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||||
Mockito.`when`(userInterface!!.userBlockInfo)
|
Mockito.`when`(userInterface!!.getUserBlockInfo())
|
||||||
.thenReturn(Observable.just(mockResponse))
|
.thenReturn(Observable.just(mockResponse))
|
||||||
|
|
||||||
val isBanned = userClient!!.isUserBlockedFromCommons.blockingGet()
|
val isBanned = userClient!!.isUserBlockedFromCommons.blockingGet()
|
||||||
|
|
@ -51,7 +51,7 @@ class UserClientTest{
|
||||||
Mockito.`when`(mwQueryResult.userInfo()).thenReturn(userInfo)
|
Mockito.`when`(mwQueryResult.userInfo()).thenReturn(userInfo)
|
||||||
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
||||||
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||||
Mockito.`when`(userInterface!!.userBlockInfo)
|
Mockito.`when`(userInterface!!.getUserBlockInfo())
|
||||||
.thenReturn(Observable.just(mockResponse))
|
.thenReturn(Observable.just(mockResponse))
|
||||||
|
|
||||||
val isBanned = userClient!!.isUserBlockedFromCommons.blockingGet()
|
val isBanned = userClient!!.isUserBlockedFromCommons.blockingGet()
|
||||||
|
|
@ -66,7 +66,7 @@ class UserClientTest{
|
||||||
Mockito.`when`(mwQueryResult.userInfo()).thenReturn(userInfo)
|
Mockito.`when`(mwQueryResult.userInfo()).thenReturn(userInfo)
|
||||||
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
val mockResponse = Mockito.mock(MwQueryResponse::class.java)
|
||||||
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
Mockito.`when`(mockResponse.query()).thenReturn(mwQueryResult)
|
||||||
Mockito.`when`(userInterface!!.userBlockInfo)
|
Mockito.`when`(userInterface!!.getUserBlockInfo())
|
||||||
.thenReturn(Observable.just(mockResponse))
|
.thenReturn(Observable.just(mockResponse))
|
||||||
|
|
||||||
val isBanned = userClient!!.isUserBlockedFromCommons.blockingGet()
|
val isBanned = userClient!!.isUserBlockedFromCommons.blockingGet()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue