Search in sources :

Example 1 with RbPageSummary

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);
}
Also used : Callback(org.wikipedia.random.RandomSummaryClient.Callback) RbPageSummary(org.wikipedia.dataclient.restbase.page.RbPageSummary) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Example 2 with RbPageSummary

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);
}
Also used : RbPageSummary(org.wikipedia.dataclient.restbase.page.RbPageSummary) UtcDate(org.wikipedia.feed.model.UtcDate) WikipediaApp(org.wikipedia.WikipediaApp) PageTitle(org.wikipedia.page.PageTitle) PageLead(org.wikipedia.dataclient.page.PageLead) UriUtil.decodeURL(org.wikipedia.util.UriUtil.decodeURL) L(org.wikipedia.util.log.L) SuppressLint(android.annotation.SuppressLint)

Example 3 with RbPageSummary

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);
}
Also used : Callback(org.wikipedia.random.RandomSummaryClient.Callback) RbPageSummary(org.wikipedia.dataclient.restbase.page.RbPageSummary) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Example 4 with RbPageSummary

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);
}
Also used : Callback(org.wikipedia.random.RandomSummaryClient.Callback) RbPageSummary(org.wikipedia.dataclient.restbase.page.RbPageSummary) Test(org.junit.Test) MockWebServerTest(org.wikipedia.test.MockWebServerTest)

Aggregations

RbPageSummary (org.wikipedia.dataclient.restbase.page.RbPageSummary)4 Test (org.junit.Test)3 Callback (org.wikipedia.random.RandomSummaryClient.Callback)3 MockWebServerTest (org.wikipedia.test.MockWebServerTest)3 SuppressLint (android.annotation.SuppressLint)1 WikipediaApp (org.wikipedia.WikipediaApp)1 PageLead (org.wikipedia.dataclient.page.PageLead)1 UtcDate (org.wikipedia.feed.model.UtcDate)1 PageTitle (org.wikipedia.page.PageTitle)1 UriUtil.decodeURL (org.wikipedia.util.UriUtil.decodeURL)1 L (org.wikipedia.util.log.L)1