initial commit

This commit is contained in:
Blake Joynes
2021-05-15 00:22:10 -04:00
commit d800f56ee6
20 changed files with 697 additions and 0 deletions

22
src/api.ts Normal file
View File

@@ -0,0 +1,22 @@
import fetch from 'node-fetch';
const BASE_URL_V3 = 'https://api.themoviedb.org/3'
export class Api{
constructor(private accessToken: string){
this.accessToken = accessToken
}
async get<T>(path: string): Promise<T> {
const response = await fetch(`${BASE_URL_V3}${path}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${this.accessToken}`,
'Content-Type': 'application/json;charset=utf-8'
},
});
return await response.json() as T;
}
}

6
src/config.ts Normal file
View File

@@ -0,0 +1,6 @@
require('dotenv').config()
export class config {
static accessToken = process.env.ACCESS_TOKEN;
}

17
src/endpoints/account.ts Normal file
View File

@@ -0,0 +1,17 @@
import { Api } from "../api";
import {Base} from "./base";
export class Account extends Base{
constructor(accessToken: string){
super(accessToken);
}
async details(): Promise<any> {
return await this.api.get('/account');
}
}

12
src/endpoints/base.ts Normal file
View File

@@ -0,0 +1,12 @@
import {Api} from "../api";
export class Base {
protected api: Api;
constructor(protected readonly accessToken: string){
this.api = new Api(accessToken);
}
}

View File

@@ -0,0 +1,20 @@
import {Base} from "./base";
import {Certifications} from "../types/certification";
export class Certification extends Base{
constructor(protected readonly accessToken: string){
super(accessToken);
}
async movies(): Promise<Certifications> {
return await this.api.get<Certifications>('/certification/movie/list');
}
async tvShows(): Promise<Certifications> {
return await this.api.get<Certifications>('/certification/tv/list');
}
}

35
src/endpoints/changes.ts Normal file
View File

@@ -0,0 +1,35 @@
import querystring, {ParsedUrlQueryInput} from 'querystring';
import {Base} from "./base";
import {Changes} from "../types/changes";
export interface ChangeOptions extends ParsedUrlQueryInput {
end_date?: string;
start_date?: string;
page?: number;
}
export class Change extends Base{
constructor(protected readonly accessToken: string){
super(accessToken);
}
async movies(options?: ChangeOptions): Promise<Changes> {
const params = querystring.encode(options);
return await this.api.get<Changes>(`/movie/changes?${params}`);
}
async tvShows(options?: ChangeOptions): Promise<Changes> {
const params = querystring.stringify(options);
return await this.api.get<Changes>(`/tv/changes?${params}`);
}
async person(options?: ChangeOptions): Promise<Changes> {
const params = querystring.stringify(options);
return await this.api.get<Changes>(`/person/changes${params}`);
}
}

0
src/index.ts Normal file
View File

41
src/tmdb.ts Normal file
View File

@@ -0,0 +1,41 @@
import { Account } from "./endpoints/account";
import {config} from "./config";
import fetch from "node-fetch";
import {Certification} from "./endpoints/certification";
import {Change} from "./endpoints/changes";
export class TMDB {
private accessToken: string;
constructor(accessToken: string){
this.accessToken = accessToken;
}
get account(){
return new Account(this.accessToken);
}
get certifications(){
return new Certification(this.accessToken);
}
get changes(){
return new Change(this.accessToken);
}
}
const tmdb = new TMDB(config.accessToken!);
(async () => {
const changes = await tmdb.changes.movies()
console.log(changes);
})()

20
src/types/certification.d.ts vendored Normal file
View File

@@ -0,0 +1,20 @@
export interface Certifications {
certifications: {
US: Certification[],
CA: Certification[],
DE: Certification[],
GB: Certification[],
AU: Certification[],
BR: Certification[],
FR: Certification[],
NZ: Certification[],
IN: Certification[],
}
}
export interface Certification {
certification: string;
meaning: string;
order: number;
}

11
src/types/changes.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
export interface Changes{
results: Change[];
page: number;
total_pages: nubmer;
total_results: number;
}
export interface Change {
id: number;
adult: boolean | undefined;
}

0
src/types/index.d.ts vendored Normal file
View File