/
TracksApi.ts
98 lines (91 loc) · 2.49 KB
/
TracksApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Http } from '../helpers/Http';
import { AudioAnalysis, AudioFeatures, Track } from '../types/SpotifyObjects';
import { MarketOptions } from '../types/SpotifyOptions';
import {
GetAudioFeaturesForTracksResponse,
GetTracksResponse,
} from '../types/SpotifyResponses';
export class TracksApi {
private http: Http;
constructor(http: Http) {
this.http = http;
}
/**
* Get Audio Analysis for a Track
*
* Get a detailed audio analysis for a single track identified by its unique
* Spotify ID.
*
* @param trackId The Spotify ID for the track.
*/
getAudioAnalysisForTrack(trackId: string): Promise<AudioAnalysis> {
return this.http.get<AudioAnalysis>(`/audio-analysis/${trackId}`);
}
/**
* Get Audio Features for a Track
*
* Get audio feature information for a single track identified by its unique
* Spotify ID.
*
* @param trackId The Spotify ID for the track.
*/
getAudioFeaturesForTrack(trackId: string): Promise<AudioFeatures> {
return this.http.get<AudioFeatures>(`/audio-features/${trackId}`);
}
/**
* Get Audio Features for Several Tracks
*
* Get audio features for multiple tracks based on their Spotify IDs.
*
* @param trackIds The Spotify IDs for the tracks.
*/
async getAudioFeaturesForTracks(
trackIds: string[],
): Promise<Array<AudioFeatures | null>> {
const response = await this.http.get<GetAudioFeaturesForTracksResponse>(
'/audio-features',
{
params: {
ids: trackIds,
},
},
);
return response.audio_features;
}
/**
* Get a Track
*
* Get Spotify catalog information for a single track identified by its unique
* Spotify ID.
*
* @param trackId The Spotify ID for the track.
* @param options Optional request information.
*/
getTrack(trackId: string, options?: MarketOptions): Promise<Track> {
return this.http.get<Track>(
`/tracks/${trackId}`,
options && { params: options },
);
}
/**
* Get Several Tracks
*
* Get Spotify catalog information for multiple tracks based on their Spotify
* IDs.
*
* @param trackIds The Spotify IDs for the tracks.
* @param options Optional request information.
*/
async getTracks(
trackIds: string[],
options?: MarketOptions,
): Promise<Array<Track | null>> {
const response = await this.http.get<GetTracksResponse>('/tracks', {
params: {
...options,
ids: trackIds,
},
});
return response.tracks;
}
}