From 772b974ae2351f9658fe8cdfa5e09fdac98c05cf Mon Sep 17 00:00:00 2001 From: DerPenz Date: Mon, 27 Feb 2023 16:14:07 +0100 Subject: [PATCH] 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; +}