Merge pull request #37 from Der-Penz/endpoint/tv-season
Endpoint/tvSeason
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tmdb-ts",
|
"name": "tmdb-ts",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"description": "TMDB v3 library wrapper",
|
"description": "TMDB v3 library wrapper",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -14,5 +14,6 @@ export * from './trending';
|
|||||||
export * from './find';
|
export * from './find';
|
||||||
export * from './keywords';
|
export * from './keywords';
|
||||||
export * from './collections';
|
export * from './collections';
|
||||||
|
export * from './tv-seasons';
|
||||||
export * from './tv-episode';
|
export * from './tv-episode';
|
||||||
|
|
||||||
|
|||||||
102
src/endpoints/tv-seasons.ts
Normal file
102
src/endpoints/tv-seasons.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import {
|
||||||
|
ChangeOption,
|
||||||
|
Changes,
|
||||||
|
Credits,
|
||||||
|
ExternalIds,
|
||||||
|
Images,
|
||||||
|
LanguageOption,
|
||||||
|
TvSeasonChangeValue,
|
||||||
|
SeasonDetails,
|
||||||
|
SeasonSelection,
|
||||||
|
Translations,
|
||||||
|
Videos,
|
||||||
|
AppendToResponseTvSeasonKey,
|
||||||
|
AppendToResponse,
|
||||||
|
} from '..';
|
||||||
|
import { BaseEndpoint } from './base';
|
||||||
|
|
||||||
|
const BASE_SEASON = (seasonSelection: SeasonSelection): string => {
|
||||||
|
return `/tv/${seasonSelection.tvShowID}/season/${seasonSelection.seasonNumber}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export class TvSeasonsEndpoint extends BaseEndpoint {
|
||||||
|
constructor(accessToken: string) {
|
||||||
|
super(accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
async details<T extends AppendToResponseTvSeasonKey[] | undefined>(
|
||||||
|
seasonSelection: SeasonSelection,
|
||||||
|
appendToResponse?: T,
|
||||||
|
options?: LanguageOption
|
||||||
|
) {
|
||||||
|
const combinedOptions = {
|
||||||
|
append_to_response: appendToResponse
|
||||||
|
? appendToResponse.join(',')
|
||||||
|
: undefined,
|
||||||
|
...options,
|
||||||
|
};
|
||||||
|
|
||||||
|
return await this.api.get<AppendToResponse<SeasonDetails, T, 'tvSeason'>>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}`,
|
||||||
|
combinedOptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async aggregateCredits(
|
||||||
|
seasonSelection: SeasonSelection,
|
||||||
|
options?: LanguageOption
|
||||||
|
) {
|
||||||
|
return await this.api.get<Credits>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}/aggregate_credits`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async changes(seasonId: number, options?: ChangeOption) {
|
||||||
|
return await this.api.get<Changes<TvSeasonChangeValue>>(
|
||||||
|
`/tv/season/${seasonId}/changes`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async credits(seasonSelection: SeasonSelection, options?: LanguageOption) {
|
||||||
|
return await this.api.get<Credits>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}/credits`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async externalIds(
|
||||||
|
seasonSelection: SeasonSelection,
|
||||||
|
options?: LanguageOption
|
||||||
|
) {
|
||||||
|
return await this.api.get<ExternalIds>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}/external_ids`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async images(seasonSelection: SeasonSelection, options?: LanguageOption) {
|
||||||
|
return await this.api.get<Images>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}/images`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async videos(seasonSelection: SeasonSelection, options?: LanguageOption) {
|
||||||
|
return await this.api.get<Videos>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}/videos`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async translations(
|
||||||
|
seasonSelection: SeasonSelection,
|
||||||
|
options?: LanguageOption
|
||||||
|
) {
|
||||||
|
return await this.api.get<Translations>(
|
||||||
|
`${BASE_SEASON(seasonSelection)}/translations`,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
FindEndpoint,
|
FindEndpoint,
|
||||||
KeywordsEndpoint,
|
KeywordsEndpoint,
|
||||||
CollectionsEndpoint,
|
CollectionsEndpoint,
|
||||||
|
TvSeasonsEndpoint,
|
||||||
TvEpisodesEndpoint,
|
TvEpisodesEndpoint,
|
||||||
} from './endpoints';
|
} from './endpoints';
|
||||||
|
|
||||||
@@ -92,4 +93,8 @@ export class TMDB {
|
|||||||
get collections(): CollectionsEndpoint {
|
get collections(): CollectionsEndpoint {
|
||||||
return new CollectionsEndpoint(this.accessToken);
|
return new CollectionsEndpoint(this.accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get tvSeasons() : TvSeasonsEndpoint {
|
||||||
|
return new TvSeasonsEndpoint(this.accessToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export * from './find';
|
|||||||
export * from './keywords';
|
export * from './keywords';
|
||||||
export * from './collections';
|
export * from './collections';
|
||||||
export * from './tv-episode';
|
export * from './tv-episode';
|
||||||
|
export * from './tv-seasons';
|
||||||
|
|
||||||
export type MediaType = 'movie' | 'tv' | 'person';
|
export type MediaType = 'movie' | 'tv' | 'person';
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
TvEpisodeChangeValue,
|
TvEpisodeChangeValue,
|
||||||
TvEpisodeCredit,
|
TvEpisodeCredit,
|
||||||
TvEpisodeTranslations,
|
TvEpisodeTranslations,
|
||||||
|
TvSeasonChangeValue,
|
||||||
} from '.';
|
} from '.';
|
||||||
|
|
||||||
export interface LanguageOption {
|
export interface LanguageOption {
|
||||||
@@ -99,16 +100,26 @@ export type AppendToResponseTvEpisodeKey =
|
|||||||
| 'videos'
|
| 'videos'
|
||||||
| 'translations';
|
| 'translations';
|
||||||
|
|
||||||
|
export type AppendToResponseTvSeasonKey =
|
||||||
|
| 'images'
|
||||||
|
| 'credits'
|
||||||
|
| 'external_ids'
|
||||||
|
| 'videos'
|
||||||
|
| 'aggregate_credits'
|
||||||
|
| 'translations';
|
||||||
|
|
||||||
type AppendToResponseAllKeys =
|
type AppendToResponseAllKeys =
|
||||||
| AppendToResponseTvKey
|
| AppendToResponseTvKey
|
||||||
| AppendToResponseMovieKey
|
| AppendToResponseMovieKey
|
||||||
| AppendToResponseTvEpisodeKey
|
| AppendToResponseTvEpisodeKey
|
||||||
|
| AppendToResponseTvSeasonKey
|
||||||
| AppendToResponsePersonKey;
|
| AppendToResponsePersonKey;
|
||||||
|
|
||||||
export type AppendToResponseMediaType =
|
export type AppendToResponseMediaType =
|
||||||
| 'movie'
|
| 'movie'
|
||||||
| 'tvShow'
|
| 'tvShow'
|
||||||
| 'person'
|
| 'person'
|
||||||
|
| 'tvSeason'
|
||||||
| 'tvEpisode';
|
| 'tvEpisode';
|
||||||
|
|
||||||
export type AppendToResponse<
|
export type AppendToResponse<
|
||||||
@@ -153,7 +164,9 @@ export type AppendToResponse<
|
|||||||
? MovieChangeValue
|
? MovieChangeValue
|
||||||
: Media extends 'tvShow'
|
: Media extends 'tvShow'
|
||||||
? TvShowChangeValue
|
? TvShowChangeValue
|
||||||
: TvEpisodeChangeValue
|
: Media extends 'tvSeason'
|
||||||
|
? TvSeasonChangeValue :
|
||||||
|
TvEpisodeChangeValue
|
||||||
>;
|
>;
|
||||||
}
|
}
|
||||||
: object) &
|
: object) &
|
||||||
|
|||||||
23
src/types/tv-seasons.ts
Normal file
23
src/types/tv-seasons.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { Episode } from '.';
|
||||||
|
|
||||||
|
export interface SeasonSelection {
|
||||||
|
tvShowID: number;
|
||||||
|
seasonNumber: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SeasonDetails {
|
||||||
|
air_date: string;
|
||||||
|
episodes: Episode[];
|
||||||
|
name: string;
|
||||||
|
overview: string;
|
||||||
|
id: number;
|
||||||
|
poster_path: string | null;
|
||||||
|
season_number: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TvSeasonChangeValue =
|
||||||
|
| string
|
||||||
|
| {
|
||||||
|
episode_id: number;
|
||||||
|
episode_number: number;
|
||||||
|
};
|
||||||
@@ -93,16 +93,6 @@ export interface TvShowDetails {
|
|||||||
vote_count: number;
|
vote_count: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SeasonDetails {
|
|
||||||
air_date: string;
|
|
||||||
episodes: Episode[];
|
|
||||||
name: string;
|
|
||||||
overview: string;
|
|
||||||
id: number;
|
|
||||||
poster_path: string | null;
|
|
||||||
season_number: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Network {
|
export interface Network {
|
||||||
id: number;
|
id: number;
|
||||||
logo_path: string;
|
logo_path: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user