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;
}
Aggregations