Search in sources :

Example 1 with SyncErrors

use of com.uwetrottmann.trakt5.entities.SyncErrors in project SeriesGuide by UweTrottmann.

the class BaseRateItemTask method doBackgroundAction.

@Override
protected Integer doBackgroundAction(Void... params) {
    if (isSendingToTrakt()) {
        if (!TraktCredentials.get(getContext()).hasCredentials()) {
            return ERROR_TRAKT_AUTH;
        }
        SyncItems ratedItems = buildTraktSyncItems();
        if (ratedItems == null) {
            return ERROR_TRAKT_API;
        }
        SyncErrors notFound;
        try {
            Sync traktSync = SgApp.getServicesComponent(getContext()).traktSync();
            Response<SyncResponse> response = traktSync.addRatings(ratedItems).execute();
            if (response.isSuccessful()) {
                notFound = response.body().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;
        }
        if (notFound != null) {
            if ((notFound.movies != null && notFound.movies.size() != 0) || (notFound.shows != null && notFound.shows.size() != 0) || (notFound.episodes != null && notFound.episodes.size() != 0)) {
                // movie, show or episode not found on trakt
                return ERROR_TRAKT_API_NOT_FOUND;
            }
        }
    }
    if (!doDatabaseUpdate()) {
        return ERROR_DATABASE;
    }
    return SUCCESS;
}
Also used : SyncItems(com.uwetrottmann.trakt5.entities.SyncItems) SyncResponse(com.uwetrottmann.trakt5.entities.SyncResponse) SyncErrors(com.uwetrottmann.trakt5.entities.SyncErrors) Sync(com.uwetrottmann.trakt5.services.Sync)

Aggregations

SyncErrors (com.uwetrottmann.trakt5.entities.SyncErrors)1 SyncItems (com.uwetrottmann.trakt5.entities.SyncItems)1 SyncResponse (com.uwetrottmann.trakt5.entities.SyncResponse)1 Sync (com.uwetrottmann.trakt5.services.Sync)1