add changes, credits, search
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import { Api } from "../api";
|
||||
import {Base} from "./base";
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
export class AccountEndpoint extends BaseEndpoint {
|
||||
constructor(accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
|
||||
export class Account extends Base{
|
||||
|
||||
constructor(accessToken: string){
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
|
||||
async details(): Promise<any> {
|
||||
return await this.api.get('/account');
|
||||
|
||||
}
|
||||
async details(): Promise<any> {
|
||||
return await this.api.get('/account');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import {Api} from "../api";
|
||||
import Api from '../api';
|
||||
|
||||
export class BaseEndpoint {
|
||||
protected api: Api;
|
||||
|
||||
export class Base {
|
||||
protected api: Api;
|
||||
|
||||
|
||||
constructor(protected readonly accessToken: string){
|
||||
this.api = new Api(accessToken);
|
||||
}
|
||||
|
||||
constructor(protected readonly accessToken: string) {
|
||||
this.api = new Api(accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
import {Base} from "./base";
|
||||
import {Certifications} from "../types/certification";
|
||||
import { BaseEndpoint } from './base';
|
||||
import { Certifications } from '../types/certification';
|
||||
|
||||
export class CertificationEndpoint extends BaseEndpoint {
|
||||
constructor(protected readonly accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
export class Certification extends Base{
|
||||
async movies(): Promise<Certifications> {
|
||||
return await this.api.get<Certifications>('/certification/movie/list');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
async tvShows(): Promise<Certifications> {
|
||||
return await this.api.get<Certifications>('/certification/tv/list');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,31 @@
|
||||
import querystring, {ParsedUrlQueryInput} from 'querystring';
|
||||
import {Base} from "./base";
|
||||
import {Changes} from "../types/changes";
|
||||
|
||||
import querystring, { ParsedUrlQueryInput } from 'querystring';
|
||||
import { BaseEndpoint } from './base';
|
||||
import { Changes } from '../types/changes';
|
||||
|
||||
export interface ChangeOptions extends ParsedUrlQueryInput {
|
||||
end_date?: string;
|
||||
start_date?: string;
|
||||
page?: number;
|
||||
end_date?: string;
|
||||
start_date?: string;
|
||||
page?: number;
|
||||
}
|
||||
|
||||
export class Change extends Base{
|
||||
export class ChangeEndpoint extends BaseEndpoint {
|
||||
constructor(protected readonly accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
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 movies(options?: ChangeOptions): Promise<Changes> {
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Changes>(`/movie/changes?${params}`);
|
||||
async person(options?: ChangeOptions): Promise<Changes> {
|
||||
const params = querystring.stringify(options);
|
||||
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
return await this.api.get<Changes>(`/person/changes${params}`);
|
||||
}
|
||||
}
|
||||
|
||||
14
src/endpoints/credits.ts
Normal file
14
src/endpoints/credits.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { BaseEndpoint } from './base';
|
||||
import { CreditResponse } from '../types/credits';
|
||||
|
||||
|
||||
export class CreditsEndpoint extends BaseEndpoint {
|
||||
constructor(protected readonly accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async getById(id: string): Promise<CreditResponse> {
|
||||
return await this.api.get<CreditResponse>(`/credit/${id}`);
|
||||
}
|
||||
|
||||
}
|
||||
7
src/endpoints/index.ts
Normal file
7
src/endpoints/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
export * from './account';
|
||||
export * from './certification';
|
||||
export * from './changes';
|
||||
export * from './credits';
|
||||
export * from './search';
|
||||
65
src/endpoints/search.ts
Normal file
65
src/endpoints/search.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { BaseEndpoint } from './base';
|
||||
import querystring, { ParsedUrlQueryInput } from 'querystring';
|
||||
import { Search } from '../types/search';
|
||||
import { Collection, Company, Movie, Person, TV } from '../types';
|
||||
|
||||
const BASE_SEARCH = '/search';
|
||||
|
||||
export interface SearchOptions extends ParsedUrlQueryInput {
|
||||
query: string;
|
||||
page?: number;
|
||||
}
|
||||
|
||||
export interface MovieSearchOptions extends SearchOptions {
|
||||
include_adult?: boolean;
|
||||
year?: number;
|
||||
primary_release_year?: number;
|
||||
}
|
||||
|
||||
export interface TvSearchOptions extends SearchOptions{
|
||||
include_adult?: boolean;
|
||||
first_air_date_year?: number;
|
||||
}
|
||||
|
||||
export interface PeopleSearchOptions extends SearchOptions{
|
||||
include_adult?: boolean;
|
||||
}
|
||||
|
||||
export class SearchEndpoint extends BaseEndpoint {
|
||||
constructor(protected readonly accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async companies(options: SearchOptions): Promise<Search<Company>>{
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Search<Company>>(`${BASE_SEARCH}/company?${params}`);
|
||||
}
|
||||
|
||||
async collections(options: SearchOptions): Promise<Search<Collection>>{
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Search<Collection>>(`${BASE_SEARCH}/collection?${params}`);
|
||||
}
|
||||
|
||||
async keywords(options: SearchOptions): Promise<Search<{ id: string, name: string }>>{
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Search<{ id: string, name: string }>>(`${BASE_SEARCH}/keyword?${params}`);
|
||||
}
|
||||
|
||||
async movies(options: MovieSearchOptions): Promise<Search<Movie>>{
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Search<Movie>>(`${BASE_SEARCH}/movie?${params}`);
|
||||
}
|
||||
|
||||
async people(options: PeopleSearchOptions): Promise<Search<Person>>{
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Search<Person>>(`${BASE_SEARCH}/person?${params}`);
|
||||
}
|
||||
|
||||
// TODO: Multi search
|
||||
|
||||
async tvShows(options: TvSearchOptions): Promise<Search<TV>>{
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<Search<TV>>(`${BASE_SEARCH}/tv?${params}`);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user