use of org.wikipedia.dataclient.restbase.page.RbPageSummary in project apps-android-wikipedia by wikimedia.
the class RandomSummaryClientTest method testRequestEligible.
@Test
public void testRequestEligible() throws Throwable {
enqueueFromFile("rb_page_summary_valid.json");
Callback cb = mock(Callback.class);
Call<RbPageSummary> call = request(cb);
server().takeRequest();
assertCallbackSuccess(call, cb);
}
use of org.wikipedia.dataclient.restbase.page.RbPageSummary in project apps-android-wikipedia by wikimedia.
the class WidgetProviderFeaturedPage method getFeaturedArticleInformation.
@SuppressLint("CheckResult")
private void getFeaturedArticleInformation(final Callback cb) {
WikipediaApp app = WikipediaApp.getInstance();
final PageTitle mainPageTitle = new PageTitle(MainPageNameData.valueFor(app.getAppOrSystemLanguageCode()), app.getWikiSite());
UtcDate date = DateUtil.getUtcRequestDateFor(0);
ServiceFactory.getRest(WikipediaApp.getInstance().getWikiSite()).getAggregatedFeed(date.year(), date.month(), date.date()).flatMap(response -> {
if (response.tfa() != null) {
return Observable.just(response.tfa());
} else {
// TODO: this logic can be removed if the feed API can return the featured article for all languages.
return getApiService(mainPageTitle).lead(mainPageTitle.getWikiSite(), null, null, null, mainPageTitle.getPrefixedText(), DimenUtil.calculateLeadImageWidth());
}
}).subscribeOn(Schedulers.io()).subscribe(response -> {
CharSequence widgetText = mainPageTitle.getText();
PageTitle pageTitle = mainPageTitle;
if (response instanceof retrofit2.Response) {
PageLead lead = (PageLead) ((retrofit2.Response) response).body();
L.d("Downloaded page " + mainPageTitle.getDisplayText());
widgetText = findFeaturedArticleTitle(lead.getLeadSectionContent());
} else if (response instanceof RbPageSummary) {
widgetText = StringUtil.fromHtml(((RbPageSummary) response).getDisplayTitle());
pageTitle = ((RbPageSummary) response).getPageTitle(app.getWikiSite());
}
cb.onFeaturedArticleReceived(pageTitle, widgetText);
}, L::e);
}
use of org.wikipedia.dataclient.restbase.page.RbPageSummary in project apps-android-wikipedia by wikimedia.
the class RandomSummaryClientTest method testRequestFailure.
@Test
public void testRequestFailure() throws Throwable {
enqueue404();
Callback cb = mock(Callback.class);
Call<RbPageSummary> call = request(cb);
server().takeRequest();
assertCallbackFailure(call, cb, IOException.class);
}
use of org.wikipedia.dataclient.restbase.page.RbPageSummary in project apps-android-wikipedia by wikimedia.
the class RandomSummaryClientTest method testRequestMalformed.
@Test
public void testRequestMalformed() throws Throwable {
enqueueFromFile("rb_page_summary_malformed.json");
Callback cb = mock(Callback.class);
Call<RbPageSummary> call = request(cb);
server().takeRequest();
assertCallbackFailure(call, cb, JsonParseException.class);
}
Aggregations