src/endpoints/tvSeason.ts   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1.14

Size

Lines of Code 100
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 42
mnd 1
bc 1
fnc 7
dl 0
loc 100
bpm 0.1428
cpm 1.1428
noi 0
c 0
b 0
f 0
rs 10

7 Functions

Rating   Name   Duplication   Size   Complexity  
A TVSeason.credits 0 10 1
A TVSeason.show 0 9 1
A TVSeason.performChecks 0 8 2
A TVSeason.externalIDs 0 10 1
A TVSeason.images 0 10 1
A TVSeason.videos 0 10 1
A TVSeason.details 0 13 1
1
import { BaseEndpoint, QueryParameters } from './baseEndpoint';
2
import {
3
    TVSeasonDetailsResponse,
4
    TVSeasonCreditsResponse,
5
    TVSeasonExternalIDResponse,
6
    TVSeasonImagesResponse,
7
    TVSeasonVideosResponse,
8
} from '../interfaces/tvSeason';
9
10
/**
11
 * TVSeason Endpoint Class
12
 */
13
export class TVSeason extends BaseEndpoint {
14
15
    /**
16
     * Show ID we are working with
17
     * @var number | null
18
     */
19
    private showID: number | null = null;
20
21
    /**
22
     * Set the Show ID we are working with
23
     * @param { number } showID
24
     * @return TVSeason
25
     */
26
    public show(showID: number): TVSeason {
27
        this.showID = showID;
28
        return this;
29
    }
30
31
    /**
32
     * Get the TV season details by id.
33
     * @param { number } seasonNumber
34
     * @param { string[] } appendToResponse
35
     * @return { Promise<TVSeasonDetailsResponse> }
36
     * @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-details
37
     */
38
    public async details(seasonNumber: number, appendToResponse: string[] = []): Promise<TVSeasonDetailsResponse> {
39
        this.performChecks();
40
        return this.sendGetRequest(`tv/${this.showID}/season/${seasonNumber}`, {
41
            append_to_response: appendToResponse,
42
        } as QueryParameters);
43
    }
44
45
    /**
46
     * Get the credits for TV season.
47
     * @param { number } seasonNumber
48
     * @return { Promise<TVSeasonCreditsResponse> }
49
     * @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-credits
50
     */
51
    public async credits(seasonNumber: number): Promise<TVSeasonCreditsResponse> {
52
        this.performChecks();
53
        return this.sendGetRequest(`tv/${this.showID}/season/${seasonNumber}/credits`);
54
    }
55
56
    /**
57
     * Get the external ids for a TV season.
58
     * @param { number } seasonNumber
59
     * @return { Promise<TVSeasonExternalIDResponse> }
60
     * @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-external-ids
61
     */
62
    public async externalIDs(seasonNumber: number): Promise<TVSeasonExternalIDResponse> {
63
        this.performChecks();
64
        return this.sendGetRequest(`tv/${this.showID}/season/${seasonNumber}/external_ids`);
65
    }
66
67
    /**
68
     * Get the images that belong to a TV season.
69
     * @param { number } seasonNumber
70
     * @return { Promise<TVSeasonImagesResponse> }
71
     * @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-images
72
     */
73
    public async images(seasonNumber: number): Promise<TVSeasonImagesResponse> {
74
        this.performChecks();
75
        return this.sendGetRequest(`tv/${this.showID}/season/${seasonNumber}/images`);
76
    }
77
78
    /**
79
     * Get the videos that have been added to a TV season.
80
     * @param { number } seasonNumber
81
     * @return { Promise<TVSeasonVideosResponse> }
82
     * @see https://developers.themoviedb.org/3/tv-seasons/get-tv-season-external-ids
83
     */
84
    public async videos(seasonNumber: number): Promise<TVSeasonVideosResponse> {
85
        this.performChecks();
86
        return this.sendGetRequest(`tv/${this.showID}/season/${seasonNumber}/videos`);
87
    }
88
89
    /**
90
     * Perform necessary checks before executing request
91
     * @return void
92
     */
93
    private performChecks(): void {
94
        if (this.showID === null) {
95
            throw new Error('You must set the Show ID first via the `show(showID: number)` method!');
96
        }
97
    }
98
99
}
100