From 955ef0369e4c7bea5ea8836ee5863ba8aea52612 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 15 May 2013 14:09:57 +0100 Subject: [PATCH] Add Job List --- .../omertron/themoviedbapi/TheMovieDbApi.java | 40 ++++++++++- .../themoviedbapi/model/JobDepartment.java | 72 +++++++++++++++++++ .../themoviedbapi/wrapper/WrapperJobList.java | 63 ++++++++++++++++ .../themoviedbapi/TheMovieDbApiTest.java | 10 +++ 4 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/JobDepartment.java create mode 100644 src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index ccd28cb91..5b5f375f3 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -56,6 +56,7 @@ public class TheMovieDbApi { private static final String BASE_SEARCH = "search/"; private static final String BASE_LIST = "list/"; private static final String BASE_KEYWORD = "keyword/"; + private static final String BASE_JOB = "job/"; // Jackson JSON configuration private static ObjectMapper mapper = new ObjectMapper(); @@ -1074,14 +1075,31 @@ public class TheMovieDbApi { throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); } + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @return + * @throws MovieDbException + */ public List getPersonPopular() throws MovieDbException { return getPersonPopular(0); } - public List getPersonPopular(int page) throws MovieDbException{ + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @param page + * @return + * @throws MovieDbException + */ + public List getPersonPopular(int page) throws MovieDbException { ApiUrl apiUrl = new ApiUrl(apiKey, BASE_PERSON, "/popular"); - if(page>0) { + if (page > 0) { apiUrl.addArgument(PARAM_PAGE, page); } @@ -1549,4 +1567,22 @@ public class TheMovieDbApi { throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); } // + // + + // + public List getJobs() throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(apiKey, BASE_JOB, "/list"); + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperJobList wrapper = mapper.readValue(webpage, WrapperJobList.class); + return wrapper.getJobs(); + } catch (IOException ex) { + LOG.warn("Failed to get job list: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + // } diff --git a/src/main/java/com/omertron/themoviedbapi/model/JobDepartment.java b/src/main/java/com/omertron/themoviedbapi/model/JobDepartment.java new file mode 100644 index 000000000..94f6d52c0 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/JobDepartment.java @@ -0,0 +1,72 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JobDepartment { + + private static final long serialVersionUID = 1L; + // Logger + private static final Logger LOG = LoggerFactory.getLogger(MovieChanges.class); + // Properties + @JsonProperty("department") + private String department; + @JsonProperty("job_list") + private List jobs; + + // + public String getDepartment() { + return department; + } + + public List getJobs() { + return jobs; + } + // + + // + public void setDepartment(String department) { + this.department = department; + } + + public void setJobs(List jobs) { + this.jobs = jobs; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java new file mode 100644 index 000000000..98fac98e2 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java @@ -0,0 +1,63 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.AlternativeTitle; +import com.omertron.themoviedbapi.model.JobDepartment; +import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperJobList { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(WrapperJobList.class); + // Properties + @JsonProperty("jobs") + private List jobs; + + public List getJobs() { + return jobs; + } + + public void setJobs(List jobs) { + this.jobs = jobs; + } + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + LOG.trace(sb.toString()); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index 1d7b232ff..8149cee42 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -750,4 +750,14 @@ public class TheMovieDbApiTest { // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } + + /** + * Test of getJobs method, of class TheMovieDbApi. + */ + @Test + public void testGetJobs() throws Exception { + LOG.info("getJobs"); + List result = tmdb.getJobs(); + assertFalse("No jobs found", result.isEmpty()); + } }