Implemented all known endpoints

Renamed ShiftRequest to ShiftStats
Implemented tests
Bumped version for release
This commit is contained in:
2018-04-25 21:28:51 -05:00
parent 9a7b4119cd
commit f730cf5345
4 changed files with 452 additions and 7 deletions

133
index.js
View File

@ -43,7 +43,7 @@ class Request {
}
}
module.exports = class ShiftRequest extends Request {
module.exports = class ShiftStats extends Request {
constructor(apiKey) {
super()
this.apiKey = apiKey || 'YXBpLnNoaWZ0c3RhdHMuY29tLDE5YjhhZGIwNDVjZjAxMzJhM2E5N2VmZDQ1YTRj'
@ -80,6 +80,15 @@ module.exports = class ShiftRequest extends Request {
return `/${path}?${querystring.stringify(query)}`
}
_gameSubpath(gameId, path, only) {
if (only == 'home') {
path = `home_${path}`
} else if (only == 'away') {
path = `away_${path}`
}
return this._request({ url: `game/${gameId}/${path}` })
}
login() {
return this._request({ url: 'login', query: {key: this.apiKey}, headers: this._basicHeaders() }).then((json) => {
this.ticketHash = json.ticket.hash
@ -87,7 +96,127 @@ module.exports = class ShiftRequest extends Request {
})
}
leagues() {
return this._request({ url: 'leagues' })
}
league(leagueId) {
return this._request({ url: `league/${leagueId}` })
}
leagueSeasons(leagueId) {
return this._request({ url: `league/${leagueId}/seasons` })
}
leagueSuspensions(leagueId, onlyActive = true) {
let query = {}
if (onlyActive) {
query.status = 'active'
}
return this._request({ url: `league/${leagueId}/suspensions`, query: query })
}
teamSearch(sport, name) {
return this._request({ url: 'teams', query: {name: name, not_ended: true, sport: sport.toLowerCase()} })
}
teamSchedule(teamId) {
return this._request({ url: `team/${teamId}/games`, query: {future: true, today: true, past: true} })
}
teamPlayersList(teamId) {
return this._request({ url: `team/${teamId}/players`, query: {status: 'active'} })
}
teamsInDivision(divisionName, leagueId, currentSeason = true) {
return this._request({ url: 'teams', query: {division: divisionName, league_id: leagueId, not_ended: currentSeason} })
}
teamGames(teamId, includeFuture = true, includeToday = true) {
return this._request({ url: `team/${teamId}/games`, query: {future: includeFuture, today: includeToday} })
}
teamGamesForStatus(teamId, status = 'Final,In Progress,Forfeit') {
return this._request({ url: `team/${teamId}/games`, query: {status: status} })
}
teamPractices(teamId, includeFuture = true, includeToday = true) {
return this._request({ url: `team/${teamId}/practices`, query: {future: includeFuture, today: includeToday} })
}
teamSuspensions(teamId, onlyActive = true) {
let query = {}
if (onlyActive) {
query.status = 'active'
}
return this._request({ url: `team/${teamId}/suspensions`, query: query })
}
game(gameId) {
return this._request({ url: `game/${gameId}` })
}
// only is 'home' or 'away', optional
gameGoals(gameId, only = null) {
return this._gameSubpath(gameId, 'goals', only)
}
// only is 'home' or 'away', optional
gameGoalies(gameId, only = null) {
return this._gameSubpath(gameId, 'goalies', only)
}
// only is 'home' or 'away', optional
gamePenalties(gameId, only = null) {
return this._gameSubpath(gameId, 'penalties', only)
}
// only is 'home' or 'away', optional
gameRoster(gameId, only = null) {
return this._gameSubpath(gameId, 'roster', only)
}
divisionGamesList(divisionId) {
return this._request({ url: `division/${divisionId}/games` })
}
// type is 'Regular Season', 'Playoffs', or 'Exhibition', required
divisionStandings(divisionId, type = 'Regular Season') {
return this._request({ url: `division/${divisionId}/standings`, query: {type: type}})
return this._request({ url: `division/${divisionId}/standings`, query: {type: type} })
}
divisionTeams(divisionId) {
return this._request({ url: `division/${divisionId}/teams` })
}
// type is 'Regular Season', 'Playoffs', or 'Exhibition', required
// limit, required
// metrics, required
divisionLeaders(divisionId, type = 'Regular Season', limit = 20, metrics = ['points', 'goals', 'assists', 'goals_against_average', 'save_percentage', 'wins', 'shutouts', 'number_first_stars', 'number_stars']) {
return this._request({ url: `division/${divisionId}/leaders`, query: {limit: limit, metrics: metrics.join(','), type: type} })
}
divisionSuspensions(divisionId, onlyActive = true) {
let query = {}
if (onlyActive) {
query.status = 'active'
}
return this._request({ url: `division/${divisionId}/suspensions`, query: query })
}
season(seasonId) {
return this._request({ url: `season/${seasonId}` })
}
seasonDivisionsList(seasonId) {
return this._request({ url: `season/${seasonId}/divisions` })
}
seasonSuspensions(seasonId, onlyActive = true) {
let query = {}
if (onlyActive) {
query.status = 'active'
}
return this._request({ url: `season/${seasonId}/suspensions`, query: query })
}
}