use of com.uwetrottmann.seriesguide.backend.movies.Movies in project SeriesGuide by UweTrottmann.
the class BaseMovieActionTask method doBackgroundAction.
@Override
protected Integer doBackgroundAction(Void... params) {
// send to hexagon
if (isSendingToHexagon()) {
Movie movie = new Movie();
movie.setTmdbId(movieTmdbId);
setHexagonMovieProperties(movie);
List<Movie> movies = new ArrayList<>();
movies.add(movie);
MovieList movieList = new MovieList();
movieList.setMovies(movies);
try {
Movies moviesService = getContext().getHexagonTools().getMoviesService();
if (moviesService == null) {
return ERROR_HEXAGON_API;
}
moviesService.save(movieList).execute();
} catch (IOException e) {
HexagonTools.trackFailedRequest(getContext(), "save movie", e);
return ERROR_HEXAGON_API;
}
}
// send to trakt
if (isSendingToTrakt()) {
if (!TraktCredentials.get(getContext()).hasCredentials()) {
return ERROR_TRAKT_AUTH;
}
SyncItems items = new SyncItems().movies(new SyncMovie().id(MovieIds.tmdb(movieTmdbId)));
try {
Response<SyncResponse> response = doTraktAction(traktSync.get(), items).execute();
if (response.isSuccessful()) {
if (isMovieNotFound(response.body())) {
return ERROR_TRAKT_API_NOT_FOUND;
}
} else {
if (SgTrakt.isUnauthorized(getContext(), response)) {
return ERROR_TRAKT_AUTH;
}
SgTrakt.trackFailedRequest(getContext(), getTraktAction(), response);
return ERROR_TRAKT_API;
}
} catch (IOException e) {
SgTrakt.trackFailedRequest(getContext(), getTraktAction(), e);
return ERROR_TRAKT_API;
}
}
// update local state
if (!doDatabaseUpdate(getContext(), movieTmdbId)) {
return ERROR_DATABASE;
}
return SUCCESS;
}
use of com.uwetrottmann.seriesguide.backend.movies.Movies in project SeriesGuide by UweTrottmann.
the class HexagonTools method getMoviesService.
/**
* Returns the instance for this hexagon service or null if not signed in.
*/
@Nullable
public synchronized Movies getMoviesService() {
GoogleAccountCredential credential = getAccountCredential(true);
if (credential.getSelectedAccount() == null) {
return null;
}
if (moviesService == null) {
Movies.Builder builder = new Movies.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential);
moviesService = CloudEndpointUtils.updateBuilder(app, builder).build();
}
return moviesService;
}
Aggregations