Merge pull request #7 from fcojean/master

Implemented MovieChangesList
master
Stuart Boston 12 years ago
parent 1ac805bed3
commit 6448542fb4

@ -19,21 +19,6 @@
*/ */
package com.omertron.themoviedbapi; package com.omertron.themoviedbapi;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType;
import com.omertron.themoviedbapi.model.*;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
import com.omertron.themoviedbapi.tools.ApiUrl;
import com.omertron.themoviedbapi.tools.WebBrowser;
import com.omertron.themoviedbapi.wrapper.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.CommonHttpClient;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -42,8 +27,21 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.omertron.themoviedbapi.tools.ApiUrl.*; import static com.omertron.themoviedbapi.tools.ApiUrl.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.CommonHttpClient;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType;
import com.omertron.themoviedbapi.model.*;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
import com.omertron.themoviedbapi.tools.ApiUrl;
import com.omertron.themoviedbapi.tools.WebBrowser;
import com.omertron.themoviedbapi.wrapper.*;
/** /**
* The MovieDb API <p> This is for version 3 of the API as specified here: http://help.themoviedb.org/kb/api/about-3 * The MovieDb API <p> This is for version 3 of the API as specified here: http://help.themoviedb.org/kb/api/about-3
@ -1905,8 +1903,45 @@ public class TheMovieDbApi {
//</editor-fold> //</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Changes Functions"> //<editor-fold defaultstate="collapsed" desc="Changes Functions">
public void getMovieChangesList(int page, String startDate, String endDate) throws MovieDbException { /**
throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); * Get a list of movie ids that have been edited. By default we show the last 24 hours and only 100 items per page. The maximum
* number of days that can be returned in a single request is 14. You can then use the movie changes API to get the actual data
* that has been changed. Please note that the change log system to support this was changed on October 5, 2012 and will only
* show movies that have been edited since.
*
* @param page
* @param startDate the start date of the changes, optional
* @param endDate the end date of the changes, optional
* @return List of changed movie
* @throws MovieDbException
*/
public TmdbResultsList<ChangedMovie> getMovieChangesList(int page, String startDate, String endDate) throws MovieDbException {
ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/changes");
if (page > 0) {
apiUrl.addArgument(PARAM_PAGE, page);
}
if (StringUtils.isNotBlank(startDate)) {
apiUrl.addArgument(PARAM_START_DATE, startDate);
}
if (StringUtils.isNotBlank(endDate)) {
apiUrl.addArgument(PARAM_END_DATE, endDate);
}
URL url = apiUrl.buildUrl();
String webpage = requestWebPage(url);
try {
WrapperMovieChanges wrapper = mapper.readValue(webpage, WrapperMovieChanges.class);
TmdbResultsList<ChangedMovie> results = new TmdbResultsList<ChangedMovie>(wrapper.getResults());
results.copyWrapper(wrapper);
return results;
} catch (IOException ex) {
LOG.warn("Failed to get movie changes: {}", ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
}
} }
public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException { public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException {

@ -0,0 +1,55 @@
/*
* Copyright (c) 2004-2013 Stuart Boston
*
* This file is part of TheMovieDB API.
*
* TheMovieDB API is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* TheMovieDB API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.model;
import com.fasterxml.jackson.annotation.JsonProperty;
public class ChangedMovie extends AbstractJsonMapping {
private static final long serialVersionUID = 1L;
/*
* Properties
*/
@JsonProperty("id")
private String id;
@JsonProperty("adult")
private boolean adult;
// <editor-fold defaultstate="collapsed" desc="Getter methods">
public String getId() {
return id;
}
public boolean isAdult() {
return adult;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Setter methods">
public void setId(String id) {
this.id = id;
}
public void setAdult(boolean adult) {
this.adult = adult;
}
// </editor-fold>
}

@ -0,0 +1,39 @@
/*
* Copyright (c) 2004-2013 Stuart Boston
*
* This file is part of TheMovieDB API.
*
* TheMovieDB API is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* TheMovieDB API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.wrapper;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model.ChangedMovie;
public class WrapperMovieChanges extends AbstractWrapperAll {
@JsonProperty("results")
private List<ChangedMovie> results;
public List<ChangedMovie> getResults() {
return results;
}
public void setResults(List<ChangedMovie> results) {
this.results = results;
}
}

@ -19,19 +19,55 @@
*/ */
package com.omertron.themoviedbapi; package com.omertron.themoviedbapi;
import com.omertron.themoviedbapi.model.*; import static org.junit.Assert.assertEquals;
import com.omertron.themoviedbapi.results.TmdbResultsList; import static org.junit.Assert.assertFalse;
import com.omertron.themoviedbapi.results.TmdbResultsMap; import static org.junit.Assert.assertNotNull;
import org.apache.commons.lang3.StringUtils; import static org.junit.Assert.assertTrue;
import org.junit.*; import static org.junit.Assert.fail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import static org.junit.Assert.*; import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.omertron.themoviedbapi.model.Account;
import com.omertron.themoviedbapi.model.AlternativeTitle;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.ChangedItem;
import com.omertron.themoviedbapi.model.ChangedMovie;
import com.omertron.themoviedbapi.model.Collection;
import com.omertron.themoviedbapi.model.CollectionInfo;
import com.omertron.themoviedbapi.model.Company;
import com.omertron.themoviedbapi.model.Discover;
import com.omertron.themoviedbapi.model.Genre;
import com.omertron.themoviedbapi.model.JobDepartment;
import com.omertron.themoviedbapi.model.Keyword;
import com.omertron.themoviedbapi.model.KeywordMovie;
import com.omertron.themoviedbapi.model.MovieDb;
import com.omertron.themoviedbapi.model.MovieDbList;
import com.omertron.themoviedbapi.model.MovieList;
import com.omertron.themoviedbapi.model.Person;
import com.omertron.themoviedbapi.model.PersonCredit;
import com.omertron.themoviedbapi.model.ReleaseInfo;
import com.omertron.themoviedbapi.model.Reviews;
import com.omertron.themoviedbapi.model.StatusCode;
import com.omertron.themoviedbapi.model.TmdbConfiguration;
import com.omertron.themoviedbapi.model.TokenAuthorisation;
import com.omertron.themoviedbapi.model.TokenSession;
import com.omertron.themoviedbapi.model.Trailer;
import com.omertron.themoviedbapi.model.Translation;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
/** /**
* Test cases for TheMovieDbApi API * Test cases for TheMovieDbApi API
@ -801,15 +837,14 @@ public class TheMovieDbApiTest {
/** /**
* Test of getMovieChangesList method, of class TheMovieDbApi. * Test of getMovieChangesList method, of class TheMovieDbApi.
*/ */
@Ignore("Not ready yet") @Test
public void testGetMovieChangesList() throws Exception { public void testGetMovieChangesList() throws Exception {
LOG.info("getMovieChangesList"); LOG.info("getMovieChangesList");
int page = 0; int page = 0;
String startDate = ""; String startDate = "";
String endDate = ""; String endDate = "";
tmdb.getMovieChangesList(page, startDate, endDate); TmdbResultsList<ChangedMovie> result = tmdb.getMovieChangesList(page, startDate, endDate);
// TODO review the generated test code and remove the default call to fail. assertFalse("No movie changes.", result.getResults().isEmpty());
fail("The test case is a prototype.");
} }
/** /**

Loading…
Cancel
Save