-
Notifications
You must be signed in to change notification settings - Fork 0
/
TBAInterface.js
50 lines (47 loc) · 1.42 KB
/
TBAInterface.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
46
47
48
49
50
// File adapted from 2451's TBAInterface.js
// TBAInterface funcitons to pull data from TheBlueAlliance.com
var teams = null;
var schedule = null;
var authKey = "oa9Mt34ilcOT2f6R5hlRSxKlkLWknCzXhyQOxHkn8gmtHtR69BNtCL1TSz7iQIUA";
/**
* Get list of teams in event
*
* @param {eventCode} eventCode the event code (i.e. 2020caln) to pull the team list
*/
function getTeams(eventCode) {
if (authKey) {
var xmlhttp = new XMLHttpRequest();
var url = "https://www.thebluealliance.com/api/v3/event/" + eventCode + "/teams/simple";
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("X-TBA-Auth-Key", authKey);
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = this.responseText;
teams = JSON.parse(response);
}
};
// Send request
xmlhttp.send();
}
}
/**
* Get schefule for event
*
* @param {eventCode} eventCode the event code (i.e. 2020caln) to pull the team list
*/
function getSchedule(eventCode) {
if (authKey) {
var xmlhttp = new XMLHttpRequest();
var url = "https://www.thebluealliance.com/api/v3/event/" + eventCode + "/matches/simple";
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("X-TBA-Auth-Key", authKey);
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = this.responseText;
schedule = JSON.parse(response);
}
};
// Send request
xmlhttp.send();
}
}