use of org.wikipedia.dataclient.mwapi.MwException in project apps-android-wikipedia by wikimedia.
the class EditPreviewClient method request.
@VisibleForTesting
Call<EditPreview> request(@NonNull Service service, @NonNull PageTitle title, @NonNull String wikitext, @NonNull final Callback cb) {
Call<EditPreview> call = service.previewEdit(title.getPrefixedText(), wikitext);
call.enqueue(new retrofit2.Callback<EditPreview>() {
@Override
public void onResponse(Call<EditPreview> call, Response<EditPreview> response) {
if (response.body().success() && response.body().hasPreviewResult()) {
cb.success(call, response.body().result());
} else if (response.body().hasError()) {
cb.failure(call, new MwException(response.body().getError()));
} else {
cb.failure(call, new IOException("An unknown error occurred."));
}
}
@Override
public void onFailure(Call<EditPreview> call, Throwable t) {
cb.failure(call, t);
}
});
return call;
}
use of org.wikipedia.dataclient.mwapi.MwException in project apps-android-wikipedia by wikimedia.
the class WikitextClient method request.
@VisibleForTesting
Call<MwQueryResponse> request(@NonNull Service service, @NonNull final PageTitle title, final int sectionID, @NonNull final Callback cb) {
Call<MwQueryResponse> call = service.request(title.getPrefixedText(), sectionID);
call.enqueue(new retrofit2.Callback<MwQueryResponse>() {
@Override
public void onResponse(@NonNull Call<MwQueryResponse> call, @NonNull Response<MwQueryResponse> response) {
// noinspection ConstantConditions
if (response.body() != null && response.body().success() && response.body().query() != null && response.body().query().firstPage() != null && getRevision(response.body().query()) != null) {
// noinspection ConstantConditions
MwQueryPage.Revision rev = getRevision(response.body().query());
cb.success(call, response.body().query().firstPage().title(), rev.content(), rev.timeStamp());
} else if (response.body() != null && response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(call, new MwException(response.body().getError()));
} else {
Throwable t = new JsonParseException("Error parsing wikitext from query response");
cb.failure(call, t);
}
}
@Override
public void onFailure(@NonNull Call<MwQueryResponse> call, @NonNull Throwable t) {
cb.failure(call, t);
}
});
return call;
}
use of org.wikipedia.dataclient.mwapi.MwException 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.MwException in project apps-android-wikipedia by wikimedia.
the class CaptchaClient method request.
@VisibleForTesting
Call<Captcha> request(@NonNull Service service, @NonNull final Callback cb) {
Call<Captcha> call = service.refreshCaptcha();
call.enqueue(new retrofit2.Callback<Captcha>() {
@Override
public void onResponse(Call<Captcha> call, Response<Captcha> response) {
if (response.body().success()) {
cb.success(call, new CaptchaResult(response.body().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<Captcha> call, Throwable t) {
cb.failure(call, t);
}
});
return call;
}
use of org.wikipedia.dataclient.mwapi.MwException 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;
}
Aggregations