1 | import * as request from 'request';
|
2 |
|
3 | export class SpotifyClient {
|
4 |
|
5 | public static async search(token: string, type: string, terms: string) {
|
6 |
|
7 | return new Promise((resolve: any, reject: any) => {
|
8 |
|
9 | request.get(this.getHeaders(token, 'search?q=' + terms + '&type=' + type), (error: any, response: any, body: any) => {
|
10 |
|
11 | if (error) {
|
12 |
|
13 | console.log(error);
|
14 | reject(error);
|
15 |
|
16 | } else {
|
17 |
|
18 | resolve(body);
|
19 |
|
20 | }
|
21 |
|
22 | });
|
23 |
|
24 | });
|
25 |
|
26 | }
|
27 |
|
28 | public static getHeaders(token: string, path: string) {
|
29 |
|
30 | return {
|
31 |
|
32 | url: 'https://api.spotify.com/v1/' + path,
|
33 | headers: { 'Authorization': 'Bearer ' + token },
|
34 | json: true
|
35 |
|
36 | };
|
37 |
|
38 | }
|
39 |
|
40 | }
|