8 Commits

Author SHA1 Message Date
Blake
c56ecbef47 Update package.json 2024-03-10 14:23:57 -04:00
Blake
876d2cac0f Merge pull request #49 from pypp/feat/undocumented-backdrop-size
Add w500 size to backdrop
2024-03-10 04:10:01 -04:00
Blake
9dae7144b2 Merge pull request #50 from pypp/feat/trending-page-options
Add pageOption to the trending endpoint
2024-03-10 04:09:51 -04:00
Netanel Henya
f99dbac1d2 feat: add pageOption to the trending endpoint 2024-02-23 11:36:05 +02:00
Netanel Henya
43f5d16dc3 feat: added w500 size to backdrop, this size is not in the officel documentation but it still exists 2024-02-23 08:16:29 +02:00
Blake
682cf48cb0 Merge pull request #48 from blakejoy/chore/add-error-res
Feat: Add error response.
2024-01-15 12:02:07 -05:00
Blake Joynes
1146ca8ad2 add error. linting 2024-01-15 11:59:48 -05:00
Blake
6a68e9973b Merge pull request #46 from blakejoy/chore/v1.6
Update package.json
2023-12-28 21:32:30 -05:00
15 changed files with 138 additions and 41 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "tmdb-ts",
"version": "1.5.0",
"version": "1.6.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "tmdb-ts",
"version": "1.5.0",
"version": "1.6.1",
"license": "MIT",
"dependencies": {
"cross-fetch": "^3.1.4"

View File

@@ -1,6 +1,6 @@
{
"name": "tmdb-ts",
"version": "1.6.0",
"version": "1.7.0",
"description": "TMDB v3 library wrapper",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@@ -1,5 +1,6 @@
import fetch from 'cross-fetch';
import { parseOptions } from './utils';
import { ErrorResponse } from './types';
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
@@ -17,6 +18,11 @@ export class Api {
'Content-Type': 'application/json;charset=utf-8',
},
});
if (!response.ok) {
return Promise.reject((await response.json()) as ErrorResponse);
}
return (await response.json()) as T;
}
}

View File

