use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class WikipediaApp method getUserIdForLanguage.
private void getUserIdForLanguage(@NonNull final String code) {
if (!AccountUtil.isLoggedIn() || TextUtils.isEmpty(AccountUtil.getUserName())) {
return;
}
final WikiSite wikiSite = WikiSite.forLanguageCode(code);
userInfoClient.request(wikiSite, AccountUtil.getUserName(), new UserExtendedInfoClient.Callback() {
@Override
public void success(@NonNull Call<MwQueryResponse> call, int id, @NonNull UserExtendedInfoClient.ListUserResponse user) {
if (AccountUtil.isLoggedIn()) {
AccountUtil.putUserIdForLanguage(code, id);
L.v("Found user ID " + id + " for " + code);
}
}
@Override
public void failure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable caught) {
L.e("Failed to get user ID for " + code, caught);
}
});
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class DescriptionClient method request.
@VisibleForTesting
Call<MwQueryResponse> request(@NonNull Service service, @NonNull final List<PageTitle> titles, @NonNull final Callback cb) {
Call<MwQueryResponse> call = service.request(TextUtils.join("|", titles));
call.enqueue(new retrofit2.Callback<MwQueryResponse>() {
@Override
public void onResponse(Call<MwQueryResponse> call, Response<MwQueryResponse> response) {
if (response.body().success()) {
// noinspection ConstantConditions
cb.success(call, response.body().query().pages());
} else if (response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(call, new MwException(response.body().getError()));
} else {
cb.failure(call, new IOException("An unknown error occurred."));
}
}
@Override
public void onFailure(Call<MwQueryResponse> call, Throwable t) {
cb.failure(call, t);
}
});
return call;
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class CreateAccountInfoClient method request.
@VisibleForTesting
Call<MwQueryResponse> request(@NonNull Service service, @NonNull final Callback cb) {
Call<MwQueryResponse> call = service.request();
call.enqueue(new retrofit2.Callback<MwQueryResponse>() {
@Override
public void onResponse(Call<MwQueryResponse> call, Response<MwQueryResponse> response) {
if (response.body().success()) {
// noinspection ConstantConditions
String token = response.body().query().createAccountToken();
// noinspection ConstantConditions
String captchaId = response.body().query().captchaId();
cb.success(call, new CreateAccountInfoResult(token, captchaId));
} else if (response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(call, new MwException(response.body().getError()));
} else {
cb.failure(call, new IOException("An unknown error occurred."));
}
}
@Override
public void onFailure(Call<MwQueryResponse> call, Throwable t) {
cb.failure(call, t);
}
});
return call;
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class GalleryItemClientTest method testRequestSuccessForImage.
@Test
public void testRequestSuccessForImage() throws Throwable {
enqueueFromFile("gallery_item_image.json");
Callback cb = mock(Callback.class);
Call<MwQueryResponse> call = request(cb, false);
server().takeRequest();
ArgumentCaptor<GalleryItem> captor = ArgumentCaptor.forClass(GalleryItem.class);
// noinspection unchecked
verify(cb).success(eq(call), captor.capture());
// noinspection unchecked
GalleryItem galleryItem = captor.getValue();
assertThat(galleryItem != null, is(true));
assertThat(String.valueOf(galleryItem.getHeight()), is("1489"));
assertThat(String.valueOf(galleryItem.getWidth()), is("2125"));
assertThat(galleryItem.getThumbUrl(), is("https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Kinkaku3402CBcropped.jpg/1280px-Kinkaku3402CBcropped.jpg"));
assertThat(galleryItem.getMimeType(), is("image/jpeg"));
assertThat(galleryItem.getUrl(), is("https://upload.wikimedia.org/wikipedia/commons/c/c9/Kinkaku3402CBcropped.jpg"));
}
use of org.wikipedia.dataclient.mwapi.MwQueryResponse in project apps-android-wikipedia by wikimedia.
the class ReadingListPageInfoClientTest method testRequestSuccess.
@Test
@SuppressWarnings("checkstyle:magicnumber")
public void testRequestSuccess() throws Throwable {
enqueueFromFile("reading_list_page_info.json");
ReadingListPageInfoClient.Callback cb = mock(ReadingListPageInfoClient.Callback.class);
Call<MwQueryResponse> call = request(cb);
server().takeRequest();
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
verify(cb).success(eq(call), captor.capture());
List<MwQueryPage> result = captor.getValue();
MwQueryPage biden = result.get(0);
MwQueryPage obama = result.get(1);
assertThat(biden.title(), is("Joe Biden"));
assertThat(biden.description(), is("47th Vice President of the United States"));
assertThat(biden.thumbUrl(), is("https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Official_portrait_of_Vice_President_Joe_Biden.jpg/255px-Official_portrait_of_Vice_President_Joe_Biden.jpg"));
assertThat(obama.title(), is("Barack Obama"));
assertThat(obama.description(), is("44th President of the United States of America"));
assertThat(obama.thumbUrl(), is("https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/256px-President_Barack_Obama.jpg"));
}
Aggregations