Add Job List
This commit is contained in:
@@ -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<Person> getPersonPopular() throws MovieDbException {
|
||||
return getPersonPopular(0);
|
||||
}
|
||||
|
||||
public List<Person> 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<Person> 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");
|
||||
}
|
||||
//</editor-fold>
|
||||
//
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Jobs">
|
||||
public List<JobDepartment> 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);
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
}
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<String> jobs;
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Getters">
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public List<String> getJobs() {
|
||||
return jobs;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Setters">
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public void setJobs(List<String> jobs) {
|
||||
this.jobs = jobs;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<JobDepartment> jobs;
|
||||
|
||||
public List<JobDepartment> getJobs() {
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public void setJobs(List<JobDepartment> 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());
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user