Merge pull request #12 from Der-Penz/keywords-collections-endpoint

Add keywords, collections endpoint
This commit is contained in:
Blake
2023-03-29 07:55:38 -04:00
committed by GitHub
9 changed files with 116 additions and 45 deletions

View File

@@ -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<DetailedCollection> {
const params = querystring.encode(options);
return await this.api.get<DetailedCollection>(`${BASE_COLLECTION}/${id}?${params}`);
}
async images(id: number, options? : LanguageOption): Promise<ImageCollection> {
const params = querystring.encode(options);
return await this.api.get<ImageCollection>(`${BASE_COLLECTION}/${id}/images?${params}`);
}
async translations(id: number, options? : LanguageOption): Promise<Translations> {
const params = querystring.encode(options);
return await this.api.get<Translations>(`${BASE_COLLECTION}/${id}/translations?${params}`);
}
}

View File

@@ -14,4 +14,6 @@ export * from './people';
export * from './review';
export * from './trending';
export * from './find';
export * from './keywords';
export * from './collections';

20
src/endpoints/keywords.ts Normal file
View File

@@ -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<Keyword> {
return await this.api.get<Keyword>(`${BASE_Keyword}/${keywordId}`);
}
async belongingMovies(keywordId : number, options?: KeywordsOptions): Promise<BelongingMovies> {
const params = querystring.encode(options);
return await this.api.get<BelongingMovies>(`${BASE_Keyword}/${keywordId}/movies?${params}`);
}
}

View File

@@ -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);
}
}

16
src/types/collections.ts Normal file
View File

@@ -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[]
}

View File

@@ -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;
}>
}
}

View File

@@ -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;

24
src/types/keywords.ts Normal file
View File

@@ -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[];
}

9
src/types/options.ts Normal file
View File

@@ -0,0 +1,9 @@
import { ParsedUrlQueryInput } from 'querystring';
export interface LanguageOption extends ParsedUrlQueryInput {
language?: string;
}
export interface PageOption extends ParsedUrlQueryInput {
page?: number;
}