use of org.wikipedia.dataclient.mwapi.MwException in project apps-android-wikipedia by wikimedia.
the class ReadingListPageInfoClient method request.
@VisibleForTesting
public Call<MwQueryResponse> request(@NonNull Service service, @NonNull 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(@NonNull Call<MwQueryResponse> call, @NonNull Response<MwQueryResponse> response) {
if (response.isSuccessful()) {
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."));
}
} else {
cb.failure(call, RetrofitException.httpError(response));
}
}
@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 LoginClient method request.
public void request(@NonNull final WikiSite wiki, @NonNull final String userName, @NonNull final String password, @NonNull final LoginCallback cb) {
cancel();
tokenCall = cachedService.service(wiki).requestLoginToken();
tokenCall.enqueue(new Callback<MwQueryResponse>() {
@Override
public void onResponse(Call<MwQueryResponse> call, Response<MwQueryResponse> response) {
if (response.body().success()) {
// noinspection ConstantConditions
login(wiki, userName, password, null, response.body().query().loginToken(), cb);
} else if (response.body().getError() != null) {
// noinspection ConstantConditions
cb.error(new MwException(response.body().getError()));
} else {
cb.error(new IOException("Unexpected error trying to retrieve login token. " + response.body().toString()));
}
}
@Override
public void onFailure(Call<MwQueryResponse> call, Throwable caught) {
cb.error(caught);
}
});
}
use of org.wikipedia.dataclient.mwapi.MwException in project apps-android-wikipedia by wikimedia.
the class NearbyClient method request.
@VisibleForTesting
Call<MwQueryResponse> request(@NonNull final WikiSite wiki, @NonNull Service service, double latitude, double longitude, double radius, @NonNull final Callback cb) {
String latLng = String.format(Locale.ROOT, "%f|%f", latitude, longitude);
radius = Math.min(MAX_RADIUS, radius);
Call<MwQueryResponse> call = service.request(latLng, radius, Constants.PREFERRED_THUMB_SIZE);
call.enqueue(new retrofit2.Callback<MwQueryResponse>() {
@Override
public void onResponse(Call<MwQueryResponse> call, Response<MwQueryResponse> response) {
// API explicitly tells us we have an error.
if (response.body().success()) {
// noinspection ConstantConditions
cb.success(call, new NearbyResult(wiki, response.body().query().nearbyPages()));
} else if (response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(call, new MwException(response.body().getError()));
} else {
cb.success(call, new NearbyResult(wiki, new ArrayList<>()));
}
}
@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 CreateAccountClient method request.
@SuppressWarnings("checkstyle:parameternumber")
@VisibleForTesting
Call<CreateAccountResponse> request(@NonNull Service service, @NonNull String username, @NonNull String password, @NonNull String retype, @NonNull String token, @Nullable String email, @Nullable String captchaId, @Nullable String captchaWord, @NonNull final Callback cb) {
Call<CreateAccountResponse> call = service.request(username, password, retype, token, Constants.WIKIPEDIA_URL, email, captchaId, captchaWord);
call.enqueue(new retrofit2.Callback<CreateAccountResponse>() {
@Override
public void onResponse(Call<CreateAccountResponse> call, Response<CreateAccountResponse> response) {
if (response.body().hasResult()) {
CreateAccountResponse result = response.body();
if ("PASS".equals(result.status())) {
cb.success(call, new CreateAccountSuccessResult(result.user()));
} else {
cb.failure(call, new CreateAccountException(result.message()));
}
} 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<CreateAccountResponse> 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 CsrfTokenClient method requestToken.
@VisibleForTesting
@NonNull
Call<MwQueryResponse> requestToken(@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
cb.success(response.body().query().csrfToken());
} else if (response.body().hasError()) {
// noinspection ConstantConditions
cb.failure(new MwException(response.body().getError()));
} else {
cb.failure(new IOException("An unknown error occurred."));
}
}
@Override
public void onFailure(Call<MwQueryResponse> call, Throwable t) {
cb.failure(t);
}
});
return call;
}
Aggregations