getData

declaration
 getData 

Option name Type Description
url String
  • The Blue Alliance API URL

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

method
 module.exports() 

Option name Type Description
id String
  • Idenfifier required by TBA api follows the format ::

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

property
 this.team 

Option name Type Description
data Object
  • Object containing the property {teamKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.listTeams 

Option name Type Description
data Object
  • Object containing the property {pageNum}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.events 

Option name Type Description
data Object
  • Object containing the properties {teamKey, year}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.eventAwards 

Option name Type Description
data Object
  • Object containing the properties {teamKey, year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.eventMatches 

Option name Type Description
data Object
  • Object containing the properties {teamKey, year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.yearsParticipated 

Option name Type Description
data Object
  • Object containing the properties {teamKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.media 

Option name Type Description
data Object
  • Object containing the properties {teamKey, year}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.historyEvents 

Option name Type Description
data Object
  • Object containing the properties {teamKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.historyAwards 

Option name Type Description
data Object
  • Object containing the properties {teamKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.historyRobots 

Option name Type Description
data Object
  • Object containing the properties {teamKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.team.historyDistricts 

Option name Type Description
data Object
  • Object containing the properties {teamKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.listEvents 

Option name Type Description
data Object
  • Object containing the properties {year}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.teams 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.matches 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.stats 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.rankings 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.awards 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.event.districtPoints 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.match 

Option name Type Description
data Object
  • Object containing the properties {year, eventKey, matchKey}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.district.list 

Option name Type Description
data Object
  • Object containing the properties {year}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.district.competitions 

Option name Type Description
data Object
  • Object containing the properties {districtKey, year}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.district.pointRankings 

Option name Type Description
data Object
  • Object containing the properties {districtKey, year}
callback Function
  • Function to be called with data returned from TBA

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

property
 this.district.teams 

Option name Type Description
data Object
  • Object containing the properties {districtKey, year}
callback Function
  • Function to be called with data returned from TBA

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
    });   
};
       
    }