/** Get the basic information for an account. You will need to have a valid session id. */
  public Account getAccount(SessionToken sessionToken) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT);

    apiUrl.addParam(PARAM_SESSION, sessionToken);

    return mapJsonResult(apiUrl, Account.class);
  }
Exemple #2
0
  /**
   * This method is used to retrieve all of the basic person information.
   *
   * <p>It will return the single highest rated profile image.
   *
   * @param personId
   */
  public PersonPeople getPersonInfo(int personId, String... appendToResponse) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId);

    apiUrl.appendToResponse(appendToResponse);

    return mapJsonResult(apiUrl, PersonPeople.class);
  }
Exemple #3
0
  /**
   * Get the list of popular people on The Movie Database.
   *
   * <p>This list refreshes every day.
   *
   * @param page
   * @return
   */
  public List<Person> getPersonPopular(Integer page) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, "popular");

    if (page != null && page > 0) {
      apiUrl.addParam(PARAM_PAGE, page);
    }

    return mapJsonResult(apiUrl, PersonResults.class).getResults();
  }
  /**
   * Try to validate TokenAuthorisation with username and password.
   *
   * @param token A TokenAuthorisation previously generated by getAuthorisationToken
   * @param user username
   * @param pwd password
   * @return The validated TokenAuthorisation. The same as input with getSuccess()==true
   */
  public TokenAuthorisation getLoginToken(TokenAuthorisation token, String user, String pwd) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_AUTH, "token/validate_with_login");

    apiUrl.addParam(PARAM_REQUEST_TOKEN, token.getRequestToken());
    apiUrl.addParam("username", user);
    apiUrl.addParam("password", pwd);

    return mapJsonResult(apiUrl, TokenAuthorisation.class);
  }
  public TvResultsPage getFavoriteSeries(
      SessionToken sessionToken, AccountID accountId, Integer page) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "favorite/tv");

    apiUrl.addParam(PARAM_SESSION, sessionToken);
    apiUrl.addPage(page);

    return mapJsonResult(apiUrl, TvResultsPage.class);
  }
  public MovieResultsPage getRatedMovies(
      SessionToken sessionToken, AccountID accountId, Integer page) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "rated_movies");

    apiUrl.addParam(PARAM_SESSION, sessionToken);
    apiUrl.addPage(page);

    return mapJsonResult(apiUrl, MovieResultsPage.class);
  }
  /** Get the lists that as user has created. */
  public MovieListResultsPage getLists(
      SessionToken sessionToken, AccountID accountId, String language, Integer page) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "lists");

    apiUrl.addParam(PARAM_SESSION, sessionToken);
    apiUrl.addLanguage(language);
    apiUrl.addPage(page);

    return mapJsonResult(apiUrl, MovieListResultsPage.class);
  }
  /**
   * This method is used to generate a session id for user based authentication.
   *
   * <p>A session id is required in order to use any of the write methods.
   *
   * @param token
   */
  public TokenSession getSessionToken(TokenAuthorisation token) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_AUTH, "session/new");

    if (!token.getSuccess()) {
      logger.warn("Authorisation token was not successful!");
      throw new MovieDbException("Authorisation token was not successful!");
    }

    apiUrl.addParam(PARAM_REQUEST_TOKEN, token.getRequestToken());

    return mapJsonResult(apiUrl, TokenSession.class);
  }
Exemple #9
0
  /**
   * Get the list of movies for a particular keyword by id.
   *
   * @param keywordId
   * @param language
   * @param page
   * @return List of movies with the keyword
   */
  public List<Keyword> getKeywordMovies(String keywordId, String language, Integer page) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_KEYWORD, keywordId, "movies");

    if (StringUtils.isNotBlank(language)) {
      apiUrl.addParam(PARAM_LANGUAGE, language);
    }

    if (page != null && page > 0) {
      apiUrl.addParam(PARAM_PAGE, page);
    }

    return mapJsonResult(apiUrl, KeywordResults.class).getResults();
  }
  /**
   * This method lets users rate a movie.
   *
   * <p>A valid session id is required.
   *
   * @param sessionToken
   * @param movieId
   * @param rating
   * @throws com.fasterxml.jackson.core.JsonProcessingException
   */
  public boolean postMovieRating(SessionToken sessionToken, Integer movieId, Integer rating) {
    ApiUrl apiUrl = new ApiUrl(TmdbMovies.TMDB_METHOD_MOVIE, movieId, "rating");

    apiUrl.addParam(PARAM_SESSION, sessionToken);

    if (rating < 0 || rating > 10) {
      throw new MovieDbException("rating out of range");
    }

    String jsonBody = Utils.convertToJson(jsonMapper, Collections.singletonMap("value", rating));

    return mapJsonResult(apiUrl, ResponseStatus.class, jsonBody).getStatusCode() == 12;
  }
  private ResponseStatus modifyWatchList(
      SessionToken sessionToken,
      AccountID accountId,
      Integer movieId,
      MediaType mediaType,
      boolean isWatched) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "watchlist");

    apiUrl.addParam(PARAM_SESSION, sessionToken);

    HashMap<String, Object> body = new HashMap<String, Object>();

    body.put("media_type", mediaType.toString());
    body.put("media_id", movieId);
    body.put("watchlist", isWatched);

    String jsonBody = Utils.convertToJson(jsonMapper, body);

    return mapJsonResult(apiUrl, ResponseStatus.class, jsonBody);
  }
  public MovieResultsPage getFavoriteMovies(SessionToken sessionToken, AccountID accountId) {
    ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "favorite/movies");
    apiUrl.addParam(PARAM_SESSION, sessionToken);

    return mapJsonResult(apiUrl, MovieResultsPage.class);
  }