diff --git a/src/endpoints/collections.ts b/src/endpoints/collections.ts new file mode 100644 index 0000000..386fb6d --- /dev/null +++ b/src/endpoints/collections.ts @@ -0,0 +1,27 @@ +import { DetailedCollection, ImageCollection, LanguageOption, Translations } from '../types'; +import { BaseEndpoint } from './base'; +import querystring from 'querystring'; + +const BASE_COLLECTION = '/collection'; + +export class CollectionsEndpoint extends BaseEndpoint { + constructor(protected readonly accessToken: string) { + super(accessToken); + } + + async details(id: number, options? : LanguageOption): Promise { + const params = querystring.encode(options); + return await this.api.get(`${BASE_COLLECTION}/${id}?${params}`); + } + + async images(id: number, options? : LanguageOption): Promise { + const params = querystring.encode(options); + return await this.api.get(`${BASE_COLLECTION}/${id}/images?${params}`); + } + + async translations(id: number, options? : LanguageOption): Promise { + const params = querystring.encode(options); + return await this.api.get(`${BASE_COLLECTION}/${id}/translations?${params}`); + } + +} \ No newline at end of file diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index afa61d5..e254664 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -14,4 +14,6 @@ export * from './people'; export * from './review'; export * from './trending'; export * from './find'; +export * from './keywords'; +export * from './collections'; diff --git a/src/endpoints/keywords.ts b/src/endpoints/keywords.ts new file mode 100644 index 0000000..818189e --- /dev/null +++ b/src/endpoints/keywords.ts @@ -0,0 +1,20 @@ +import { BaseEndpoint } from './base'; +import querystring from 'querystring'; +import { BelongingMovies, Keyword, KeywordsOptions } from '../types'; + +const BASE_Keyword = '/keyword'; + +export class KeywordsEndpoint extends BaseEndpoint { + constructor(accessToken: string) { + super(accessToken); + } + + async details(keywordId : number): Promise { + return await this.api.get(`${BASE_Keyword}/${keywordId}`); + } + + async belongingMovies(keywordId : number, options?: KeywordsOptions): Promise { + const params = querystring.encode(options); + return await this.api.get(`${BASE_Keyword}/${keywordId}/movies?${params}`); + } +} diff --git a/src/tmdb.ts b/src/tmdb.ts index eb386a3..73af31a 100644 --- a/src/tmdb.ts +++ b/src/tmdb.ts @@ -13,6 +13,8 @@ import { ReviewEndpoint, TrendingEndpoint, FindEndpoint, + KeywordsEndpoint, + CollectionsEndpoint, } from './endpoints'; export default class TMDB { @@ -77,4 +79,12 @@ export default class TMDB { get find() : FindEndpoint{ return new FindEndpoint(this.accessToken); } + + get keywords() : KeywordsEndpoint{ + return new KeywordsEndpoint(this.accessToken); + } + + get collections() : CollectionsEndpoint{ + return new CollectionsEndpoint(this.accessToken); + } } diff --git a/src/types/collections.ts b/src/types/collections.ts new file mode 100644 index 0000000..bffdc50 --- /dev/null +++ b/src/types/collections.ts @@ -0,0 +1,16 @@ +import { Movie } from "."; + +export interface Collection { + id: number; + backdrop_path: string; + name: string; + poster_path: string; + adult: boolean; + original_language: string; + original_name: string; + overview: string; +} + +export interface DetailedCollection extends Collection { + parts: Movie[] +} diff --git a/src/types/credits.ts b/src/types/credits.ts index 678081d..9eaebb4 100644 --- a/src/types/credits.ts +++ b/src/types/credits.ts @@ -1,4 +1,4 @@ -import { Person } from './'; +import { Image, Person } from './'; export interface CreditSeason { air_date?: string; @@ -82,31 +82,10 @@ export interface Credits { crew: Crew[]; } - -export interface Backdrop { - aspect_ratio: number; - file_path: string; - height: number; - iso_639_1?: any; - vote_average: number; - vote_count: number; - width: number; -} - -export interface Poster { - aspect_ratio: number; - file_path: string; - height: number; - iso_639_1: string; - vote_average: number; - vote_count: number; - width: number; -} - -export interface CreditImages { +export interface ImageCollection { id: number; - backdrops: Backdrop[]; - posters: Poster[]; + backdrops: Image[]; + posters: Image[]; } @@ -124,14 +103,4 @@ export interface Video { export interface Videos { id: number; results: Video[]; -} - -export interface Keywords { - id: number; - keywords: Array<{ - id: number; - name: string; - }> - -} - +} \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index 783be6b..003d1c8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,4 @@ +export * from './options'; export * from './certification'; export * from './credits'; export * from './configuration'; @@ -11,6 +12,8 @@ export * from './discover'; export * from './review'; export * from './trending'; export * from './find'; +export * from './keywords'; +export * from './collections'; export interface AuthorDetails { name: string; @@ -48,17 +51,8 @@ export interface Person { popularity: number; } -export interface Collection { - id:number; - backdrop_path: string; - name: string; - poster_path: string; -} - export interface Movie { id: number; - logo_path: string; - name: string; poster_path: string; adult: boolean; overview: string; diff --git a/src/types/keywords.ts b/src/types/keywords.ts new file mode 100644 index 0000000..f820bed --- /dev/null +++ b/src/types/keywords.ts @@ -0,0 +1,24 @@ +import { ParsedUrlQueryInput } from 'querystring'; +import { Movie } from '.'; + +export interface KeywordsOptions extends ParsedUrlQueryInput { + include_adult?: boolean; + language?: string; +} + +export interface BelongingMovies{ + page: number; + results: Movie[]; + total_results: number; + total_pages: number; +} + +export interface Keyword{ + id: number; + name: string; +} + +export interface Keywords { + id: number; + keywords: Keyword[]; +} \ No newline at end of file diff --git a/src/types/options.ts b/src/types/options.ts new file mode 100644 index 0000000..2f30fb4 --- /dev/null +++ b/src/types/options.ts @@ -0,0 +1,9 @@ +import { ParsedUrlQueryInput } from 'querystring'; + +export interface LanguageOption extends ParsedUrlQueryInput { + language?: string; +} + +export interface PageOption extends ParsedUrlQueryInput { + page?: number; +}