mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
Show wikidata edits done through the app (#2431)
* Show wikidata edits done through the app * Minor changes based on code review
This commit is contained in:
parent
aee8839eea
commit
73bb0c52c9
8 changed files with 138 additions and 18 deletions
|
|
@ -26,6 +26,7 @@ import fr.free.nrw.commons.nearby.model.NearbyResponse;
|
|||
import fr.free.nrw.commons.nearby.model.NearbyResultItem;
|
||||
import fr.free.nrw.commons.upload.FileUtils;
|
||||
import fr.free.nrw.commons.utils.DateUtils;
|
||||
import fr.free.nrw.commons.wikidata.model.GetWikidataEditCountResponse;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import okhttp3.HttpUrl;
|
||||
|
|
@ -63,7 +64,7 @@ public class OkHttpJsonApiClient {
|
|||
public Single<Integer> getUploadCount(String userName) {
|
||||
HttpUrl.Builder urlBuilder = wikiMediaToolforgeUrl.newBuilder();
|
||||
urlBuilder
|
||||
.addPathSegments("urbanecmbot/commonsmisc/uploadsbyuser.py")
|
||||
.addPathSegments("/uploadsbyuser.py")
|
||||
.addQueryParameter("user", userName);
|
||||
Request request = new Request.Builder()
|
||||
.url(urlBuilder.build())
|
||||
|
|
@ -72,12 +73,38 @@ public class OkHttpJsonApiClient {
|
|||
return Single.fromCallable(() -> {
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
if (response != null && response.isSuccessful()) {
|
||||
|
||||
return Integer.parseInt(response.body().string().trim());
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Single<Integer> getWikidataEdits(String userName) {
|
||||
HttpUrl.Builder urlBuilder = wikiMediaToolforgeUrl.newBuilder();
|
||||
urlBuilder
|
||||
.addPathSegments("/wikidataedits.py")
|
||||
.addQueryParameter("user", userName);
|
||||
Request request = new Request.Builder()
|
||||
.url(urlBuilder.build())
|
||||
.build();
|
||||
|
||||
return Single.fromCallable(() -> {
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
if (response != null &&
|
||||
response.isSuccessful() && response.body() != null) {
|
||||
String json = response.body().string();
|
||||
if (json == null) {
|
||||
return 0;
|
||||
}
|
||||
GetWikidataEditCountResponse countResponse = gson.fromJson(json, GetWikidataEditCountResponse.class);
|
||||
return countResponse.getWikidataEditCount();
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes userName as input, which is then used to fetch the feedback/achievements
|
||||
* statistics using OkHttp and JavaRx. This function return JSONObject
|
||||
|
|
@ -87,7 +114,7 @@ public class OkHttpJsonApiClient {
|
|||
*/
|
||||
public Single<FeedbackResponse> getAchievements(String userName) {
|
||||
final String fetchAchievementUrlTemplate =
|
||||
wikiMediaToolforgeUrl + "urbanecmbot/commonsmisc/feedback.py";
|
||||
wikiMediaToolforgeUrl + "/feedback.py";
|
||||
return Single.fromCallable(() -> {
|
||||
String url = String.format(
|
||||
Locale.ENGLISH,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue