forked from DoF-6413/Dof-Scouting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTBAInterface.js
66 lines (59 loc) · 2.28 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// TBAInterface funcitons to pull data from TheBlueAlliance.com
//
// Slightly reformatted from the original source to add comments. The TBA key is the
// original one from ScoutingPASS. We really should get our own but thats something to do
// AFTER the bigger changes are added to our scouting app.
// The teams at the selected event
var teams = null;
// The match schedule at the selected event
var schedule = null;
// The TBA API key to use when making TBA API calls
var authKey = "uTHeEfPigDp9huQCpLNkWK7FBQIb01Qrzvt4MAjh9z2WQDkrsvNE77ch6bOPvPb6";
/**
* Get list of teams at the event
*
* @param {eventCode} - The TBA event code (i.e. 2024azva) to pull the team list for
*/
function getTeams( eventCode ) {
// Request the team list if we have an API key.
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() {
// State 4 means that the request had been sent, the server had finished returning the response and
// the browser had finished downloading the response content. Basically the AJAX call has completed.
if ( this.readyState == 4 && this.status == 200 ) {
var response = this.responseText;
teams = JSON.parse( response );
}
};
// Send request
xmlhttp.send();
}
}
/**
* Get schedule for the specified event
*
* @param {eventCode} - The TBA event code (i.e. 2024azva) to pull the schedule for
*/
function getSchedule( eventCode ) {
// Request the team list if we have an API key.
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() {
// State 4 means that the request had been sent, the server had finished returning the response and
// the browser had finished downloading the response content. Basically the AJAX call has completed.
if ( this.readyState == 4 && this.status == 200 ) {
var response = this.responseText;
schedule = JSON.parse( response );
}
};
// Send request
xmlhttp.send();
}
}