Search in sources :

Example 1 with SyncShow

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;
}
Also used : SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SyncResponse(com.uwetrottmann.trakt5.entities.SyncResponse) SyncShow(com.uwetrottmann.trakt5.entities.SyncShow) IOException(java.io.IOException)

Example 2 with SyncShow

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;
}
Also used : SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SyncResponse(com.uwetrottmann.trakt5.entities.SyncResponse) SyncShow(com.uwetrottmann.trakt5.entities.SyncShow) Sync(com.uwetrottmann.trakt5.services.Sync)

Example 3 with SyncShow

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()))));
}
Also used : SyncEpisode(com.uwetrottmann.trakt5.entities.SyncEpisode) SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SgRoomDatabase(com.battlelancer.seriesguide.provider.SgRoomDatabase) SgEpisode2Numbers(com.battlelancer.seriesguide.provider.SgEpisode2Numbers) SyncShow(com.uwetrottmann.trakt5.entities.SyncShow) SyncSeason(com.uwetrottmann.trakt5.entities.SyncSeason) Nullable(androidx.annotation.Nullable)

Aggregations

SyncItems (com.uwetrottmann.trakt5.entities.SyncItems)3 SyncShow (com.uwetrottmann.trakt5.entities.SyncShow)3 SyncResponse (com.uwetrottmann.trakt5.entities.SyncResponse)2 Nullable (androidx.annotation.Nullable)1 SgEpisode2Numbers (com.battlelancer.seriesguide.provider.SgEpisode2Numbers)1 SgRoomDatabase (com.battlelancer.seriesguide.provider.SgRoomDatabase)1 SyncEpisode (com.uwetrottmann.trakt5.entities.SyncEpisode)1 SyncSeason (com.uwetrottmann.trakt5.entities.SyncSeason)1 Sync (com.uwetrottmann.trakt5.services.Sync)1 IOException (java.io.IOException)1