-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpotifyHelper.js
45 lines (39 loc) · 1.11 KB
/
SpotifyHelper.js
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
import querystring from "querystring";
export function getCurrentUser(access_token) {
const path = "https://api.spotify.com/v1/me";
const options = {
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + access_token
}
};
return fetch(path, options)
.then(response => response.json())
.then(json => json);
}
export function getHashParam(name) {
var regex = new RegExp("(#)(" + name + ")(=)([^#]*)"),
matches = [];
matches = regex.exec(window.location.hash);
if (matches !== null && matches.length > 4 && matches[4] !== null) {
return matches[4];
} else {
return false;
}
}
export function getSpotifyLoginURL() {
return fetch("/get_spotify_uri")
.then(response => response.json())
.then(json => json.spotify_uri);
}
function generateRandomString(length) {
let text = "";
const possible =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}