node-sportsdata: Easy wrapper around the SportsData API
This module is designed to be an easy-to-use wrapper around the SportsData API. This module is designed to be used with node.js, but could be modified to be used directly in the browser as well.
This module is meant to become a comprehensive list of the SportsData API calls available to you. Currently, I have only focused on the API calls for the NFL and NBA, but I will focus on the others as their seasons begin.
Install
npm install sportsdata
Or from source:
git clone git://github.com/rgerard/node-sportsdata.git cd node-sportsdata npm install
Simple Examples
var sportsdata_nfl = NFL; // Init the object with the access level, version, apikey, year, and season you care aboutsportsdata_nfl; // Get the season schedulesportsdata_nfl; var sportsdata_nba = NBA; // Init the object with the access level, version, apikey, seasonID, and season you care aboutsportsdata_nba; // Get the season schedulesportsdata_nba;
Test
I have written unit tests for these API calls using the nodeunit framework. The unit tests do not make actual API calls, as that would waste your API call limit. Instead, I have mocked the request object, and replace the call response with a pre-captured response for that exact same API call.
To run the unit tests:
nodeunit test/
Documentation
NFL
Please refer to the SportsData NFL API documentation for more detail on their API.
- init
- getWeeklySchedule
- getSeasonSchedule
- getGameStats
- getGameSummary
- getPlayByPlay
- getPlaySummary
- getGameBoxscore
- getExtendedBoxscore
- getWeeklyBoxscore
- getGameRoster
- getTeamHierarchy
- getTeamRoster
- getInjuries
- getGameDepthChart
- getTeamDepthChart
- getWeeklyLeagueLeaders
- getStandings
- getSeasonalStats
NBA
Please refer to the SportsData NBA API documentation for more detail on their API.
- init
- getSeasonSchedule
- get3DaySchedule
- getStandings
- getRosters
- getGameScoreAndStats
- getPlayByPlay
- getEventsGloassary
- getSeasonalStats
NFL API ### init(access_level, version, apikey, year, season)
Inits the object with your API data, including your API key.
Arguments
- access_level - Your API access level
- version - The version of the API
- apikey - Your API key
- year - The year
- season - The season type
Example
// Fetch the schedule for Week 1 of the NFL seasonvar sportsdata_nfl = NFL;sportsdata_nfl;
### getWeeklySchedule(week, callback)
Returns the schedule for the week in question as a JSON object
Arguments
- week - The week to retrieve the schedule for
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the schedule for Week 1 of the NFL seasonsportsdata;
### getSeasonSchedule(callback)
Returns the schedule for the entire season as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the schedule for the entire NFL seasonsportsdata;
### getGameStats(week, awayteam, hometeam, callback)
Returns the game stats for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the game statssportsdata;
### getGameSummary(week, awayteam, hometeam, callback)
Returns the game summary for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the game summarysportsdata;
### getPlayByPlay(week, awayteam, hometeam, callback)
Returns the play-by-play for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the play-by-playsportsdata;
### getPlaySummary(week, awayteam, hometeam, playid, callback)
Returns the play summary for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- playid - The ID of the specific play involved. This value is found in the response from getPlayByPlay.
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the play summarysportsdata;
### getGameBoxscore(week, awayteam, hometeam, callback)
Returns the boxscore for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the boxscoresportsdata;
### getExtendedBoxscore(week, awayteam, hometeam, callback)
Returns the extended boxscore for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the extended boxscoresportsdata;
### getWeeklyBoxscore(week, callback)
Returns the weekly boxscores as a JSON object
Arguments
- week - The week in question
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the weekly boxscoressportsdata;
### getGameRoster(week, awayteam, hometeam, callback)
Returns the game roster for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the game rostersportsdata;
### getTeamHierarchy(callback)
Returns the team hierarchy as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the team hierarchysportsdata;
### getTeamRoster(team, callback)
Returns the team roster of a specific team as a JSON object
Arguments
- team - The 3-letter abbreviation of the team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the team hierarchysportsdata;
### getInjuries(week, awayteam, hometeam, callback)
Returns the injuries for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the injuriessportsdata;
### getGameDepthChart(week, awayteam, hometeam, callback)
Returns the game depth chart for the game in question as a JSON object
Arguments
- week - The week in question
- awayteam - The 3-letter abbreviation of the away team
- hometeam - The 3-letter abbreviation of the home team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the game depth chartsportsdata;
### getTeamDepthChart(team, callback)
Returns the team depth chart for a team as a JSON object
Arguments
- team - The 3-letter abbreviation of the team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the team depth chartsportsdata;
### getWeeklyLeagueLeaders(week, callback)
Returns the weekly leaders as a JSON object
Arguments
- week - The week in question
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the weekly leaderssportsdata;
### getStandings(callback)
Returns the standings as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the standingssportsdata;
### getSeasonalStats(team, callback)
Returns the seasonal stats for a team as a JSON object
Arguments
- team - The 3-letter abbreviation of the team
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the seasonal stats for a teamsportsdata;
NBA API ### init(access_level, version, apikey, seasonID, season)
Inits the object with your API data, including your API key.
Arguments
- access_level - Your API access level
- version - The version of the API to use
- apikey - Your API key
- seasonID - The year
- season - The season type
Example
// Init the object with the access level, version, apikey, seasonID, and season you care aboutvar sportsdata_nba = NBA;sportsdata_nba;
### getSeasonSchedule(callback)
Returns the schedule for the entire season as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the schedule for the entire NBA seasonsportsdata;
### get3DaySchedule(callback)
Returns the rolling 3-day schedule as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the rolling 3-day schedulesportsdata;
### getStandings(callback)
Returns the standings as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the standingssportsdata;
### getRosters(callback)
Returns the rosters as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the rosterssportsdata;
### getGameScoreAndStats(gameid, callback)
Returns the game score and stats of a specific game as a JSON object
Arguments
- gameid - The id of the game in question. This value is returned from the API call getSeasonSchedule.
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the rosterssportsdata;
### getPlayByPlay(gameid, callback)
Returns the play-by-play of a specific game as a JSON object
Arguments
- gameid - The id of the game in question. This value is returned from the API call getSeasonSchedule.
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the play-by-playsportsdata;
### getEventsGloassary(callback)
Returns the events glossary as a JSON object
Arguments
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the events glossarysportsdata;
### getSeasonalStats(teamid, callback)
Returns the events glossary as a JSON object
Arguments
- teamid - The id of the team in question. This value is returned from the API call getStandings.
- callback(err, body) - A callback which is called after the API call has returned, or an error has occurred.
Example
// Fetch the events glossarysportsdata;