mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 05:43:55 +01:00
With media client APIs migrated to retrofit (#2998)
* With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests
This commit is contained in:
parent
828b5a3cd1
commit
78141cb609
17 changed files with 252 additions and 92 deletions
46
app/src/main/java/fr/free/nrw/commons/media/MediaClient.java
Normal file
46
app/src/main/java/fr/free/nrw/commons/media/MediaClient.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package fr.free.nrw.commons.media;
|
||||
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import io.reactivex.Single;
|
||||
|
||||
/**
|
||||
* Media Client to handle custom calls to Commons MediaWiki APIs
|
||||
*/
|
||||
@Singleton
|
||||
public class MediaClient {
|
||||
|
||||
private final MediaInterface mediaInterface;
|
||||
|
||||
@Inject
|
||||
public MediaClient(MediaInterface mediaInterface) {
|
||||
this.mediaInterface = mediaInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a page exists on Commons
|
||||
* The same method can be used to check for file or talk page
|
||||
*
|
||||
* @param title File:Test.jpg or Commons:Deletion_requests/File:Test1.jpeg
|
||||
*/
|
||||
public Single<Boolean> checkPageExistsUsingTitle(String title) {
|
||||
return mediaInterface.checkPageExistsUsingTitle(title)
|
||||
.map(mwQueryResponse -> mwQueryResponse
|
||||
.query().firstPage().pageId() > 0)
|
||||
.singleOrError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the fileSha and returns whether a file with a matching SHA exists or not
|
||||
*
|
||||
* @param fileSha SHA of the file to be checked
|
||||
*/
|
||||
public Single<Boolean> checkFileExistsUsingSha(String fileSha) {
|
||||
return mediaInterface.checkFileExistsUsingSha(fileSha)
|
||||
.map(mwQueryResponse -> mwQueryResponse
|
||||
.query().allImages().size() > 0)
|
||||
.singleOrError();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package fr.free.nrw.commons.media;
|
||||
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* Interface for interacting with Commons media related APIs
|
||||
*/
|
||||
public 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")
|
||||
Observable<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")
|
||||
Observable<MwQueryResponse> checkFileExistsUsingSha(@Query("aisha1") String aisha1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue