Making Stattleship API calls is dead simple.
- Build and set parameters
- Use that to fetch data
- Use fully populated PORO's
The pattern is pretty much as follows:
query_params = Stattleship::Params::BasketballGameLogsParams.new
query_params.player_id = 'nba-stephen-curry'
query_params.since = '1 week ago'
game_logs = Stattleship::BasketballGameLogs.fetch(params: query_params)
pp game_logs.first
That's it.
Just repeat for other sports (ie, HockeyGameLogsParams and HockeyGameLogs) or other endpoints (FootballPlayersParams and FootballPlayers) etc.
The fetch call will automatically traverse the paginated response and you'll get easy to use PORO's of data specific to that model.
There's validation, too, on the params to make sure you set just the ones it accepts. Ie, you can't make a call to FootballPlayers with a player that whose slug doesn't start with nfl- and things like that.
You'll need
- Stattleship API Access Token from https://www.stattleship.com
- Set that in your
.envfile asSTATTLESHIP_ACCESS_TOKEN=your_token - To build the gem:
gem build stattleship-ruby.gemspec - To install the gem (with the current version of the gem file):
gem install stattleship-ruby-0.1.xx.gem - To run examples, that .env file should be in the
/examplesdir. - Copy the
sample.envfile, insert your token and save asexamples/.env - The
cdto the/examplesdirectory andruby <example>.rbsuch that the .env loads
-
- Uses
BasketballGameLogsParamsand makes aBasketballGameLogsrequest - Use the
player_idandsinceparameters to get Stephen Curry's game logs for the past week
- Uses
-
- Uses
FootballGameLogsParamsand makes aFootballGameLogsrequest - Use the
player_id,interval_typeandsinceparameters to get Cam Newton's game logs for the past weeks by specifying the interval type (divisionplayoffs, conferencechampionships, etc)
- Uses
-
- Uses
HockeyGamesParamsand makes aHockeyGamesrequest - Uses the
statusandsinceparameters to return ended Chicago Blackhawk games - Demonstrates
started_atis a proper DateTime and rendersscorelines
- Uses
-
- Uses
FootballFeatsParamsand makes aFootballFeatsrequest - Uses
player_idandlevel_upparameters to return Cam Newton regular season accomplishments
- Uses
-
- Uses
BasketballInjuriesParamsand makes aBasketballInjuriesrequest - Use the
team_idandsinceto get Spurs injuries and show the injury note and its injury location (knee, back, etc)
- Uses
-
- Uses
HockeyPenaltiesParamsand makes aHockeyPenaltiesrequest - Uses the
statusandsinceparameters to return penalties for ended Buffalo Sabres games in last 2 weeks - Demonstrates
minutesis a proper Integer and renders a friendly-readable sentence describing the penalty
- Uses
-
- Uses
FootballPlayersParamsand makes aFootballPlayersrequest - Uses
team_idparameters to return Denver Broncos players - Demonstrates ability to filter and sort on a numeric
salaryto get list of players making more than $5M and where they went toschool
- Uses
-
- Uses
HockeyScoringPlaysParamsand makes aHockeyScoringPlaysrequest - Uses the
statusandsinceparameters to return scoring plays for ended Dallas Stars games in last month - Demonstrates can access an array of players who assisted on each goal
- Uses
-
- Uses
BasketballStatLeadersParamsand makes aBasketballStatLeadersrequest - Use the
type,statandplaceparameters get the top 5 three point leaders (with ties)
- Uses
-
- Uses
FootballStatsParamsand makes aFootballStatsrequest - Use the
type,statandplayer_idparameters get Aaron Rodgers TDs thrown in each game - Demonstrates ability to get
game-specific data per stat, such asweather_conditions
- Uses
-
- Uses
BasketballTeamGameLogsParamsand makes aBasketballTeamGameLogsrequest - Use the
team_idandsinceparameters to get Cavaliers team game logs for the past week
- Uses
-
- Uses
FootballTotalPlayerStatParamsand makes aFootballTotalPlayerStatrequest - Use the
player_id,typeandstatparameters to Adrian Peterson's total number of rushing attempts in the regular season - Demonstrates a fully populated player, so can access his
weightetc
- Uses
-
- Uses
HockeyTotalTeamStatParamsand makes aHockeyTotalTeamStatrequest - Use the
team_idandstatparameters to the total number of third period goals the Canadiens has scored
- Uses
-
- Uses
BasketballTopStatsParamsand makes aBasketballTopStatsrequest - Use the
type,stat, andplaceparameters to return the 3 best (highest) offensive rebounding performances in NBA - Demonstrates a fully populated game, so know when this was accomplished
- Uses
-
- Uses
BasketballTeamOutcomeStreaksParamsand makes aBasketballTeamOutcomeStreaksrequest - Use the
outcomeandcurrentparameters to return winning streaks that filters to those more than 2 games in length - Demonstrates a fully populated streak
- Uses
-
- Uses
HockeyTeamOutcomeStreaksParamsand makes aHockeyTeamOutcomeStreaksrequest - Use the
team_idandrankedparameters to the top 3 ranked streaks in length - Demonstrates a fully populated streak with season and league
- Uses
-
- Uses games params and request for each sport
- Demonstrates a fully populated list of officials for each game
-
- Uses basketball_scoreboards params
- Demonstrates a fully populated list of scoreboards to fetch a list of scoreboards (points, time per game) for a basketball game