sportsdata
v0.1.19
Published
Node module that wraps the SportsData API
Downloads
5
Readme
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
Or from source:
Simple Examples
var sportsdata_nfl = require('sportsdata').NFL;
// Init the object with the access level, version, apikey, year, and season you care about
sportsdata_nfl.init('t', 1, apikey, '2012', 'REG');
// Get the season schedule
sportsdata_nfl.getSeasonSchedule(function(error, schedule) {
if (!error) {
console.log(schedule) // Print the season schedule for the NFL season
}
});
var sportsdata_nba = require('sportsdata').NBA;
// Init the object with the access level, version, apikey, seasonID, and season you care about
sportsdata_nba.init('t', 2, apikey, '2012', 'REG');
// Get the season schedule
sportsdata_nba.getSeasonSchedule(function(error, schedule) {
if (!error) {
console.log(schedule) // Print the season schedule for the NBA season
}
});
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
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 season
var sportsdata_nfl = require('sportsdata').NFL;
sportsdata_nfl.init('t', 1, apikey, '2012', 'REG');
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 season
sportsdata.getWeeklySchedule(1, function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 season
sportsdata.getSeasonSchedule(function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 stats
sportsdata.getGameStats(1, 'DAL', 'NYG', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 summary
sportsdata.getGameSummary(1, 'DAL', 'NYG', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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-play
sportsdata.getPlayByPlay(1, 'DAL', 'NYG', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 summary
sportsdata.getPlaySummary(1, 'DAL', 'NYG', 'fdec3736-3598-4cde-ad4c-7270afc6d4e7', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 boxscore
sportsdata.getGameBoxscore(1, 'DAL', 'NYG', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 boxscore
sportsdata.getExtendedBoxscore(1, 'DAL', 'NYG', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 boxscores
sportsdata.getWeeklyBoxscore(1, function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 roster
sportsdata.getGameRoster(1, 'DAL', 'NYG', function(error, stats) {
if (!error) {
console.log(stats);
}
});
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 hierarchy
sportsdata.getTeamHierarchy(function(error, data) {
if (!error) {
console.log(data);
}
});
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 hierarchy
sportsdata.getTeamRoster('DAL', function(error, data) {
if (!error) {
console.log(data);
}
});
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 injuries
sportsdata.getInjuries(1, 'DAL', 'NYG', function(error, data) {
if (!error) {
console.log(data);
}
});
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 chart
sportsdata.getGameDepthChart(1, 'DAL', 'NYG', function(error, data) {
if (!error) {
console.log(data);
}
});
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 chart
sportsdata.getTeamDepthChart('DAL', function(error, data) {
if (!error) {
console.log(data);
}
});
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 leaders
sportsdata.getWeeklyLeagueLeaders(1, function(error, data) {
if (!error) {
console.log(data);
}
});
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 standings
sportsdata.getStandings(function(error, data) {
if (!error) {
console.log(data);
}
});
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 team
sportsdata.getSeasonalStats('DAL', function(error, data) {
if (!error) {
console.log(data);
}
});
NBA API
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 about
var sportsdata_nba = require('sportsdata').NBA;
sportsdata_nba.init('t', 2, apikey, '2012', 'REG');
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 season
sportsdata.getSeasonSchedule(function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 schedule
sportsdata.get3DaySchedule(function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 standings
sportsdata.getStandings(function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 rosters
sportsdata.getRosters(function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 rosters
sportsdata.getGameScoreAndStats(2393, function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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-play
sportsdata.getPlayByPlay(2393, function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 glossary
sportsdata.getEventsGloassary(function(error, schedule) {
if (!error) {
console.log(schedule);
}
});
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 glossary
sportsdata.getSeasonalStats(7406, function(error, schedule) {
if (!error) {
console.log(schedule);
}
});