update readme, started movie endpoints
This commit is contained in:
12
README.md
12
README.md
@@ -4,4 +4,14 @@
|
||||
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'})`
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseEndpoint } from './base';
|
||||
import { BaseEndpoint } from './base';
|
||||
import { Certifications } from '../types/certification';
|
||||
|
||||
export class CertificationEndpoint extends BaseEndpoint {
|
||||
|
||||
19
src/endpoints/genre.ts
Normal file
19
src/endpoints/genre.ts
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,5 @@ export * from './certification';
|
||||
export * from './changes';
|
||||
export * from './credits';
|
||||
export * from './search';
|
||||
export * from './genre';
|
||||
export * from './movies';
|
||||
|
||||
19
src/endpoints/movies.ts
Normal file
19
src/endpoints/movies.ts
Normal 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`);
|
||||
}
|
||||
|
||||
}
|
||||
10
src/tmdb.ts
10
src/tmdb.ts
@@ -3,6 +3,8 @@ import {
|
||||
CertificationEndpoint,
|
||||
ChangeEndpoint,
|
||||
CreditsEndpoint,
|
||||
GenreEndpoint,
|
||||
MoviesEndpoint,
|
||||
SearchEndpoint,
|
||||
} from './endpoints';
|
||||
|
||||
@@ -28,8 +30,16 @@ export default class TMDB {
|
||||
get credits(): CreditsEndpoint {
|
||||
return new CreditsEndpoint(this.accessToken);
|
||||
}
|
||||
|
||||
get search(): SearchEndpoint{
|
||||
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
11
src/types/index.d.ts
vendored
@@ -1,6 +1,7 @@
|
||||
import * as certs from './certification';
|
||||
import * as credits from './credits';
|
||||
import * as changes from './changes';
|
||||
export * from './certification';
|
||||
export * from './credits';
|
||||
export * from './changes';
|
||||
|
||||
|
||||
export interface KnownFor {
|
||||
id: number;
|
||||
@@ -80,6 +81,10 @@ export interface TV {
|
||||
vote_average: number;
|
||||
}
|
||||
|
||||
export interface Genre {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export {
|
||||
certs,
|
||||
|
||||
58
src/types/movie.d.ts
vendored
Normal file
58
src/types/movie.d.ts
vendored
Normal 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[];
|
||||
}
|
||||
Reference in New Issue
Block a user