Skip to content

Commit

Permalink
feat(api): add new methods & watchProvider entity
Browse files Browse the repository at this point in the history
  • Loading branch information
leocabeza committed Aug 8, 2021
1 parent dc64d0c commit 56c0ddf
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 8 deletions.
29 changes: 23 additions & 6 deletions src/entities/v3/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const changes = async (movieId, options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/movies/get-movie-credits
*/
export const credits = async movieId => {
export const credits = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}
Expand Down Expand Up @@ -150,7 +150,7 @@ export const details = async (movieId, options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/movies/get-movie-external-ids
*/
export const externalIds = async movieId => {
export const externalIds = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}
Expand Down Expand Up @@ -188,7 +188,7 @@ export const images = async (movieId, options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/movies/get-movie-keywords
*/
export const keywords = async movieId => {
export const keywords = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}
Expand Down Expand Up @@ -343,7 +343,7 @@ export const recommendations = async (movieId, options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/movies/get-movie-release-dates
*/
export const releaseDates = async movieId => {
export const releaseDates = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}
Expand Down Expand Up @@ -415,7 +415,7 @@ export const topRated = async (options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/movies/get-movie-translations
*/
export const translations = async movieId => {
export const translations = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}
Expand Down Expand Up @@ -448,10 +448,27 @@ export const upcoming = async (options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/movies/get-movie-videos
*/
export const videos = async movieId => {
export const videos = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}

return makeHttpRequest(urls.v3.MOVIE_VIDEOS.replace(':id', movieId));
};

/**
* Powered by our partnership with JustWatch, you can query this method to get a list of the availabilities per country by provider.
* This is not going to return full deep links, but rather, it's just enough information to display what's available where.
* You can link to the provided TMDB URL to help support TMDB and provide the actual deep links to the content.
* Please note: In order to use this data you must attribute the source of the data as JustWatch. If we find any usage not complying with these terms we will revoke access to the API.
* @param {number} movieId
* @return {Promise} Promise
* @see https://developers.themoviedb.org/3/movies/get-movie-watch-providers
*/
export const watchProviders = async (movieId) => {
if (!movieId) {
return Promise.reject('A movieId has to be provided');
}

return makeHttpRequest(urls.v3.MOVIE_WATCH_PROVIDERS.replace(':id', movieId));
};
63 changes: 63 additions & 0 deletions src/entities/v3/tv-season.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,40 @@ export const accountStates = async (tvId, seasonNumber, options = {}) => {
);
};

/**
* Get the aggregate credits for TV season.
* This call differs from the main credits call in
* that it does not only return the season credits,
* but rather is a view of all the cast & crew for all of the episodes belonging to a season.
* @param {number} tvId - Required
* @param {number} seasonNumber - Required
* @param {Object} options
* @param {string} options.language
* @returns {Promise}
* @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-aggregate-credits
*/
export const aggregateCredits = async (tvId, seasonNumber, options = {}) => {
const { language } = options;

if (!tvId && tvId !== 0) {
return Promise.reject('A tvId has to be provided');
}

if (!seasonNumber && seasonNumber !== 0) {
return Promise.reject('A seasonNumber has to be provided');
}

return await makeHttpRequest(
urls.v3.TV_SEASON_AGGREGATE_CREDITS.replace(':id', tvId).replace(
':seasonNumber',
seasonNumber
),
{
language,
}
);
};

/**
* Get the changes for a TV season. By default only the last 24 hours are returned.
* You can query up to 14 days in a single query by using the start_date and end_date query options.
Expand Down Expand Up @@ -190,6 +224,35 @@ export const images = async (tvId, seasonNumber, options = {}) => {
);
};

/**
* Get the credits for TV season.
* @param {number} tvId - Required
* @param {number} seasonNumber - Required
* @param {Object} options
* @param {string} options.language
* @returns {Promise}
* @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-translations
*/
export const translations = async (tvId, seasonNumber) => {
if (!tvId) {
return Promise.reject('A tvId has to be provided');
}

if (!seasonNumber) {
return Promise.reject('A seasonNumber has to be provided');
}

return makeHttpRequest(
urls.v3.TV_SEASON_TRANSLATIONS.replace(':tvId', tvId).replace(
':seasonNumber',
seasonNumber
),
{
language,
}
);
};

/**
* Get the videos that have been added to a TV season.
* @param {number} tvId - Required
Expand Down
46 changes: 44 additions & 2 deletions src/entities/v3/tv.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ export const accountStates = async (tvId, options = {}) => {
);
};

/**
* Get the aggregate credits (cast and crew) that have been added to a TV show.
* This call differs from the main credits call in that it does not return the newest season but rather,
* is a view of all the entire cast & crew for all episodes belonging to a TV show.
* @param {number} tvId - Required
* @param {Object} options
* @param {string} options.language
* @returns {Promise}
* @see https://developers.themoviedb.org/3/tv/get-tv-aggregate-credits
*/
export const aggregateCredits = async (tvId, options = {}) => {
const { language } = options;

if (!tvId && tvId !== 0) {
return Promise.reject('A tvId has to be provided');
}

return await makeHttpRequest(
urls.v3.TV_AGGREGATE_CREDITS.replace(':id', tvId),
{
language,
}
);
};

/**
* Get a list of TV shows that are airing today. This query is purely day based as we do not currently support airing times.
* You can specify a timezone to offset the day calculation. Without a specified timezone, this query defaults to EST (Eastern Time UTC-05:00).
Expand Down Expand Up @@ -263,7 +288,7 @@ export const images = async (tvId, options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/tv/get-tv-keywords
*/
export const keywords = async tvId => {
export const keywords = async (tvId) => {
if (!tvId && tvId !== 0) {
return Promise.reject('A tvId has to be provided');
}
Expand Down Expand Up @@ -403,7 +428,7 @@ export const reviews = async (tvId, options = {}) => {
* @returns {Promise}
* @see https://developers.themoviedb.org/3/tv/get-screened-theatrically
*/
export const screenedTheatrically = async tvId => {
export const screenedTheatrically = async (tvId) => {
if (!tvId && tvId !== 0) {
return Promise.reject('A tvId has to be provided');
}
Expand Down Expand Up @@ -488,3 +513,20 @@ export const videos = async (tvId, options = {}) => {
language,
});
};

/**
* Powered by our partnership with JustWatch, you can query this method to get a list of the availabilities per country by provider.
* This is not going to return full deep links, but rather, it's just enough information to display what's available where.
* You can link to the provided TMDB URL to help support TMDB and provide the actual deep links to the content.
* Please note: In order to use this data you must attribute the source of the data as JustWatch. If we find any usage not complying with these terms we will revoke access to the API.
* @param {number} tvId
* @return {Promise} Promise
* @see https://developers.themoviedb.org/3/tv/get-tv-watch-providers
*/
export const watchProviders = async (tvId) => {
if (!tvId) {
return Promise.reject('A tvId has to be provided');
}

return makeHttpRequest(urls.v3.TV_WATCH_PROVIDERS.replace(':id', tvId));
};
2 changes: 2 additions & 0 deletions src/entities/v3/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as tv from './tv';
import * as tvEpisode from './tv-episode';
import * as tvEpisodeGroup from './tv-episode-group';
import * as tvSeason from './tv-season';
import * as watchProvider from './watch-provider';

export default {
account,
Expand All @@ -48,4 +49,5 @@ export default {
tvEpisode,
tvEpisodeGroup,
tvSeason,
watchProvider,
};
57 changes: 57 additions & 0 deletions src/entities/v3/watch-provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { makeHttpRequest } from 'utils/utils';
import urls from 'urls/urls';

/**
* @module watchProvider
*/

/**
* Returns a list of all of the countries we have watch provider (OTT/streaming) data for.
* @param {Object} options
* @param {string} options.language
* @returns {Promise}
* @see https://developers.themoviedb.org/3/watch-providers/get-available-regions
*/
export const availableRegions = async (options = {}) => {
const { language } = options;

return await makeHttpRequest(urls.v3.WATCH_PROVIDERS_AVAILABLE_REGIONS, {
language,
});
};

/**
* Returns a list of the watch provider (OTT/streaming) data we have available for movies.
* You can specify a watch_region param if you want to further filter the list by country.
* @param {Object} options
* @param {string} options.language
* @param {string} options.watch_region
* @returns {Promise}
* @see https://developers.themoviedb.org/3/watch-providers/get-movie-providers
*/
export const movie = async (options = {}) => {
const { language, watch_region } = options;

return await makeHttpRequest(urls.v3.WATCH_PROVIDERS_MOVIE, {
language,
watch_region,
});
};

/**
* Returns a list of the watch provider (OTT/streaming) data we have available for TV series.
* You can specify a watch_region param if you want to further filter the list by country.
* @param {Object} options
* @param {string} options.language
* @param {string} options.watch_region
* @returns {Promise}
* @see https://developers.themoviedb.org/3/watch-providers/get-tv-providers
*/
export const tv = async (options = {}) => {
const { language, watch_region } = options;

return await makeHttpRequest(urls.v3.WATCH_PROVIDERS_TV, {
language,
watch_region,
});
};
10 changes: 10 additions & 0 deletions src/urls/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const MOVIE_SIMILAR = '/movie/:id/similar';
export const MOVIE_TOP_RATED = '/movie/top_rated';
export const MOVIE_TRANSLATIONS = '/movie/:id/translations';
export const MOVIE_UPCOMING = '/movie/upcoming';
export const MOVIE_WATCH_PROVIDERS = '/movie/:id/watch/providers';
export const MOVIE_VIDEOS = '/movie/:id/videos';
export const NETWORK_DETAILS = '/network/:id';
export const NETWORK_ALTERNATIVE_NAMES = '/network/:id/alternative_names';
Expand All @@ -101,6 +102,7 @@ export const SEARCH_PEOPLE = '/search/person';
export const SEARCH_TV = '/search/tv';
export const TRENDING_ITEMS = '/trending/:mediaType/:timeWindow';
export const TV_ACCOUNT_STATES = '/tv/:id/account_states';
export const TV_AGGREGATE_CREDITS = '/tv/:id/aggregate_credits';
export const TV_AIRING_TODAY = '/tv/airing_today';
export const TV_ALTERNATIVE_TITLES = '/tv/:id/alternative_titles';
export const TV_CHANGES = '/tv/:id/changes';
Expand All @@ -122,6 +124,7 @@ export const TV_SIMILAR = '/tv/:id/similar';
export const TV_TOP_RATED = '/tv/top_rated';
export const TV_TRANSLATIONS = '/tv/:id/translations';
export const TV_VIDEOS = '/tv/:id/videos';
export const TV_WATCH_PROVIDERS = '/tv/:id/watch/providers';
export const TV_EPISODE_ACCOUNT_STATES =
'/tv/:tvId/season/:seasonNumber/episode/:episodeNumber/account_states';
export const TV_EPISODE_CHANGES = '/tv/episode/:episodeId/changes';
Expand All @@ -142,10 +145,17 @@ export const TV_EPISODE_VIDEOS =
export const TV_EPISODE_GROUP_DETAILS = '/tv/episode_group/:id';
export const TV_SEASON_ACCOUNT_STATES =
'/tv/:tvId/season/:seasonNumber/account_states';
export const TV_SEASON_AGGREGATE_CREDITS =
'/tv/:id/season/:seasonNumber/aggregate_credits';
export const TV_SEASON_CHANGES = '/tv/season/:seasonId/changes';
export const TV_SEASON_CREDITS = '/tv/:tvId/season/:seasonNumber/credits';
export const TV_SEASON_DETAILS = '/tv/:tvId/season/:seasonNumber';
export const TV_SEASON_EXTERNAL_IDS =
'/tv/:tvId/season/:seasonNumber/external_ids';
export const TV_SEASON_IMAGES = '/tv/:tvId/season/:seasonNumber/images';
export const TV_SEASON_TRANSLATIONS =
'/tv/:tvId/season/:seasonNumber/translations';
export const TV_SEASON_VIDEOS = '/tv/:tvId/season/:seasonNumber/videos';
export const WATCH_PROVIDERS_AVAILABLE_REGIONS = '/watch/providers/regions';
export const WATCH_PROVIDERS_MOVIE = '/watch/providers/movie';
export const WATCH_PROVIDERS_TV = '/watch/providers/tv';

0 comments on commit 56c0ddf

Please sign in to comment.