Timezones

This commit is contained in:
Stuart Boston
2015-02-28 11:49:13 +00:00
parent bc333a4cb6
commit bbc85c09c4
9 changed files with 92 additions and 23 deletions
@@ -47,10 +47,10 @@ import com.omertron.themoviedbapi.model.change.ChangedMedia;
import com.omertron.themoviedbapi.model2.collection.Collection;
import com.omertron.themoviedbapi.model2.collection.CollectionInfo;
import com.omertron.themoviedbapi.model2.company.Company;
import com.omertron.themoviedbapi.model2.Configuration;
import com.omertron.themoviedbapi.model2.config.Configuration;
import com.omertron.themoviedbapi.model2.discover.Discover;
import com.omertron.themoviedbapi.model.Genre;
import com.omertron.themoviedbapi.model2.JobDepartment;
import com.omertron.themoviedbapi.model2.config.JobDepartment;
import com.omertron.themoviedbapi.model.keyword.Keyword;
import com.omertron.themoviedbapi.model.keyword.KeywordMovie;
import com.omertron.themoviedbapi.model.MovieDb;
@@ -79,6 +79,7 @@ import com.omertron.themoviedbapi.tools.HttpTools;
import com.omertron.themoviedbapi.tools.MethodBase;
import java.net.URL;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.HttpClient;
import org.yamj.api.common.http.SimpleHttpClientBuilder;
@@ -653,8 +654,17 @@ public class TheMovieDbApi {
public TmdbResultsList<JobDepartment> getJobs() throws MovieDbException {
return tmdbConfiguration.getJobs();
}
//</editor-fold>
/**
* Get the list of supported timezones for the API methods that support them.
*
* @return @throws MovieDbException
*/
public Map<String, List<String>> getTimezones() throws MovieDbException {
return tmdbConfiguration.getTimezones();
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Credits">
/**
* Get the detailed information about a particular credit record.
@@ -875,7 +885,6 @@ public class TheMovieDbApi {
public StatusCode removeItemFromList(String sessionId, String listId, Integer mediaId) throws MovieDbException {
return tmdbList.removeItem(sessionId, listId, mediaId);
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Movies">
@@ -1223,15 +1232,11 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Review">
/**
*
* @param movieId
* @param language
* @param page
* @param appendToResponse
* @return
* @throws MovieDbException
* @param reviewId
* @return @throws MovieDbException
*/
public TmdbResultsList<Review> getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException {
return tmdbReviews.getReviews(movieId, language, page, appendToResponse);
public Review getReviews(String reviewId) throws MovieDbException {
return tmdbReviews.getReview(reviewId);
}
//</editor-fold>
@@ -19,10 +19,11 @@
*/
package com.omertron.themoviedbapi.methods;
import com.fasterxml.jackson.core.type.TypeReference;
import com.omertron.themoviedbapi.MovieDbException;
import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER;
import com.omertron.themoviedbapi.model2.Configuration;
import com.omertron.themoviedbapi.model2.JobDepartment;
import com.omertron.themoviedbapi.model2.config.Configuration;
import com.omertron.themoviedbapi.model2.config.JobDepartment;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.tools.ApiUrl;
import com.omertron.themoviedbapi.tools.HttpTools;
@@ -32,6 +33,9 @@ import com.omertron.themoviedbapi.wrapper.WrapperConfig;
import com.omertron.themoviedbapi.wrapper.WrapperJobList;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.yamj.api.common.exception.ApiExceptionType;
/**
@@ -99,4 +103,27 @@ public class TmdbConfiguration extends AbstractMethod {
}
}
public Map<String, List<String>> getTimezones() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.TIMEZONES).setSubMethod(MethodSub.LIST).buildUrl();
String webpage = httpTools.getRequest(url);
List<Map<String, List<String>>> tzList;
try {
tzList = MAPPER.readValue(webpage, new TypeReference<List<Map<String, List<String>>>>() {
});
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get timezone list", url, ex);
}
Map<String, List<String>> timezones = new HashMap<String, List<String>>();
for (Map<String, List<String>> tzMap : tzList) {
for (Map.Entry<String, List<String>> x : tzMap.entrySet()) {
timezones.put(x.getKey(), x.getValue());
}
}
return timezones;
}
}
@@ -51,7 +51,7 @@ Genres (Done)
Guest Sessions (Partial - in Account)
/guest_session/{guest_session_id}/rated_movies Get a list of rated movies for a specific guest session id.
Jobs (Done)
Jobs (Done - part of configuration)
/job/list Get a list of valid jobs.
Keyword (Done)
@@ -115,7 +115,7 @@ Search
/search/person Search for people by name.
/search/tv Search for TV shows by title.
Timezones
Timezones (Done - part of configuration)
/timezones/list Get the list of supported timezones for the API methods that support them.
TV
@@ -17,11 +17,12 @@
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.model2;
package com.omertron.themoviedbapi.model2.config;
import com.omertron.themoviedbapi.model2.AbstractJsonMapping;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.model2.AbstractJsonMapping;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
@@ -17,10 +17,11 @@
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.model2;
package com.omertron.themoviedbapi.model2.config;
import com.omertron.themoviedbapi.model2.AbstractJsonMapping;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model2.AbstractJsonMapping;
import java.util.List;
@@ -43,6 +43,7 @@ public enum MethodBase {
PERSON("person"),
REVIEW("review"),
SEARCH("search"),
TIMEZONES("timezones"),
TV("tv");
private final String value;
@@ -20,7 +20,7 @@
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model2.Configuration;
import com.omertron.themoviedbapi.model2.config.Configuration;
import java.util.Collections;
import java.util.List;
@@ -20,7 +20,7 @@
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model2.JobDepartment;
import com.omertron.themoviedbapi.model2.config.JobDepartment;
import java.util.List;
/**
@@ -21,11 +21,16 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.model2.Configuration;
import com.omertron.themoviedbapi.model2.config.Configuration;
import com.omertron.themoviedbapi.model2.config.JobDepartment;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -65,7 +70,7 @@ public class TmdbConfigurationTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
// @Test
public void testGetConfig() throws MovieDbException {
LOG.info("getConfig");
Configuration result = instance.getConfig();
@@ -83,7 +88,7 @@ public class TmdbConfigurationTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testCreateImageUrl() throws MovieDbException {
LOG.info("createImageUrl");
Configuration config = instance.getConfig();
@@ -92,4 +97,33 @@ public class TmdbConfigurationTest extends AbstractTests {
assertTrue("Error compiling image URL", !result.isEmpty());
}
/**
* Test of getJobs method, of class TmdbConfiguration.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
public void testGetJobs() throws MovieDbException {
LOG.info("getJobs");
TmdbResultsList<JobDepartment> result = instance.getJobs();
assertNotNull("Null results", result);
assertFalse("Empty results", result.getResults().isEmpty());
assertTrue("No results", result.getResults().size() > 0);
}
/**
* Test of getTimezones method, of class TmdbConfiguration.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetTimezones() throws MovieDbException {
LOG.info("getTimezones");
Map<String, List<String>> result = instance.getTimezones();
assertNotNull("Null results", result);
assertFalse("Empty results", result.isEmpty());
assertTrue("No US TZ",result.containsKey("US"));
assertTrue("No GB TZ",result.containsKey("GB"));
}
}