From ea430efcf5ca2ff4bb1e80270427e4fe1f745af5 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 15:40:22 +0100 Subject: [PATCH 1/9] added keywords endpoint and types --- src/endpoints/index.ts | 1 + src/endpoints/keywords.ts | 20 ++++++++++++++++++++ src/types/index.ts | 1 + src/types/keywords.ts | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/endpoints/keywords.ts create mode 100644 src/types/keywords.ts diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index afa61d5..8f22f9b 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -14,4 +14,5 @@ export * from './people'; export * from './review'; export * from './trending'; export * from './find'; +export * from './keywords'; 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/types/index.ts b/src/types/index.ts index 783be6b..f086a0c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -11,6 +11,7 @@ export * from './discover'; export * from './review'; export * from './trending'; export * from './find'; +export * from './keywords'; export interface AuthorDetails { name: string; diff --git a/src/types/keywords.ts b/src/types/keywords.ts new file mode 100644 index 0000000..9edccd9 --- /dev/null +++ b/src/types/keywords.ts @@ -0,0 +1,19 @@ +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; +} \ No newline at end of file From ca2fa16ad0c032b57abaaeceff3db3b61df7618c Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 15:40:32 +0100 Subject: [PATCH 2/9] refactored Keywords to use Keyword interface --- src/types/credits.ts | 12 +----------- src/types/keywords.ts | 5 +++++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/types/credits.ts b/src/types/credits.ts index 678081d..3eb7a9b 100644 --- a/src/types/credits.ts +++ b/src/types/credits.ts @@ -124,14 +124,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/keywords.ts b/src/types/keywords.ts index 9edccd9..762c2c8 100644 --- a/src/types/keywords.ts +++ b/src/types/keywords.ts @@ -16,4 +16,9 @@ export interface BelongingMovies{ export interface Keyword{ id: number; name: string; +} + +export interface Keywords { + id: number; + keywords: Keyword[]; } \ No newline at end of file From 69e50d0eb9ca3b618a4fa14b26ac7b3ab44da197 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 15:41:11 +0100 Subject: [PATCH 3/9] integrated keywords endpoint with main TMDB class --- src/tmdb.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tmdb.ts b/src/tmdb.ts index eb386a3..5776d8a 100644 --- a/src/tmdb.ts +++ b/src/tmdb.ts @@ -13,6 +13,7 @@ import { ReviewEndpoint, TrendingEndpoint, FindEndpoint, + KeywordsEndpoint, } from './endpoints'; export default class TMDB { @@ -77,4 +78,8 @@ export default class TMDB { get find() : FindEndpoint{ return new FindEndpoint(this.accessToken); } + + get keywords() : KeywordsEndpoint{ + return new KeywordsEndpoint(this.accessToken); + } } From 772b974ae2351f9658fe8cdfa5e09fdac98c05cf Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 16:14:07 +0100 Subject: [PATCH 4/9] added Collection endpoint and types, buildable option interfaces --- src/endpoints/collections.ts | 17 +++++++++++++++++ src/endpoints/index.ts | 1 + src/types/collections.ts | 16 ++++++++++++++++ src/types/index.ts | 9 ++------- src/types/options.ts | 9 +++++++++ 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/endpoints/collections.ts create mode 100644 src/types/collections.ts create mode 100644 src/types/options.ts diff --git a/src/endpoints/collections.ts b/src/endpoints/collections.ts new file mode 100644 index 0000000..eac1121 --- /dev/null +++ b/src/endpoints/collections.ts @@ -0,0 +1,17 @@ +import { DetailedCollection, LanguageOption, PageOption } 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}`); + } + +} \ No newline at end of file diff --git a/src/endpoints/index.ts b/src/endpoints/index.ts index 8f22f9b..e254664 100644 --- a/src/endpoints/index.ts +++ b/src/endpoints/index.ts @@ -15,4 +15,5 @@ export * from './review'; export * from './trending'; export * from './find'; export * from './keywords'; +export * from './collections'; 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/index.ts b/src/types/index.ts index f086a0c..c2330ff 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'; @@ -12,6 +13,7 @@ export * from './review'; export * from './trending'; export * from './find'; export * from './keywords'; +export * from './collections'; export interface AuthorDetails { name: string; @@ -49,13 +51,6 @@ 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; 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; +} From 2315d196db2e1a6d35dfa424e4b7d90d799cd4ad Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 16:15:27 +0100 Subject: [PATCH 5/9] removed unused properties of Movie interface --- src/types/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/types/index.ts b/src/types/index.ts index c2330ff..003d1c8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -53,8 +53,6 @@ export interface Person { export interface Movie { id: number; - logo_path: string; - name: string; poster_path: string; adult: boolean; overview: string; From e19dfc8fda2a0bef43069a8452af06904dbe0464 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 16:23:13 +0100 Subject: [PATCH 6/9] refactored Image types --- src/types/credits.ts | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/types/credits.ts b/src/types/credits.ts index 3eb7a9b..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[]; } From 8649352bf988cf79aded93cc27cb6546809f9497 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 16:30:19 +0100 Subject: [PATCH 7/9] added missing collection endpoints --- src/endpoints/collections.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/endpoints/collections.ts b/src/endpoints/collections.ts index eac1121..0103ceb 100644 --- a/src/endpoints/collections.ts +++ b/src/endpoints/collections.ts @@ -1,4 +1,4 @@ -import { DetailedCollection, LanguageOption, PageOption } from '../types'; +import { DetailedCollection, ImageCollection, LanguageOption, PageOption, Translations } from '../types'; import { BaseEndpoint } from './base'; import querystring from 'querystring'; @@ -14,4 +14,14 @@ export class CollectionsEndpoint extends BaseEndpoint { 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 From 3ac257491df144a7308c58ebfd014a78a444c9b9 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 16:30:41 +0100 Subject: [PATCH 8/9] integrated collections endpoint with main TMDB class --- src/tmdb.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tmdb.ts b/src/tmdb.ts index 5776d8a..73af31a 100644 --- a/src/tmdb.ts +++ b/src/tmdb.ts @@ -14,6 +14,7 @@ import { TrendingEndpoint, FindEndpoint, KeywordsEndpoint, + CollectionsEndpoint, } from './endpoints'; export default class TMDB { @@ -82,4 +83,8 @@ export default class TMDB { get keywords() : KeywordsEndpoint{ return new KeywordsEndpoint(this.accessToken); } + + get collections() : CollectionsEndpoint{ + return new CollectionsEndpoint(this.accessToken); + } } From 82f84f4b6847a282afe65958b6c4b61400f3eed3 Mon Sep 17 00:00:00 2001 From: DerPenz Date: Fri, 10 Mar 2023 14:30:48 +0100 Subject: [PATCH 9/9] fixed styling and import --- src/endpoints/collections.ts | 2 +- src/types/keywords.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/endpoints/collections.ts b/src/endpoints/collections.ts index 0103ceb..386fb6d 100644 --- a/src/endpoints/collections.ts +++ b/src/endpoints/collections.ts @@ -1,4 +1,4 @@ -import { DetailedCollection, ImageCollection, LanguageOption, PageOption, Translations } from '../types'; +import { DetailedCollection, ImageCollection, LanguageOption, Translations } from '../types'; import { BaseEndpoint } from './base'; import querystring from 'querystring'; diff --git a/src/types/keywords.ts b/src/types/keywords.ts index 762c2c8..f820bed 100644 --- a/src/types/keywords.ts +++ b/src/types/keywords.ts @@ -2,15 +2,15 @@ import { ParsedUrlQueryInput } from 'querystring'; import { Movie } from '.'; export interface KeywordsOptions extends ParsedUrlQueryInput { - include_adult?: boolean; - language?: string; + include_adult?: boolean; + language?: string; } export interface BelongingMovies{ page: number; - results: Movie[]; - total_results: number; - total_pages: number; + results: Movie[]; + total_results: number; + total_pages: number; } export interface Keyword{