Skip to content

Consistent api interfaces #5530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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>
}
Loading