use of com.uwetrottmann.trakt5.entities.SyncShow in project SeriesGuide by UweTrottmann.
the class TraktTools method uploadEpisodes.
/**
* Uploads all the given watched/collected episodes of the given show to trakt.
*
* @return Any of the {@link TraktTools} result codes.
*/
private int uploadEpisodes(int showTraktId, List<SyncSeason> syncSeasons, Flag flag) {
SyncShow syncShow = new SyncShow();
syncShow.id(ShowIds.trakt(showTraktId));
syncShow.seasons = syncSeasons;
// upload
SyncItems syncItems = new SyncItems().shows(syncShow);
try {
Response<SyncResponse> response;
if (flag == Flag.WATCHED) {
// uploading watched episodes
response = traktSync.get().addItemsToWatchedHistory(syncItems).execute();
} else {
// uploading collected episodes
response = traktSync.get().addItemsToCollection(syncItems).execute();
}
if (response.isSuccessful()) {
return SUCCESS;
} else {
if (SgTrakt.isUnauthorized(context, response)) {
return FAILED_CREDENTIALS;
}
SgTrakt.trackFailedRequest(context, "add episodes to " + flag.name, response);
}
} catch (IOException e) {
SgTrakt.trackFailedRequest(context, "add episodes to " + flag.name, e);
}
return FAILED_API;
}
use of com.uwetrottmann.trakt5.entities.SyncShow in project SeriesGuide by UweTrottmann.
the class BaseShowActionTask method doBackgroundAction.
@Override
protected Integer doBackgroundAction(Void... params) {
if (isSendingToTrakt()) {
if (!TraktCredentials.get(getContext()).hasCredentials()) {
return ERROR_TRAKT_AUTH;
}
SyncItems items = new SyncItems().shows(new SyncShow().id(ShowIds.tmdb(showTmdbId)));
try {
Sync traktSync = SgApp.getServicesComponent(getContext()).traktSync();
Response<SyncResponse> response = doTraktAction(traktSync, items).execute();
if (response.isSuccessful()) {
if (isShowNotFound(response.body())) {
return ERROR_TRAKT_API_NOT_FOUND;
}
} else {
if (SgTrakt.isUnauthorized(getContext(), response)) {
return ERROR_TRAKT_AUTH;
}
Errors.logAndReport(getTraktAction(), response);
return ERROR_TRAKT_API;
}
} catch (Exception e) {
Errors.logAndReport(getTraktAction(), e);
return ERROR_TRAKT_API;
}
}
return SUCCESS;
}
use of com.uwetrottmann.trakt5.entities.SyncShow in project SeriesGuide by UweTrottmann.
the class RateEpisodeTask method buildTraktSyncItems.
@Nullable
@Override
protected SyncItems buildTraktSyncItems() {
SgRoomDatabase database = SgRoomDatabase.getInstance(getContext());
SgEpisode2Numbers episode = database.sgEpisode2Helper().getEpisodeNumbers(episodeId);
if (episode == null)
return null;
int showTmdbId = database.sgShow2Helper().getShowTmdbId(episode.getShowId());
if (showTmdbId == 0)
return null;
return new SyncItems().shows(new SyncShow().id(ShowIds.tmdb(showTmdbId)).seasons(new SyncSeason().number(episode.getSeason()).episodes(new SyncEpisode().number(episode.getEpisodenumber()).rating(getRating()))));
}
Aggregations