forked from commons-app/apps-android-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With media client APIs migrated to retrofit (commons-app#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
- Loading branch information
1 parent
828b5a3
commit 78141cb
Showing
17 changed files
with
252 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/java/fr/free/nrw/commons/media/MediaClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/fr/free/nrw/commons/media/MediaInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.