getData
Option name | Type | Description |
---|---|---|
url | String |
|
Files a GET request to The Blue Alliance using a Promise.
var getData = (url) =>{
return new Promise((resolve,reject) =>{
tbaReq.open("GET", url, true); // Instantiate XMLHTTPRequest as a GET request at url. Mark as asynchronous
tbaReq.onreadystatechange = () => { // Runs when reday state changes
if(tbaReq.readyState === 4){ // Checks if request has been made
if(tbaReq.status === 200){ // Checks if request was a success
resolve(tbaReq.responseText); // Sets Promise equal to the response
}
else{
reject(tbaReq.statusText); // If the the request failed set the Promise equal to the error text
}
}
};
tbaReq.send(); // Sends the request
})
}
exports
Option name | Type | Description |
---|---|---|
id | String |
|
Export a constructor for TBA requests
module.exports = function TBA(id){
// Set the app ID to the given ID
this.id = "X-TBA-App-Id=" + id;
// Objects which contains methods for requests
this.team = {};
this.event = {};
this.district = {};
team
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team Request
this.team = (data, callback) => {
console.log(`${startURL}/team/frc${data.teamKey}?${this.id}`);
getData(`${startURL}/team/frc${data.teamKey}?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
listTeams
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a page from the Team List Request
this.team.listTeams = (data, callback) => {
getData(`${startURL}/teams/${data.pageNum}?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
events
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team Events Request
this.team.events = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/${data.year}/events?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
eventAwards
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team Event Awards Request
this.team.eventAwards = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/event/${data.year}${data.eventKey}/awards?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
eventMatches
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team Event Matches Request
this.team.eventMatches = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/event/${data.year}${data.eventKey}/matches?${this.id}`).then((response) =>{
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
yearsParticipated
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team Years Participated Request
this.team.yearsParticipated = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/years_participated?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
media
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team Media Request
this.team.media = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/${data.year}/media?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
historyEvents
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team History Events Request
this.team.historyEvents = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/history/events?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
return(err);
});
};
historyAwards
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team History Awards Request
this.team.historyAwards = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/history/awards?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
historyRobots
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team History Robots Request
this.team.historyRobots = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/history/robots?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
historyDistricts
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Team History Districts Request
this.team.historyDistricts = (data, callback) => {
getData(`${startURL}/team/frc${data.teamKey}/history/districts?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
event
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a specific Event Request
this.event = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
listEvents
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for an Event List Request
this.event.listEvents = (data, callback) => {
getData(`${startURL}/events/${data.year}?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
teams
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Event Teams Request
this.event.teams = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}/teams?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
matches
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Event Matches Request
this.event.matches = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}/matches?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
stats
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Event Stats Request
this.event.stats = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}/stats?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
rankings
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Event Rankings Request
this.event.rankings = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}/rankings?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
awards
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Event Awards Request
this.event.awards = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}/awards?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
districtPoints
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Event District Points Request
this.event.districtPoints = (data, callback) => {
getData(`${startURL}/event/${data.year}${data.eventKey}/district_points?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
match
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a Match Request
this.match = (data, callback) => {
getData(`${startURL}/match/${data.year}${data.eventKey}_${data.matchKey}?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
list
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a District List Request
this.district.list = (data, callback) => {
getData(`${startURL}/districts/${data.year}?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
competitions
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a District Events Request
this.district.competitions = (data, callback) => {
getData(`${startURL}/district/${data.districtKey}/${data.year}/events?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
pointRankings
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a District Rankings Request
this.district.pointRankings = (data, callback) => {
getData(`${startURL}/district/${data.districtKey}/${data.year}/rankings?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
teams
Option name | Type | Description |
---|---|---|
data | Object |
|
callback | Function |
|
Files a GET request with the format for a District Teams Request
this.district.teams = (data, callback) => {
getData(`${startURL}/district/${data.districtKey}/${data.year}/teams?${this.id}`).then((response) => {
callback(JSON.parse(response)); // Calls the callback function with the response from TBA
},
(err) => {
callback(err); // Calls the callback function with the error log
});
};
}