Search in sources :

Example 1 with SeriesResultsResponse

use of com.uwetrottmann.thetvdb.entities.SeriesResultsResponse in project SeriesGuide by UweTrottmann.

the class TvdbTools method searchSeries.

@Nullable
public List<SearchResult> searchSeries(@NonNull String query, @Nullable final String language) throws TvdbException {
    retrofit2.Response<SeriesResultsResponse> response;
    try {
        response = tvdbSearch.get().series(query, null, null, language).execute();
    } catch (IOException e) {
        throw new TvdbException("searchSeries: " + e.getMessage(), e);
    }
    if (response.code() == 404) {
        // API returns 404 if there are no search results
        return null;
    }
    ensureSuccessfulResponse(response.raw(), "searchSeries: ");
    List<Series> tvdbResults = response.body().data;
    if (tvdbResults == null || tvdbResults.size() == 0) {
        // no results from tvdb
        return null;
    }
    // parse into our data format
    List<SearchResult> results = new ArrayList<>(tvdbResults.size());
    for (Series tvdbResult : tvdbResults) {
        SearchResult result = new SearchResult();
        result.tvdbid = tvdbResult.id;
        result.title = tvdbResult.seriesName;
        result.overview = tvdbResult.overview;
        result.language = language;
        results.add(result);
    }
    return results;
}
Also used : TheTvdbSeries(com.uwetrottmann.thetvdb.services.TheTvdbSeries) Series(com.uwetrottmann.thetvdb.entities.Series) SeriesResultsResponse(com.uwetrottmann.thetvdb.entities.SeriesResultsResponse) ArrayList(java.util.ArrayList) SearchResult(com.battlelancer.seriesguide.items.SearchResult) IOException(java.io.IOException) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)1 SearchResult (com.battlelancer.seriesguide.items.SearchResult)1 Series (com.uwetrottmann.thetvdb.entities.Series)1 SeriesResultsResponse (com.uwetrottmann.thetvdb.entities.SeriesResultsResponse)1 TheTvdbSeries (com.uwetrottmann.thetvdb.services.TheTvdbSeries)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1