Use union types for Region, Language, and Page options
This commit is contained in:
@@ -6,15 +6,16 @@ import {
|
|||||||
ExternalIds,
|
ExternalIds,
|
||||||
Images,
|
Images,
|
||||||
Keywords,
|
Keywords,
|
||||||
|
LanguageOption,
|
||||||
LatestMovie,
|
LatestMovie,
|
||||||
LocaleOptions,
|
|
||||||
MovieChanges,
|
MovieChanges,
|
||||||
MovieDetails,
|
MovieDetails,
|
||||||
MovieLists,
|
MovieLists,
|
||||||
MoviesPlayingNow,
|
MoviesPlayingNow,
|
||||||
PageOptions,
|
PageOption,
|
||||||
PopularMovies,
|
PopularMovies,
|
||||||
Recommendations,
|
Recommendations,
|
||||||
|
RegionOption,
|
||||||
ReleaseDates,
|
ReleaseDates,
|
||||||
Reviews,
|
Reviews,
|
||||||
SimilarMovies,
|
SimilarMovies,
|
||||||
@@ -62,14 +63,14 @@ export class MoviesEndpoint extends BaseEndpoint{
|
|||||||
return await this.api.get<Keywords>(`${BASE_MOVIE}/${id}/keywords`);
|
return await this.api.get<Keywords>(`${BASE_MOVIE}/${id}/keywords`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async lists(id: number, options?: PageOptions): Promise<MovieLists>{
|
async lists(id: number, options?: LanguageOption | PageOption): Promise<MovieLists>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<MovieLists>(`${BASE_MOVIE}/${id}/lists?${params}`);
|
return await this.api.get<MovieLists>(`${BASE_MOVIE}/${id}/lists?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async recommendations(id: number, options?: PageOptions): Promise<Recommendations>{
|
async recommendations(id: number, options?: PageOption): Promise<Recommendations>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
@@ -80,14 +81,14 @@ export class MoviesEndpoint extends BaseEndpoint{
|
|||||||
return await this.api.get<ReleaseDates>(`${BASE_MOVIE}/${id}/release_dates`);
|
return await this.api.get<ReleaseDates>(`${BASE_MOVIE}/${id}/release_dates`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reviews(id: number, options?: PageOptions): Promise<Reviews>{
|
async reviews(id: number, options?: PageOption): Promise<Reviews>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews?${params}`);
|
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async similar(id: number, options?: PageOptions): Promise<SimilarMovies>{
|
async similar(id: number, options?: PageOption): Promise<SimilarMovies>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
@@ -114,28 +115,28 @@ export class MoviesEndpoint extends BaseEndpoint{
|
|||||||
return await this.api.get<LatestMovie>(`${BASE_MOVIE}/latest`);
|
return await this.api.get<LatestMovie>(`${BASE_MOVIE}/latest`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async nowPlaying(options?: LocaleOptions): Promise<MoviesPlayingNow>{
|
async nowPlaying(options?: PageOption & LanguageOption & RegionOption): Promise<MoviesPlayingNow>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<MoviesPlayingNow>(`${BASE_MOVIE}/now_playing?${params}`);
|
return await this.api.get<MoviesPlayingNow>(`${BASE_MOVIE}/now_playing?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async popular(options?: PageOptions): Promise<PopularMovies>{
|
async popular(options?: PageOption): Promise<PopularMovies>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<PopularMovies>(`${BASE_MOVIE}/popular?${params}`);
|
return await this.api.get<PopularMovies>(`${BASE_MOVIE}/popular?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async topRated(options?: LocaleOptions): Promise<TopRatedMovies>{
|
async topRated(options?: PageOption & LanguageOption & RegionOption): Promise<TopRatedMovies>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<TopRatedMovies>(`${BASE_MOVIE}/top_rated?${params}`);
|
return await this.api.get<TopRatedMovies>(`${BASE_MOVIE}/top_rated?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async upcoming(options?: LocaleOptions): Promise<UpcomingMovies>{
|
async upcoming(options?: PageOption & LanguageOption & RegionOption): Promise<UpcomingMovies>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
|
|||||||
@@ -1,4 +1,17 @@
|
|||||||
import { ChangeOptions, ExternalIds, Image, PageOptions, PeopleTranslations, PersonChanges, PersonCombinedCredits, PersonDetail, PersonMovieCredit, PersonTvShowCredit, PopularPersons, TaggedImages } from '../types';
|
import {
|
||||||
|
ChangeOptions,
|
||||||
|
ExternalIds,
|
||||||
|
Image,
|
||||||
|
PageOption,
|
||||||
|
PeopleTranslations,
|
||||||
|
PersonChanges,
|
||||||
|
PersonCombinedCredits,
|
||||||
|
PersonDetail,
|
||||||
|
PersonMovieCredit,
|
||||||
|
PersonTvShowCredit,
|
||||||
|
PopularPersons,
|
||||||
|
TaggedImages
|
||||||
|
} from '../types';
|
||||||
import { BaseEndpoint } from './base';
|
import { BaseEndpoint } from './base';
|
||||||
|
|
||||||
const BASE_PERSON = '/person';
|
const BASE_PERSON = '/person';
|
||||||
@@ -39,7 +52,7 @@ export class PeopleEndpoint extends BaseEndpoint {
|
|||||||
return await this.api.get<{id: number, profiles: Image[]}>(`${BASE_PERSON}/${id}/images`)
|
return await this.api.get<{id: number, profiles: Image[]}>(`${BASE_PERSON}/${id}/images`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async taggedImages(id: number, options?: PageOptions): Promise<TaggedImages>{
|
async taggedImages(id: number, options?: PageOption): Promise<TaggedImages>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
@@ -54,7 +67,7 @@ export class PeopleEndpoint extends BaseEndpoint {
|
|||||||
return await this.api.get<PersonDetail>(`${BASE_PERSON}/latest`);
|
return await this.api.get<PersonDetail>(`${BASE_PERSON}/latest`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async popular(options?: PageOptions): Promise<PopularPersons>{
|
async popular(options?: PageOption): Promise<PopularPersons>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ import {
|
|||||||
ExternalIds,
|
ExternalIds,
|
||||||
Images,
|
Images,
|
||||||
Keywords,
|
Keywords,
|
||||||
|
LanguageOption,
|
||||||
LatestTvShows,
|
LatestTvShows,
|
||||||
LocaleOptions,
|
|
||||||
OnTheAir,
|
OnTheAir,
|
||||||
PageOptions,
|
PageOption,
|
||||||
PopularTvShows,
|
PopularTvShows,
|
||||||
Recommendations,
|
Recommendations,
|
||||||
|
RegionOption,
|
||||||
Reviews,
|
Reviews,
|
||||||
ScreenedTheatrically,
|
ScreenedTheatrically,
|
||||||
SeasonDetails,
|
SeasonDetails,
|
||||||
@@ -77,14 +78,14 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
|||||||
return await this.api.get<Keywords>(`${BASE_TV}/${id}/keywords`);
|
return await this.api.get<Keywords>(`${BASE_TV}/${id}/keywords`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async recommendations(id: number, options?: PageOptions): Promise<Recommendations>{
|
async recommendations(id: number, options?: PageOption): Promise<Recommendations>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<Recommendations>(`${BASE_TV}/${id}/recommendations?${params}`);
|
return await this.api.get<Recommendations>(`${BASE_TV}/${id}/recommendations?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reviews(id: number, options?: PageOptions): Promise<Reviews>{
|
async reviews(id: number, options?: PageOption): Promise<Reviews>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
@@ -95,7 +96,7 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
|||||||
return await this.api.get<ScreenedTheatrically>(`${BASE_TV}/${id}/screened_theatrically`);
|
return await this.api.get<ScreenedTheatrically>(`${BASE_TV}/${id}/screened_theatrically`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async similar(id: number, options?: PageOptions): Promise<SimilarTvShows>{
|
async similar(id: number, options?: PageOption): Promise<SimilarTvShows>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
@@ -126,21 +127,21 @@ export class TvShowsEndpoint extends BaseEndpoint{
|
|||||||
return await this.api.get<OnTheAir>(`${BASE_TV}/on_the_air`);
|
return await this.api.get<OnTheAir>(`${BASE_TV}/on_the_air`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async airingToday(options?: LocaleOptions): Promise<TvShowsAiringToday>{
|
async airingToday(options?: PageOption & LanguageOption & RegionOption): Promise<TvShowsAiringToday>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<TvShowsAiringToday>(`${BASE_TV}/airing_today?${params}`);
|
return await this.api.get<TvShowsAiringToday>(`${BASE_TV}/airing_today?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async popular(options?: PageOptions): Promise<PopularTvShows>{
|
async popular(options?: PageOption & LanguageOption & RegionOption): Promise<PopularTvShows>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
return await this.api.get<PopularTvShows>(`${BASE_TV}/popular?${params}`);
|
return await this.api.get<PopularTvShows>(`${BASE_TV}/popular?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async topRated(options?: LocaleOptions): Promise<TopRatedTvShows>{
|
async topRated(options?: PageOption & LanguageOption & RegionOption): Promise<TopRatedTvShows>{
|
||||||
const params = options
|
const params = options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
: '';
|
: '';
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ export * from './movies';
|
|||||||
export * from './search';
|
export * from './search';
|
||||||
export * from './tv-shows';
|
export * from './tv-shows';
|
||||||
export * from './watch-providers';
|
export * from './watch-providers';
|
||||||
export * from './page';
|
|
||||||
export * from './people';
|
export * from './people';
|
||||||
export * from './discover';
|
export * from './discover';
|
||||||
export * from './review';
|
export * from './review';
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
export interface PageOptions {
|
|
||||||
page?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LocaleOptions extends PageOptions {
|
|
||||||
region?: string;
|
|
||||||
language?: string;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user