Merge pull request #10 from Der-Penz/review-trending-find-endpoints
add review, trending, find endpoints
This commit is contained in:
14
src/endpoints/find.ts
Normal file
14
src/endpoints/find.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { BaseEndpoint } from './base';
|
||||
import querystring from 'querystring';
|
||||
import { ExternalIdOptions, FindResult } from '../types';
|
||||
|
||||
export class FindEndpoint extends BaseEndpoint {
|
||||
constructor(accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async byId(externalId: string, options: ExternalIdOptions): Promise<FindResult> {
|
||||
const params = querystring.encode(options);
|
||||
return await this.api.get<FindResult>(`/find/${externalId}?${params}`);
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,7 @@ export * from './configuration';
|
||||
export * from './tv-shows';
|
||||
export * from './discover';
|
||||
export * from './people';
|
||||
export * from './review';
|
||||
export * from './trending';
|
||||
export * from './find';
|
||||
|
||||
|
||||
12
src/endpoints/review.ts
Normal file
12
src/endpoints/review.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ReviewDetails } from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
export class ReviewEndpoint extends BaseEndpoint {
|
||||
constructor(accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async details(id: string): Promise<ReviewDetails> {
|
||||
return await this.api.get<ReviewDetails>(`/review/${id}`);
|
||||
}
|
||||
}
|
||||
14
src/endpoints/trending.ts
Normal file
14
src/endpoints/trending.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { MediaType, TimeWindow, TrendingResults, } from '../types';
|
||||
import { BaseEndpoint } from './base';
|
||||
|
||||
export class TrendingEndpoint extends BaseEndpoint {
|
||||
constructor(accessToken: string) {
|
||||
super(accessToken);
|
||||
}
|
||||
|
||||
async trending<T extends MediaType>(mediaType : T, timeWindow: TimeWindow): Promise<TrendingResults<T>> {
|
||||
return await this.api.get<TrendingResults<T>>(`/trending/${mediaType}/${timeWindow}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
15
src/tmdb.ts
15
src/tmdb.ts
@@ -10,6 +10,9 @@ import {
|
||||
ConfigurationEndpoint,
|
||||
DiscoverEndpoint,
|
||||
PeopleEndpoint,
|
||||
ReviewEndpoint,
|
||||
TrendingEndpoint,
|
||||
FindEndpoint,
|
||||
} from './endpoints';
|
||||
|
||||
export default class TMDB {
|
||||
@@ -62,4 +65,16 @@ export default class TMDB {
|
||||
get people(): PeopleEndpoint{
|
||||
return new PeopleEndpoint(this.accessToken);
|
||||
}
|
||||
|
||||
get review(): ReviewEndpoint{
|
||||
return new ReviewEndpoint(this.accessToken);
|
||||
}
|
||||
|
||||
get trending(): TrendingEndpoint{
|
||||
return new TrendingEndpoint(this.accessToken);
|
||||
}
|
||||
|
||||
get find() : FindEndpoint{
|
||||
return new FindEndpoint(this.accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
29
src/types/find.ts
Normal file
29
src/types/find.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ParsedUrlQueryInput } from 'querystring';
|
||||
import { Episode, Media, MediaType, Movie, Person, Season, TV } from '.';
|
||||
|
||||
export type ExternalSource =
|
||||
| 'imdb_id'
|
||||
| 'freebase_mid'
|
||||
| 'freebase_id'
|
||||
| 'tvdb_id'
|
||||
| 'tvrage_id'
|
||||
| 'facebook_id'
|
||||
| 'twitter_id'
|
||||
| 'instagram_id';
|
||||
|
||||
export interface ExternalIdOptions extends ParsedUrlQueryInput {
|
||||
external_source: ExternalSource;
|
||||
language?: string;
|
||||
}
|
||||
|
||||
type MediaTagged<T> = T & {
|
||||
media_type: MediaType;
|
||||
};
|
||||
|
||||
export interface FindResult {
|
||||
movie_results: MediaTagged<Movie>[];
|
||||
person_results: MediaTagged<Person>[];
|
||||
tv_results: MediaTagged<TV>[];
|
||||
tv_episode_results: MediaTagged<Episode>[];
|
||||
tv_season_results: MediaTagged<Season & { show_id: string }>[];
|
||||
}
|
||||
@@ -8,6 +8,9 @@ export * from './tv-shows';
|
||||
export * from './watch-providers';
|
||||
export * from './people';
|
||||
export * from './discover';
|
||||
export * from './review';
|
||||
export * from './trending';
|
||||
export * from './find';
|
||||
|
||||
export interface AuthorDetails {
|
||||
name: string;
|
||||
|
||||
8
src/types/review.ts
Normal file
8
src/types/review.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Review } from './';
|
||||
|
||||
export interface ReviewDetails extends Review{
|
||||
iso_639_1: string;
|
||||
media_id: number;
|
||||
media_title: number;
|
||||
media_type: number;
|
||||
}
|
||||
19
src/types/trending.ts
Normal file
19
src/types/trending.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Movie, Person, TV } from '.';
|
||||
export type MediaType = 'all' | 'movie' | 'tv' | 'person';
|
||||
|
||||
export type TimeWindow = 'day' | 'week';
|
||||
|
||||
type TrendingResult<T extends MediaType> = T extends 'tv'
|
||||
? TV
|
||||
: T extends 'movie'
|
||||
? Movie
|
||||
: T extends 'person'
|
||||
? Person
|
||||
: TV | Movie | Person;
|
||||
|
||||
export interface TrendingResults<T extends MediaType> {
|
||||
page: number;
|
||||
results: (TrendingResult<T> & {media_type: MediaType})[];
|
||||
total_pages: number;
|
||||
total_results: number;
|
||||
}
|
||||
@@ -100,6 +100,8 @@ export interface Episode {
|
||||
still_path: string
|
||||
vote_average: number
|
||||
vote_count: number
|
||||
show_id: number;
|
||||
runtime: number;
|
||||
}
|
||||
|
||||
export interface SeasonDetails {
|
||||
|
||||
Reference in New Issue
Block a user