Removed reliance on MovieDb object from ApiBuilder
parent
7d9552a08c
commit
9f135c3ca7
File diff suppressed because it is too large
Load Diff
@ -1,354 +1,355 @@
|
||||
/*
|
||||
* 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.io.Serializable;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Movie Bean
|
||||
*
|
||||
* @author stuart.boston
|
||||
*/
|
||||
public class MovieDb implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MovieDb.class);
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
@JsonProperty("backdrop_path")
|
||||
private String backdropPath;
|
||||
@JsonProperty("id")
|
||||
private int id;
|
||||
@JsonProperty("original_title")
|
||||
private String originalTitle;
|
||||
@JsonProperty("popularity")
|
||||
private float popularity;
|
||||
@JsonProperty("poster_path")
|
||||
private String posterPath;
|
||||
@JsonProperty("release_date")
|
||||
private String releaseDate;
|
||||
@JsonProperty("title")
|
||||
private String title;
|
||||
@JsonProperty("adult")
|
||||
private boolean adult;
|
||||
@JsonProperty("belongs_to_collection")
|
||||
private Collection belongsToCollection;
|
||||
@JsonProperty("budget")
|
||||
private long budget;
|
||||
@JsonProperty("genres")
|
||||
private List<Genre> genres;
|
||||
@JsonProperty("homepage")
|
||||
private String homepage;
|
||||
@JsonProperty("imdb_id")
|
||||
private String imdbID;
|
||||
@JsonProperty("overview")
|
||||
private String overview;
|
||||
@JsonProperty("production_companies")
|
||||
private List<ProductionCompany> productionCompanies;
|
||||
@JsonProperty("production_countries")
|
||||
private List<ProductionCountry> productionCountries;
|
||||
@JsonProperty("revenue")
|
||||
private long revenue;
|
||||
@JsonProperty("runtime")
|
||||
private int runtime;
|
||||
@JsonProperty("spoken_languages")
|
||||
private List<Language> spokenLanguages;
|
||||
@JsonProperty("tagline")
|
||||
private String tagline;
|
||||
@JsonProperty("vote_average")
|
||||
private float voteAverage;
|
||||
@JsonProperty("vote_count")
|
||||
private int voteCount;
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Getter methods">
|
||||
public String getBackdropPath() {
|
||||
return backdropPath;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getOriginalTitle() {
|
||||
return originalTitle;
|
||||
}
|
||||
|
||||
public float getPopularity() {
|
||||
return popularity;
|
||||
}
|
||||
|
||||
public String getPosterPath() {
|
||||
return posterPath;
|
||||
}
|
||||
|
||||
public String getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
return adult;
|
||||
}
|
||||
|
||||
public Collection getBelongsToCollection() {
|
||||
return belongsToCollection;
|
||||
}
|
||||
|
||||
public long getBudget() {
|
||||
return budget;
|
||||
}
|
||||
|
||||
public List<Genre> getGenres() {
|
||||
return genres;
|
||||
}
|
||||
|
||||
public String getHomepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
public String getImdbID() {
|
||||
return imdbID;
|
||||
}
|
||||
|
||||
public String getOverview() {
|
||||
return overview;
|
||||
}
|
||||
|
||||
public List<ProductionCompany> getProductionCompanies() {
|
||||
return productionCompanies;
|
||||
}
|
||||
|
||||
public List<ProductionCountry> getProductionCountries() {
|
||||
return productionCountries;
|
||||
}
|
||||
|
||||
public long getRevenue() {
|
||||
return revenue;
|
||||
}
|
||||
|
||||
public int getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public List<Language> getSpokenLanguages() {
|
||||
return spokenLanguages;
|
||||
}
|
||||
|
||||
public String getTagline() {
|
||||
return tagline;
|
||||
}
|
||||
|
||||
public float getVoteAverage() {
|
||||
return voteAverage;
|
||||
}
|
||||
|
||||
public int getVoteCount() {
|
||||
return voteCount;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Setter methods">
|
||||
public void setBackdropPath(String backdropPath) {
|
||||
this.backdropPath = backdropPath;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setOriginalTitle(String originalTitle) {
|
||||
this.originalTitle = originalTitle;
|
||||
}
|
||||
|
||||
public void setPopularity(float popularity) {
|
||||
this.popularity = popularity;
|
||||
}
|
||||
|
||||
public void setPosterPath(String posterPath) {
|
||||
this.posterPath = posterPath;
|
||||
}
|
||||
|
||||
public void setReleaseDate(String releaseDate) {
|
||||
this.releaseDate = releaseDate;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setAdult(boolean adult) {
|
||||
this.adult = adult;
|
||||
}
|
||||
|
||||
public void setBelongsToCollection(Collection belongsToCollection) {
|
||||
this.belongsToCollection = belongsToCollection;
|
||||
}
|
||||
|
||||
public void setBudget(long budget) {
|
||||
this.budget = budget;
|
||||
}
|
||||
|
||||
public void setGenres(List<Genre> genres) {
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public void setHomepage(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
public void setImdbID(String imdbID) {
|
||||
this.imdbID = imdbID;
|
||||
}
|
||||
|
||||
public void setOverview(String overview) {
|
||||
this.overview = overview;
|
||||
}
|
||||
|
||||
public void setProductionCompanies(List<ProductionCompany> productionCompanies) {
|
||||
this.productionCompanies = productionCompanies;
|
||||
}
|
||||
|
||||
public void setProductionCountries(List<ProductionCountry> productionCountries) {
|
||||
this.productionCountries = productionCountries;
|
||||
}
|
||||
|
||||
public void setRevenue(long revenue) {
|
||||
this.revenue = revenue;
|
||||
}
|
||||
|
||||
public void setRuntime(int runtime) {
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
public void setSpokenLanguages(List<Language> spokenLanguages) {
|
||||
this.spokenLanguages = spokenLanguages;
|
||||
}
|
||||
|
||||
public void setTagline(String tagline) {
|
||||
this.tagline = tagline;
|
||||
}
|
||||
|
||||
public void setVoteAverage(float voteAverage) {
|
||||
this.voteAverage = voteAverage;
|
||||
}
|
||||
|
||||
public void setVoteCount(int voteCount) {
|
||||
this.voteCount = voteCount;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
// </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());
|
||||
}
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Equals and HashCode">
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final MovieDb other = (MovieDb) obj;
|
||||
if (this.id != other.id) {
|
||||
return false;
|
||||
}
|
||||
if ((this.imdbID == null) ? (other.imdbID != null) : !this.imdbID.equals(other.imdbID)) {
|
||||
return false;
|
||||
}
|
||||
if (this.runtime != other.runtime) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 89 * hash + this.id;
|
||||
hash = 89 * hash + (this.imdbID != null ? this.imdbID.hashCode() : 0);
|
||||
hash = 89 * hash + this.runtime;
|
||||
return hash;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("[MovieDB=");
|
||||
sb.append("[backdropPath=").append(backdropPath);
|
||||
sb.append("],[id=").append(id);
|
||||
sb.append("],[originalTitle=").append(originalTitle);
|
||||
sb.append("],[popularity=").append(popularity);
|
||||
sb.append("],[posterPath=").append(posterPath);
|
||||
sb.append("],[releaseDate=").append(releaseDate);
|
||||
sb.append("],[title=").append(title);
|
||||
sb.append("],[adult=").append(adult);
|
||||
sb.append("],[belongsToCollection=").append(belongsToCollection);
|
||||
sb.append("],[budget=").append(budget);
|
||||
sb.append("],[genres=").append(genres);
|
||||
sb.append("],[homepage=").append(homepage);
|
||||
sb.append("],[imdbID=").append(imdbID);
|
||||
sb.append("],[overview=").append(overview);
|
||||
sb.append("],[productionCompanies=").append(productionCompanies);
|
||||
sb.append("],[productionCountries=").append(productionCountries);
|
||||
sb.append("],[revenue=").append(revenue);
|
||||
sb.append("],[runtime=").append(runtime);
|
||||
sb.append("],[spokenLanguages=").append(spokenLanguages);
|
||||
sb.append("],[tagline=").append(tagline);
|
||||
sb.append("],[voteAverage=").append(voteAverage);
|
||||
sb.append("],[voteCount=").append(voteCount);
|
||||
sb.append("],[status=").append(status);
|
||||
sb.append("]]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.io.Serializable;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Movie Bean
|
||||
*
|
||||
* @author stuart.boston
|
||||
*/
|
||||
public class MovieDb implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MovieDb.class);
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
@JsonProperty("backdrop_path")
|
||||
private String backdropPath;
|
||||
@JsonProperty("id")
|
||||
private int id;
|
||||
@JsonProperty("original_title")
|
||||
private String originalTitle;
|
||||
@JsonProperty("popularity")
|
||||
private float popularity;
|
||||
@JsonProperty("poster_path")
|
||||
private String posterPath;
|
||||
@JsonProperty("release_date")
|
||||
private String releaseDate;
|
||||
@JsonProperty("title")
|
||||
private String title;
|
||||
@JsonProperty("adult")
|
||||
private boolean adult;
|
||||
@JsonProperty("belongs_to_collection")
|
||||
private Collection belongsToCollection;
|
||||
@JsonProperty("budget")
|
||||
private long budget;
|
||||
@JsonProperty("genres")
|
||||
private List<Genre> genres;
|
||||
@JsonProperty("homepage")
|
||||
private String homepage;
|
||||
@JsonProperty("imdb_id")
|
||||
private String imdbID;
|
||||
@JsonProperty("overview")
|
||||
private String overview;
|
||||
@JsonProperty("production_companies")
|
||||
private List<ProductionCompany> productionCompanies;
|
||||
@JsonProperty("production_countries")
|
||||
private List<ProductionCountry> productionCountries;
|
||||
@JsonProperty("revenue")
|
||||
private long revenue;
|
||||
@JsonProperty("runtime")
|
||||
private int runtime;
|
||||
@JsonProperty("spoken_languages")
|
||||
private List<Language> spokenLanguages;
|
||||
@JsonProperty("tagline")
|
||||
private String tagline;
|
||||
@JsonProperty("vote_average")
|
||||
private float voteAverage;
|
||||
@JsonProperty("vote_count")
|
||||
private int voteCount;
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Getter methods">
|
||||
public String getBackdropPath() {
|
||||
return backdropPath;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getOriginalTitle() {
|
||||
return originalTitle;
|
||||
}
|
||||
|
||||
public float getPopularity() {
|
||||
return popularity;
|
||||
}
|
||||
|
||||
public String getPosterPath() {
|
||||
return posterPath;
|
||||
}
|
||||
|
||||
public String getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public boolean isAdult() {
|
||||
return adult;
|
||||
}
|
||||
|
||||
public Collection getBelongsToCollection() {
|
||||
return belongsToCollection;
|
||||
}
|
||||
|
||||
public long getBudget() {
|
||||
return budget;
|
||||
}
|
||||
|
||||
public List<Genre> getGenres() {
|
||||
return genres;
|
||||
}
|
||||
|
||||
public String getHomepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
public String getImdbID() {
|
||||
return imdbID;
|
||||
}
|
||||
|
||||
public String getOverview() {
|
||||
return overview;
|
||||
}
|
||||
|
||||
public List<ProductionCompany> getProductionCompanies() {
|
||||
return productionCompanies;
|
||||
}
|
||||
|
||||
public List<ProductionCountry> getProductionCountries() {
|
||||
return productionCountries;
|
||||
}
|
||||
|
||||
public long getRevenue() {
|
||||
return revenue;
|
||||
}
|
||||
|
||||
public int getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public List<Language> getSpokenLanguages() {
|
||||
return spokenLanguages;
|
||||
}
|
||||
|
||||
public String getTagline() {
|
||||
return tagline;
|
||||
}
|
||||
|
||||
public float getVoteAverage() {
|
||||
return voteAverage;
|
||||
}
|
||||
|
||||
public int getVoteCount() {
|
||||
return voteCount;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Setter methods">
|
||||
public void setBackdropPath(String backdropPath) {
|
||||
this.backdropPath = backdropPath;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setOriginalTitle(String originalTitle) {
|
||||
this.originalTitle = originalTitle;
|
||||
}
|
||||
|
||||
public void setPopularity(float popularity) {
|
||||
this.popularity = popularity;
|
||||
}
|
||||
|
||||
public void setPosterPath(String posterPath) {
|
||||
this.posterPath = posterPath;
|
||||
}
|
||||
|
||||
public void setReleaseDate(String releaseDate) {
|
||||
this.releaseDate = releaseDate;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setAdult(boolean adult) {
|
||||
this.adult = adult;
|
||||
}
|
||||
|
||||
public void setBelongsToCollection(Collection belongsToCollection) {
|
||||
this.belongsToCollection = belongsToCollection;
|
||||
}
|
||||
|
||||
public void setBudget(long budget) {
|
||||
this.budget = budget;
|
||||
}
|
||||
|
||||
public void setGenres(List<Genre> genres) {
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public void setHomepage(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
public void setImdbID(String imdbID) {
|
||||
this.imdbID = imdbID;
|
||||
}
|
||||
|
||||
public void setOverview(String overview) {
|
||||
this.overview = overview;
|
||||
}
|
||||
|
||||
public void setProductionCompanies(List<ProductionCompany> productionCompanies) {
|
||||
this.productionCompanies = productionCompanies;
|
||||
}
|
||||
|
||||
public void setProductionCountries(List<ProductionCountry> productionCountries) {
|
||||
this.productionCountries = productionCountries;
|
||||
}
|
||||
|
||||
public void setRevenue(long revenue) {
|
||||
this.revenue = revenue;
|
||||
}
|
||||
|
||||
public void setRuntime(int runtime) {
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
public void setSpokenLanguages(List<Language> spokenLanguages) {
|
||||
this.spokenLanguages = spokenLanguages;
|
||||
}
|
||||
|
||||
public void setTagline(String tagline) {
|
||||
this.tagline = tagline;
|
||||
}
|
||||
|
||||
public void setVoteAverage(float voteAverage) {
|
||||
this.voteAverage = voteAverage;
|
||||
}
|
||||
|
||||
public void setVoteCount(int voteCount) {
|
||||
this.voteCount = voteCount;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
// </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());
|
||||
}
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Equals and HashCode">
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final MovieDb other = (MovieDb) obj;
|
||||
if (this.id != other.id) {
|
||||
return false;
|
||||
}
|
||||
if ((this.imdbID == null) ? (other.imdbID != null) : !this.imdbID.equals(other.imdbID)) {
|
||||
return false;
|
||||
}
|
||||
if (this.runtime != other.runtime) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 89 * hash + this.id;
|
||||
hash = 89 * hash + (this.imdbID != null ? this.imdbID.hashCode() : 0);
|
||||
hash = 89 * hash + this.runtime;
|
||||
return hash;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("[MovieDB=");
|
||||
sb.append("[backdropPath=").append(backdropPath);
|
||||
sb.append("],[id=").append(id);
|
||||
sb.append("],[originalTitle=").append(originalTitle);
|
||||
sb.append("],[popularity=").append(popularity);
|
||||
sb.append("],[posterPath=").append(posterPath);
|
||||
sb.append("],[releaseDate=").append(releaseDate);
|
||||
sb.append("],[title=").append(title);
|
||||
sb.append("],[adult=").append(adult);
|
||||
sb.append("],[belongsToCollection=").append(belongsToCollection);
|
||||
sb.append("],[budget=").append(budget);
|
||||
sb.append("],[genres=").append(genres);
|
||||
sb.append("],[homepage=").append(homepage);
|
||||
sb.append("],[imdbID=").append(imdbID);
|
||||
sb.append("],[overview=").append(overview);
|
||||
sb.append("],[productionCompanies=").append(productionCompanies);
|
||||
sb.append("],[productionCountries=").append(productionCountries);
|
||||
sb.append("],[revenue=").append(revenue);
|
||||
sb.append("],[runtime=").append(runtime);
|
||||
sb.append("],[spokenLanguages=").append(spokenLanguages);
|
||||
sb.append("],[tagline=").append(tagline);
|
||||
sb.append("],[voteAverage=").append(voteAverage);
|
||||
sb.append("],[voteCount=").append(voteCount);
|
||||
sb.append("],[status=").append(status);
|
||||
sb.append("]]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,213 +1,224 @@
|
||||
/*
|
||||
* 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.tools;
|
||||
|
||||
import com.omertron.themoviedbapi.TheMovieDbApi;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The API URL that is used to construct the API call
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public class ApiUrl {
|
||||
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ApiUrl.class);
|
||||
/*
|
||||
* TheMovieDbApi API Base URL
|
||||
*/
|
||||
private static final String TMDB_API_BASE = "http://api.themoviedb.org/3/";
|
||||
/*
|
||||
* Parameter configuration
|
||||
*/
|
||||
private static final String DELIMITER_FIRST = "?";
|
||||
private static final String DELIMITER_SUBSEQUENT = "&";
|
||||
private static final String DEFAULT_STRING = "";
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
private TheMovieDbApi tmdb;
|
||||
private String method;
|
||||
private String submethod;
|
||||
private Map<String, String> arguments = new HashMap<String, String>();
|
||||
/*
|
||||
* API Parameters
|
||||
*/
|
||||
public static final String PARAM_ADULT = "include_adult=";
|
||||
public static final String PARAM_API_KEY = "api_key=";
|
||||
public static final String PARAM_COUNTRY = "country=";
|
||||
public static final String PARAM_FAVORITE = "favorite=";
|
||||
public static final String PARAM_ID = "id=";
|
||||
public static final String PARAM_LANGUAGE = "language=";
|
||||
public static final String PARAM_INCLUDE_ALL_MOVIES = "include_all_movies=";
|
||||
// public static final String PARAM_MOVIE_ID = "movie_id=";
|
||||
public static final String PARAM_MOVIE_WATCHLIST = "movie_watchlist=";
|
||||
public static final String PARAM_PAGE = "page=";
|
||||
public static final String PARAM_QUERY = "query=";
|
||||
public static final String PARAM_SESSION = "session_id=";
|
||||
public static final String PARAM_TOKEN = "request_token=";
|
||||
public static final String PARAM_VALUE = "value=";
|
||||
public static final String PARAM_YEAR = "year=";
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Constructor Methods">
|
||||
/**
|
||||
* Constructor for the simple API URL method without a sub-method
|
||||
*
|
||||
* @param method
|
||||
*/
|
||||
public ApiUrl(TheMovieDbApi tmdb, String method) {
|
||||
this.tmdb = tmdb;
|
||||
this.method = method;
|
||||
this.submethod = DEFAULT_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the API URL with a sub-method
|
||||
*
|
||||
* @param method
|
||||
* @param submethod
|
||||
*/
|
||||
public ApiUrl(TheMovieDbApi tmdb, String method, String submethod) {
|
||||
this.tmdb = tmdb;
|
||||
this.method = method;
|
||||
this.submethod = submethod;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/**
|
||||
* Build the URL from the pre-created arguments.
|
||||
*/
|
||||
public URL buildUrl() {
|
||||
StringBuilder urlString = new StringBuilder(TMDB_API_BASE);
|
||||
|
||||
// Get the start of the URL
|
||||
urlString.append(method);
|
||||
|
||||
// We have either a queury, or a direct request
|
||||
if (arguments.containsKey(PARAM_QUERY)) {
|
||||
// Append the suffix of the API URL
|
||||
urlString.append(submethod);
|
||||
|
||||
// Append the key information
|
||||
urlString.append(DELIMITER_FIRST).append(PARAM_API_KEY);
|
||||
urlString.append(tmdb.getApiKey());
|
||||
|
||||
// Append the search term
|
||||
urlString.append(DELIMITER_SUBSEQUENT);
|
||||
urlString.append(PARAM_QUERY);
|
||||
|
||||
String query = arguments.get(PARAM_QUERY);
|
||||
|
||||
try {
|
||||
urlString.append(URLEncoder.encode(query, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
LOG.trace("Unable to encode query: '" + query + "' trying raw.");
|
||||
// If we can't encode it, try it raw
|
||||
urlString.append(query);
|
||||
}
|
||||
|
||||
arguments.remove(PARAM_QUERY);
|
||||
} else {
|
||||
// Append the ID if provided
|
||||
if (arguments.containsKey(PARAM_ID)) {
|
||||
urlString.append(arguments.get(PARAM_ID));
|
||||
arguments.remove(PARAM_ID);
|
||||
}
|
||||
|
||||
// Append the suffix of the API URL
|
||||
urlString.append(submethod);
|
||||
|
||||
// Append the key information
|
||||
urlString.append(DELIMITER_FIRST).append(PARAM_API_KEY);
|
||||
urlString.append(tmdb.getApiKey());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> argEntry : arguments.entrySet()) {
|
||||
urlString.append(DELIMITER_SUBSEQUENT).append(argEntry.getKey());
|
||||
urlString.append(argEntry.getValue());
|
||||
}
|
||||
|
||||
try {
|
||||
LOG.trace("URL: {}", urlString.toString());
|
||||
return new URL(urlString.toString());
|
||||
} catch (MalformedURLException ex) {
|
||||
LOG.warn("Failed to create URL {} - {}", urlString.toString(), ex.toString());
|
||||
return null;
|
||||
} finally {
|
||||
arguments.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arguments individually
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addArgument(String key, String value) {
|
||||
arguments.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arguments individually
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addArgument(String key, int value) {
|
||||
arguments.put(key, Integer.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arguments individually
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addArgument(String key, boolean value) {
|
||||
arguments.put(key, Boolean.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the arguments
|
||||
*/
|
||||
public void clearArguments() {
|
||||
arguments.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the arguments directly
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void setArguments(Map<String, String> args) {
|
||||
arguments.putAll(args);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.tools;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The API URL that is used to construct the API call
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public class ApiUrl {
|
||||
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ApiUrl.class);
|
||||
/*
|
||||
* TheMovieDbApi API Base URL
|
||||
*/
|
||||
private static final String TMDB_API_BASE = "http://api.themoviedb.org/3/";
|
||||
/*
|
||||
* Parameter configuration
|
||||
*/
|
||||
private static final String DELIMITER_FIRST = "?";
|
||||
private static final String DELIMITER_SUBSEQUENT = "&";
|
||||
private static final String DEFAULT_STRING = "";
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
private String apiKey;
|
||||
private String method;
|
||||
private String submethod;
|
||||
private Map<String, String> arguments = new HashMap<String, String>();
|
||||
/*
|
||||
* API Parameters
|
||||
*/
|
||||
public static final String PARAM_ADULT = "include_adult=";
|
||||
public static final String PARAM_API_KEY = "api_key=";
|
||||
public static final String PARAM_COUNTRY = "country=";
|
||||
public static final String PARAM_FAVORITE = "favorite=";
|
||||
public static final String PARAM_ID = "id=";
|
||||
public static final String PARAM_LANGUAGE = "language=";
|
||||
public static final String PARAM_INCLUDE_ALL_MOVIES = "include_all_movies=";
|
||||
// public static final String PARAM_MOVIE_ID = "movie_id=";
|
||||
public static final String PARAM_MOVIE_WATCHLIST = "movie_watchlist=";
|
||||
public static final String PARAM_PAGE = "page=";
|
||||
public static final String PARAM_QUERY = "query=";
|
||||
public static final String PARAM_SESSION = "session_id=";
|
||||
public static final String PARAM_TOKEN = "request_token=";
|
||||
public static final String PARAM_VALUE = "value=";
|
||||
public static final String PARAM_YEAR = "year=";
|
||||
private static final String APPEND_TO_RESPONSE = "append_to_response=";
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Constructor Methods">
|
||||
/**
|
||||
* Constructor for the simple API URL method without a sub-method
|
||||
*
|
||||
* @param method
|
||||
*/
|
||||
public ApiUrl(String apiKey, String method) {
|
||||
this.apiKey = apiKey;
|
||||
this.method = method;
|
||||
this.submethod = DEFAULT_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the API URL with a sub-method
|
||||
*
|
||||
* @param method
|
||||
* @param submethod
|
||||
*/
|
||||
public ApiUrl(String apiKey, String method, String submethod) {
|
||||
this.apiKey = apiKey;
|
||||
this.method = method;
|
||||
this.submethod = submethod;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/**
|
||||
* Build the URL from the pre-created arguments.
|
||||
*/
|
||||
public URL buildUrl() {
|
||||
StringBuilder urlString = new StringBuilder(TMDB_API_BASE);
|
||||
|
||||
// Get the start of the URL
|
||||
urlString.append(method);
|
||||
|
||||
// We have either a queury, or a direct request
|
||||
if (arguments.containsKey(PARAM_QUERY)) {
|
||||
// Append the suffix of the API URL
|
||||
urlString.append(submethod);
|
||||
|
||||
// Append the key information
|
||||
urlString.append(DELIMITER_FIRST).append(PARAM_API_KEY);
|
||||
urlString.append(apiKey);
|
||||
|
||||
// Append the search term
|
||||
urlString.append(DELIMITER_SUBSEQUENT);
|
||||
urlString.append(PARAM_QUERY);
|
||||
|
||||
String query = arguments.get(PARAM_QUERY);
|
||||
|
||||
try {
|
||||
urlString.append(URLEncoder.encode(query, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
LOG.trace("Unable to encode query: '{}' trying raw.", query);
|
||||
// If we can't encode it, try it raw
|
||||
urlString.append(query);
|
||||
}
|
||||
|
||||
arguments.remove(PARAM_QUERY);
|
||||
} else {
|
||||
// Append the ID if provided
|
||||
if (arguments.containsKey(PARAM_ID)) {
|
||||
urlString.append(arguments.get(PARAM_ID));
|
||||
arguments.remove(PARAM_ID);
|
||||
}
|
||||
|
||||
// Append the suffix of the API URL
|
||||
urlString.append(submethod);
|
||||
|
||||
// Append the key information
|
||||
urlString.append(DELIMITER_FIRST).append(PARAM_API_KEY);
|
||||
urlString.append(apiKey);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> argEntry : arguments.entrySet()) {
|
||||
urlString.append(DELIMITER_SUBSEQUENT).append(argEntry.getKey());
|
||||
urlString.append(argEntry.getValue());
|
||||
}
|
||||
|
||||
try {
|
||||
LOG.trace("URL: {}", urlString.toString());
|
||||
return new URL(urlString.toString());
|
||||
} catch (MalformedURLException ex) {
|
||||
LOG.warn("Failed to create URL {} - {}", urlString.toString(), ex.toString());
|
||||
return null;
|
||||
} finally {
|
||||
arguments.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arguments individually
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addArgument(String key, String value) {
|
||||
arguments.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arguments individually
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addArgument(String key, int value) {
|
||||
arguments.put(key, Integer.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add arguments individually
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addArgument(String key, boolean value) {
|
||||
arguments.put(key, Boolean.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the arguments
|
||||
*/
|
||||
public void clearArguments() {
|
||||
arguments.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the arguments directly
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void setArguments(Map<String, String> args) {
|
||||
arguments.putAll(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append any optional parameters to the URL
|
||||
*
|
||||
* @param appendToResponse
|
||||
*/
|
||||
public void appendToResponse(String[] appendToResponse) {
|
||||
if (appendToResponse.length > 0) {
|
||||
addArgument(APPEND_TO_RESPONSE, appendToResponse[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue