update readme, started movie endpoints

This commit is contained in:
Blake Joynes
2021-05-15 11:44:02 -04:00
parent 92f84a31f3
commit 9937277752
8 changed files with 128 additions and 5 deletions

View File

@@ -4,4 +4,14 @@
Typescript library wrapper of [TMDB API](https://developers.themoviedb.org/) v3 . Typescript library wrapper of [TMDB API](https://developers.themoviedb.org/) v3 .
This uses authentication token for requests so there is no need to append api key to the url. This uses new jwt authentication token for requests so there is no need to append api key to the url.
Once you have registered for access to the api you can use your access token as follows:
`import TMDB from 'tmdb-ts';`
`const tmdb = new TMDB(accessToken);`
`tmdb.search.movies({query: 'American Pie'})`

19
src/endpoints/genre.ts Normal file
View File

@@ -0,0 +1,19 @@
import { BaseEndpoint } from './base';
export interface Genres {
genres: Array<{id: number, name: string}>
}
export class GenreEndpoint extends BaseEndpoint {
constructor(protected readonly accessToken: string) {
super(accessToken);
}
async movies(): Promise<Genres> {
return await this.api.get<Genres>('/genre/movie/list');
}
async tvShows(): Promise<Genres> {
return await this.api.get<Genres>('/genre/tv/list');
}
}

View File

@@ -5,3 +5,5 @@ export * from './certification';
export * from './changes'; export * from './changes';
export * from './credits'; export * from './credits';
export * from './search'; export * from './search';
export * from './genre';
export * from './movies';

19
src/endpoints/movies.ts Normal file
View File

@@ -0,0 +1,19 @@
import { BaseEndpoint } from './base';
import { AlternativeTitles, MovieDetails } from '../types/movie';
const BASE_MOVIE = '/movie';
export class MoviesEndpoint extends BaseEndpoint{
constructor(protected readonly accessToken: string) {
super(accessToken);
}
async details(id: number): Promise<MovieDetails>{
return await this.api.get<MovieDetails>(`${BASE_MOVIE}/${id}`);
}
async alternativeTitles(id: number): Promise<AlternativeTitles>{
return await this.api.get<AlternativeTitles>(`${BASE_MOVIE}/${id}/alternative_titles`);
}
}

View File

@@ -3,6 +3,8 @@ import {
CertificationEndpoint, CertificationEndpoint,
ChangeEndpoint, ChangeEndpoint,
CreditsEndpoint, CreditsEndpoint,
GenreEndpoint,
MoviesEndpoint,
SearchEndpoint, SearchEndpoint,
} from './endpoints'; } from './endpoints';
@@ -28,8 +30,16 @@ export default class TMDB {
get credits(): CreditsEndpoint { get credits(): CreditsEndpoint {
return new CreditsEndpoint(this.accessToken); return new CreditsEndpoint(this.accessToken);
} }
get search(): SearchEndpoint{ get search(): SearchEndpoint{
return new SearchEndpoint(this.accessToken); return new SearchEndpoint(this.accessToken);
} }
get genres(): GenreEndpoint{
return new GenreEndpoint(this.accessToken);
}
get movies(): MoviesEndpoint{
return new MoviesEndpoint(this.accessToken);
}
} }

11
src/types/index.d.ts vendored
View File

@@ -1,6 +1,7 @@
import * as certs from './certification'; export * from './certification';
import * as credits from './credits'; export * from './credits';
import * as changes from './changes'; export * from './changes';
export interface KnownFor { export interface KnownFor {
id: number; id: number;
@@ -80,6 +81,10 @@ export interface TV {
vote_average: number; vote_average: number;
} }
export interface Genre {
id: number;
name: string;
}
export { export {
certs, certs,

58
src/types/movie.d.ts vendored Normal file
View File

@@ -0,0 +1,58 @@
import { Genre } from './index';
export interface ProductionCompany {
id: number;
logo_path: string;
name: string;
origin_country: string;
}
export interface ProductionCountry {
iso_3166_1: string;
name: string;
}
export interface SpokenLanguage {
iso_639_1: string;
name: string;
}
export interface MovieDetails {
adult: boolean;
backdrop_path: string;
belongs_to_collection?: any;
budget: number;
genres: Genre[];
homepage: string;
id: number;
imdb_id: string;
original_language: string;
original_title: string;
overview: string;
popularity: number;
poster_path?: any;
production_companies: ProductionCompany[];
production_countries: ProductionCountry[];
release_date: string;
revenue: number;
runtime: number;
spoken_languages: SpokenLanguage[];
status: string;
tagline: string;
title: string;
video: boolean;
vote_average: number;
vote_count: number;
}
export interface Title {
iso_3166_1: string;
title: string;
type: string;
}
export interface AlternativeTitles {
id: number;
titles: Title[];
}