Flesh out Player model and write patch to populate players from sporting API
This commit is contained in:
31
app/services/sports_data.service.js
Normal file
31
app/services/sports_data.service.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { Service } = require('flitter-di')
|
||||
const axios = require('axios').default;
|
||||
|
||||
/**
|
||||
* A service class for interacting with data from the SportsDataIO API.
|
||||
*/
|
||||
class SportsDataService extends Service {
|
||||
static get services() {
|
||||
return [...super.services, 'configs']
|
||||
}
|
||||
|
||||
async get_team_players(team_key) {
|
||||
return this.get_request(`Players/${team_key}`)
|
||||
}
|
||||
|
||||
async get_active_teams() {
|
||||
return this.get_request('Teams')
|
||||
}
|
||||
|
||||
async get_request(path) {
|
||||
const response = await axios.get(this.url(path))
|
||||
return response.data
|
||||
}
|
||||
|
||||
url(path) {
|
||||
if ( path.startsWith('/') ) path = path.slice(1)
|
||||
return `https://api.sportsdata.io/v3/nfl/scores/json/${path}?key=${this.configs.get('server.sports_data.api_key')}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = SportsDataService
|
||||
Reference in New Issue
Block a user