TV Shows complete

This commit is contained in:
Stuart Boston
2015-03-05 09:41:21 +00:00
parent b35c4beb45
commit 59f806b27e
3 changed files with 85 additions and 65 deletions
@@ -27,8 +27,11 @@ import com.omertron.themoviedbapi.model.keyword.Keyword;
import com.omertron.themoviedbapi.model.media.MediaCreditList;
import com.omertron.themoviedbapi.model.media.MediaState;
import com.omertron.themoviedbapi.model.movie.AlternativeTitle;
import com.omertron.themoviedbapi.model.movie.Translation;
import com.omertron.themoviedbapi.model.movie.Video;
import com.omertron.themoviedbapi.model.person.ContentRating;
import com.omertron.themoviedbapi.model.person.ExternalID;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import com.omertron.themoviedbapi.model.tv.TVInfo;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.tools.ApiUrl;
@@ -43,6 +46,8 @@ import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles;
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
import com.omertron.themoviedbapi.wrapper.WrapperImages;
import com.omertron.themoviedbapi.wrapper.WrapperTranslations;
import com.omertron.themoviedbapi.wrapper.WrapperVideos;
import java.io.IOException;
import java.net.URL;
import org.yamj.api.common.exception.ApiExceptionType;
@@ -338,12 +343,21 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVTranslations(int tvID) throws MovieDbException {
public TmdbResultsList<Translation> getTVTranslations(int tvID) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, tvID);
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.TRANSLATIONS).buildUrl(parameters);
return null;
String webpage = httpTools.getRequest(url);
try {
WrapperTranslations wrapper = MAPPER.readValue(webpage, WrapperTranslations.class);
TmdbResultsList<Translation> results = new TmdbResultsList<Translation>(wrapper.getTranslations());
results.copyWrapper(wrapper);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get translations", url, ex);
}
}
/**
@@ -355,13 +369,22 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVVideos(int tvID, String language) throws MovieDbException {
public TmdbResultsList<Video> getTVVideos(int tvID, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, tvID);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.VIDEOS).buildUrl(parameters);
return null;
String webpage = httpTools.getRequest(url);
try {
WrapperVideos wrapper = MAPPER.readValue(webpage, WrapperVideos.class);
TmdbResultsList<Video> results = new TmdbResultsList<Video>(wrapper.getVideos());
results.copyWrapper(wrapper);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get videos", url, ex);
}
}
/**
@@ -370,9 +393,15 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVLatest() throws MovieDbException {
public TVInfo getLatestTV() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.LATEST).buildUrl();
return null;
String webpage = httpTools.getRequest(url);
try {
return MAPPER.readValue(webpage, TVInfo.class);
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest movie", url, ex);
}
}
/**
@@ -386,13 +415,14 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVOnTheAir(Integer page, String language) throws MovieDbException {
public TmdbResultsList<TVBasic> getTVOnTheAir(Integer page, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.PAGE, page);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.ON_THE_AIR).buildUrl(parameters);
return null;
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "on the air");
return wrapper.getTmdbResultsList();
}
/**
@@ -406,14 +436,15 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVAiringToday(Integer page, String language, String timezone) throws MovieDbException {
public TmdbResultsList<TVBasic> getTVAiringToday(Integer page, String language, String timezone) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.PAGE, page);
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.TIMEZONE, timezone);
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.AIRING_TODAY).buildUrl(parameters);
return null;
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "airing today");
return wrapper.getTmdbResultsList();
}
/**
@@ -429,13 +460,14 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVTopRated(Integer page, String language) throws MovieDbException {
public TmdbResultsList<TVBasic> getTVTopRated(Integer page, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.PAGE, page);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.TOP_RATED).buildUrl(parameters);
return null;
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "top rated TV shows");
return wrapper.getTmdbResultsList();
}
/**
@@ -446,12 +478,13 @@ public class TmdbTV extends AbstractMethod {
* @return
* @throws com.omertron.themoviedbapi.MovieDbException
*/
public String getTVPopular(Integer page, String language) throws MovieDbException {
public TmdbResultsList<TVBasic> getTVPopular(Integer page, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.PAGE, page);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.POPULAR).buildUrl(parameters);
return null;
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "popular TV shows");
return wrapper.getTmdbResultsList();
}
}
@@ -69,7 +69,7 @@ public enum MethodSub {
TAGGED_IMAGES("tagged_images"),
TOKEN_NEW("token/new"),
TOKEN_VALIDATE("token/validate_with_login"),
TOP_RATED("top-rated"),
TOP_RATED("top_rated"),
TRANSLATIONS("translations"),
TV("tv"),
TV_CREDITS("tv_credits"),
@@ -34,8 +34,11 @@ import com.omertron.themoviedbapi.model.media.MediaCreditCast;
import com.omertron.themoviedbapi.model.media.MediaCreditList;
import com.omertron.themoviedbapi.model.media.MediaState;
import com.omertron.themoviedbapi.model.movie.AlternativeTitle;
import com.omertron.themoviedbapi.model.movie.Translation;
import com.omertron.themoviedbapi.model.movie.Video;
import com.omertron.themoviedbapi.model.person.ContentRating;
import com.omertron.themoviedbapi.model.person.ExternalID;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import com.omertron.themoviedbapi.model.tv.TVInfo;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.tools.MethodBase;
@@ -51,7 +54,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -83,7 +85,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVInfo() throws MovieDbException {
LOG.info("getTVInfo");
@@ -105,7 +107,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVAccountState() throws MovieDbException {
LOG.info("getTVAccountState");
@@ -121,7 +123,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVAlternativeTitles() throws MovieDbException {
LOG.info("getTVAlternativeTitles");
@@ -136,7 +138,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVChanges() throws MovieDbException {
LOG.info("getTVChanges");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -167,7 +169,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVContentRatings() throws MovieDbException {
LOG.info("getTVContentRatings");
@@ -184,7 +186,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVCredits() throws MovieDbException {
LOG.info("getTVCredits");
@@ -212,7 +214,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVExternalIDs() throws MovieDbException {
LOG.info("getTVExternalIDs");
@@ -229,7 +231,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVImages() throws MovieDbException {
LOG.info("getTVImages");
@@ -265,7 +267,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testGetTVKeywords() throws MovieDbException {
LOG.info("getTVKeywords");
@@ -282,7 +284,7 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
@Test
public void testPostTVRating() throws MovieDbException {
LOG.info("postTVRating");
@@ -317,15 +319,14 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVTranslations() throws MovieDbException {
LOG.info("getTVTranslations");
for (TestID test : TV_IDS) {
String result = instance.getTVTranslations(test.getTmdb());
TmdbResultsList<Translation> result = instance.getTVTranslations(test.getTmdb());
assertFalse("No translations", result.isEmpty());
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
@@ -333,33 +334,31 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVVideos() throws MovieDbException {
LOG.info("getTVVideos");
String language = LANGUAGE_DEFAULT;
for (TestID test : TV_IDS) {
String result = instance.getTVVideos(test.getTmdb(), language);
TmdbResultsList<Video> result = instance.getTVVideos(test.getTmdb(), language);
assertFalse("No videos", result.isEmpty());
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of getTVLatest method, of class TmdbTV.
* Test of getLatestTV method, of class TmdbTV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVLatest() throws MovieDbException {
LOG.info("getTVLatest");
for (TestID test : TV_IDS) {
String result = instance.getTVLatest();
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
TVInfo result = instance.getLatestTV();
assertNotNull("Null TV returned", result);
assertTrue("No ID", result.getId() > 0);
assertTrue("No title", StringUtils.isNotBlank(result.getName()));
}
/**
@@ -367,17 +366,14 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVOnTheAir() throws MovieDbException {
LOG.info("getTVOnTheAir");
Integer page = null;
String language = LANGUAGE_DEFAULT;
for (TestID test : TV_IDS) {
String result = instance.getTVOnTheAir(page, language);
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
TmdbResultsList<TVBasic> result = instance.getTVOnTheAir(page, language);
assertFalse("No results", result.isEmpty());
}
/**
@@ -385,18 +381,15 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVAiringToday() throws MovieDbException {
LOG.info("getTVAiringToday");
Integer page = null;
String language = LANGUAGE_DEFAULT;
String timezone = "";
for (TestID test : TV_IDS) {
String result = instance.getTVAiringToday(page, language, timezone);
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
TmdbResultsList<TVBasic> result = instance.getTVAiringToday(page, language, timezone);
assertFalse("No results", result.isEmpty());
}
/**
@@ -404,17 +397,14 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVTopRated() throws MovieDbException {
LOG.info("getTVTopRated");
Integer page = null;
String language = LANGUAGE_DEFAULT;
for (TestID test : TV_IDS) {
String result = instance.getTVTopRated(page, language);
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
TmdbResultsList<TVBasic> result = instance.getTVTopRated(page, language);
assertFalse("No results", result.isEmpty());
}
/**
@@ -422,17 +412,14 @@ public class TmdbTVTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
@Test
public void testGetTVPopular() throws MovieDbException {
LOG.info("getTVPopular");
Integer page = null;
String language = LANGUAGE_DEFAULT;
for (TestID test : TV_IDS) {
String result = instance.getTVPopular(page, language);
}
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
TmdbResultsList<TVBasic> result = instance.getTVPopular(page, language);
assertFalse("No results", result.isEmpty());
}
}