@@ -24,7 +24,10 @@ export class CollectionsEndpoint extends BaseEndpoint {
);
}
async images(id: number, options?: CollectionImageOptions): Promise<ImageCollection> {
async images(
id: number,
options?: CollectionImageOptions
): Promise<ImageCollection> {
const computedOptions = {
include_image_language: options?.include_image_language?.join(','),
language: options?.language,

View File

@@ -35,7 +35,7 @@ export interface MoviesImageSearchOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_image_language?: string[],
include_image_language?: string[];
}
export class MoviesEndpoint extends BaseEndpoint {
@@ -85,12 +85,18 @@ export class MoviesEndpoint extends BaseEndpoint {
return await this.api.get<ExternalIds>(`${BASE_MOVIE}/${id}/external_ids`);
}
async images(id: number, options?: MoviesImageSearchOptions): Promise<Images> {
async images(
id: number,
options?: MoviesImageSearchOptions
): Promise<Images> {
const computedOptions = {
include_image_language: options?.include_image_language?.join(','),
language: options?.language,
};
return await this.api.get<Images>(`${BASE_MOVIE}/${id}/images`, computedOptions);
return await this.api.get<Images>(
`${BASE_MOVIE}/${id}/images`,
computedOptions
);
}
async keywords(id: number): Promise<Keywords> {
@@ -120,11 +126,17 @@ export class MoviesEndpoint extends BaseEndpoint {
);
}
async reviews(id: number, options?: LanguageOption & PageOption): Promise<Reviews> {
async reviews(
id: number,
options?: LanguageOption & PageOption
): Promise<Reviews> {
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews`, options);
}
async similar(id: number, options?: LanguageOption & PageOption): Promise<SimilarMovies> {
async similar(
id: number,
options?: LanguageOption & PageOption
): Promise<SimilarMovies> {
return await this.api.get<SimilarMovies>(
`${BASE_MOVIE}/${id}/similar`,
options

View File

@@ -34,7 +34,7 @@ export class PeopleEndpoint extends BaseEndpoint {
append_to_response: appendToResponse
? appendToResponse.join(',')
: undefined,
language: language
language: language,
};
return await this.api.get<AppendToResponse<PersonDetails, T, 'person'>>(
`${BASE_PERSON}/${id}`,
@@ -52,21 +52,30 @@ export class PeopleEndpoint extends BaseEndpoint {
);
}
async movieCredits(id: number, options?: LanguageOption): Promise<PersonMovieCredit> {
async movieCredits(
id: number,
options?: LanguageOption
): Promise<PersonMovieCredit> {
return await this.api.get<PersonMovieCredit>(
`${BASE_PERSON}/${id}/movie_credits`,
options
);
}
async tvShowCredits(id: number, options?: LanguageOption): Promise<PersonTvShowCredit> {
async tvShowCredits(
id: number,
options?: LanguageOption
): Promise<PersonTvShowCredit> {
return await this.api.get<PersonTvShowCredit>(
`${BASE_PERSON}/${id}/tv_credits`,
options
);
}
async combinedCredits(id: number, options?: LanguageOption): Promise<PersonCombinedCredits> {
async combinedCredits(
id: number,
options?: LanguageOption
): Promise<PersonCombinedCredits> {
return await this.api.get<PersonCombinedCredits>(
`${BASE_PERSON}/${id}/combined_credits`,
options
@@ -98,7 +107,9 @@ export class PeopleEndpoint extends BaseEndpoint {
return await this.api.get<PersonDetails>(`${BASE_PERSON}/latest`);
}
async popular(options?: LanguageOption & PageOption): Promise<PopularPersons> {
async popular(
options?: LanguageOption & PageOption
): Promise<PopularPersons> {
return await this.api.get<PopularPersons>(
`${BASE_PERSON}/popular`,
options

View File

@@ -1,6 +1,15 @@
import { BaseEndpoint } from './base';
import { MultiSearchResult, Search } from '../types/search';
import { Collection, Company, LanguageOption, Movie, PageOption, Person, RegionOption, TV } from '../types';
import {
Collection,
Company,
LanguageOption,
Movie,
PageOption,
Person,
RegionOption,
TV,
} from '../types';
const BASE_SEARCH = '/search';
@@ -9,27 +18,44 @@ export interface SearchOptions {
page?: number;
}
export interface MovieSearchOptions extends SearchOptions, LanguageOption, PageOption, RegionOption {
export interface MovieSearchOptions
extends SearchOptions,
LanguageOption,
PageOption,
RegionOption {
include_adult?: boolean;
year?: number;
primary_release_year?: number;
}
export interface CollectionSearchOptions extends SearchOptions, LanguageOption, PageOption, RegionOption {
export interface CollectionSearchOptions
extends SearchOptions,
LanguageOption,
PageOption,
RegionOption {
include_adult?: boolean;
}
export interface TvSearchOptions extends SearchOptions, LanguageOption, PageOption {
export interface TvSearchOptions
extends SearchOptions,
LanguageOption,
PageOption {
include_adult?: boolean;
year?: number;
first_air_date_year?: number;
}
export interface PeopleSearchOptions extends SearchOptions, LanguageOption, PageOption {
export interface PeopleSearchOptions
extends SearchOptions,
LanguageOption,
PageOption {
include_adult?: boolean;
}
export interface MultiSearchOptions extends SearchOptions, LanguageOption, PageOption {
export interface MultiSearchOptions
extends SearchOptions,
LanguageOption,
PageOption {
include_adult?: boolean;
}

View File

@@ -1,4 +1,10 @@
import { TrendingMediaType, TimeWindow, TrendingResults, LanguageOption } from '../types';
import {
TrendingMediaType,
TimeWindow,
TrendingResults,
LanguageOption,
PageOption,
} from '../types';
import { BaseEndpoint } from './base';
export class TrendingEndpoint extends BaseEndpoint {
@@ -9,7 +15,7 @@ export class TrendingEndpoint extends BaseEndpoint {
async trending<T extends TrendingMediaType>(
mediaType: T,
timeWindow: TimeWindow,
options?: LanguageOption
options?: LanguageOption & PageOption
): Promise<TrendingResults<T>> {
return await this.api.get<TrendingResults<T>>(
`/trending/${mediaType}/${timeWindow}`,

View File

@@ -8,7 +8,6 @@ import {
Images,
TvEpisodeTranslations,
Videos,
AppendToResponseMovieKey,
AppendToResponse,
Changes,
TvEpisodeChangeValue,
@@ -24,14 +23,14 @@ export interface TvEpisodeImageSearchOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_image_language?: string[],
include_image_language?: string[];
}
export interface TvEpisodeVideoSearchOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_video_language?: string[],
include_video_language?: string[];
}
export class TvEpisodesEndpoint extends BaseEndpoint {
@@ -76,7 +75,10 @@ export class TvEpisodesEndpoint extends BaseEndpoint {
);
}
async images(episodeSelection: EpisodeSelection, options?: TvEpisodeImageSearchOptions) {
async images(
episodeSelection: EpisodeSelection,
options?: TvEpisodeImageSearchOptions
) {
const computedOptions = {
include_image_language: options?.include_image_language?.join(','),
language: options?.language,
@@ -93,7 +95,10 @@ export class TvEpisodesEndpoint extends BaseEndpoint {
);
}
async videos(episodeSelection: EpisodeSelection, options?: TvEpisodeVideoSearchOptions) {
async videos(
episodeSelection: EpisodeSelection,
options?: TvEpisodeVideoSearchOptions
) {
const computedOptions = {
include_video_language: options?.include_video_language?.join(','),
language: options?.language,

View File

@@ -24,14 +24,14 @@ export interface TvSeasonImageSearchOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_image_language?: string[],
include_image_language?: string[];
}
export interface TvSeasonVideoSearchOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_video_language?: string[],
include_video_language?: string[];
}
export class TvSeasonsEndpoint extends BaseEndpoint {
@@ -91,7 +91,10 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
);
}
async images(seasonSelection: SeasonSelection, options?: TvSeasonImageSearchOptions) {
async images(
seasonSelection: SeasonSelection,
options?: TvSeasonImageSearchOptions
) {
const computedOptions = {
include_image_language: options?.include_image_language?.join(','),
language: options?.language,
@@ -102,7 +105,10 @@ export class TvSeasonsEndpoint extends BaseEndpoint {
);
}
async videos(seasonSelection: SeasonSelection, options?: TvSeasonVideoSearchOptions) {
async videos(
seasonSelection: SeasonSelection,
options?: TvSeasonVideoSearchOptions
) {
const computedOptions = {
include_video_language: options?.include_video_language?.join(','),
language: options?.language,

View File

@@ -80,7 +80,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
);
}
async aggregateCredits(id: number, options?: LanguageOption): Promise<AggregateCredits> {
async aggregateCredits(
id: number,
options?: LanguageOption
): Promise<AggregateCredits> {
return await this.api.get<AggregateCredits>(
`${BASE_TV}/${id}/aggregate_credits`,
options
@@ -110,7 +113,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
include_image_language: options?.include_image_language?.join(','),
language: options?.language,
};
return await this.api.get<Images>(`${BASE_TV}/${id}/images`, computedOptions);
return await this.api.get<Images>(
`${BASE_TV}/${id}/images`,
computedOptions
);
}
async keywords(id: number): Promise<Keywords> {
@@ -127,7 +133,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
);
}
async reviews(id: number, options?: LanguageOption & PageOption): Promise<Reviews> {
async reviews(
id: number,
options?: LanguageOption & PageOption
): Promise<Reviews> {
return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews`, options);
}
@@ -137,7 +146,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
);
}
async similar(id: number, options?: LanguageOption & PageOption): Promise<SimilarTvShows> {
async similar(
id: number,
options?: LanguageOption & PageOption
): Promise<SimilarTvShows> {
return await this.api.get<SimilarTvShows>(
`${BASE_TV}/${id}/similar`,
options
@@ -153,7 +165,10 @@ export class TvShowsEndpoint extends BaseEndpoint {
include_video_language: options?.include_video_language?.join(','),
language: options?.language,
};
return await this.api.get<Videos>(`${BASE_TV}/${id}/videos`, computedOptions);
return await this.api.get<Videos>(
`${BASE_TV}/${id}/videos`,
computedOptions
);
}
/**

View File

@@ -19,5 +19,5 @@ export interface CollectionImageOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_image_language?: string[],
}
include_image_language?: string[];
}

View File

@@ -15,6 +15,7 @@ export interface Configuration {
export const enum BackdropSizes {
W300 = 'w300',
W500 = 'w500',
W780 = 'w780',
W1280 = 'w1280',
ORIGINAL = 'original',

View File

@@ -19,6 +19,12 @@ export * from './collections';
export * from './tv-episode';
export * from './tv-seasons';
export interface ErrorResponse {
status_code: number;
status_message: string;
success: boolean;
}
export type MediaType = 'movie' | 'tv' | 'person';
export interface AuthorDetails {

View File

@@ -279,12 +279,12 @@ export interface TvShowImageOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_image_language?: string[],
include_image_language?: string[];
}
export interface TvShowVideoOptions extends LanguageOption {
/**
* a list of ISO-639-1 values to query
*/
include_video_language?: string[],
}
include_video_language?: string[];
}