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
.env
file 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
/examples
dir. - Copy the
sample.env
file, insert your token and save asexamples/.env
- The
cd
to the/examples
directory andruby <example>.rb
such that the .env loads
-
- Uses
BasketballGameLogsParams
and makes aBasketballGameLogs
request - Use the
player_id
andsince
parameters to get Stephen Curry's game logs for the past week
- Uses
-
- Uses
FootballGameLogsParams
and makes aFootballGameLogs
request - Use the
player_id
,interval_type
andsince
parameters to get Cam Newton's game logs for the past weeks by specifying the interval type (divisionplayoffs, conferencechampionships, etc)
- Uses
-
- Uses
HockeyGamesParams
and makes aHockeyGames
request - Uses the
status
andsince
parameters to return ended Chicago Blackhawk games - Demonstrates
started_at
is a proper DateTime and rendersscoreline
s
- Uses
-
- Uses
FootballFeatsParams
and makes aFootballFeats
request - Uses
player_id
andlevel_up
parameters to return Cam Newton regular season accomplishments
- Uses
-
- Uses
BasketballInjuriesParams
and makes aBasketballInjuries
request - Use the
team_id
andsince
to get Spurs injuries and show the injury note and its injury location (knee, back, etc)
- Uses
-
- Uses
HockeyPenaltiesParams
and makes aHockeyPenalties
request - Uses the
status
andsince
parameters to return penalties for ended Buffalo Sabres games in last 2 weeks - Demonstrates
minutes
is a proper Integer and renders a friendly-readable sentence describing the penalty
- Uses
-
- Uses
FootballPlayersParams
and makes aFootballPlayers
request - Uses
team_id
parameters to return Denver Broncos players - Demonstrates ability to filter and sort on a numeric
salary
to get list of players making more than $5M and where they went toschool
- Uses
-
- Uses
HockeyScoringPlaysParams
and makes aHockeyScoringPlays
request - Uses the
status
andsince
parameters 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
BasketballStatLeadersParams
and makes aBasketballStatLeaders
request - Use the
type
,stat
andplace
parameters get the top 5 three point leaders (with ties)
- Uses
-
- Uses
FootballStatsParams
and makes aFootballStats
request - Use the
type
,stat
andplayer_id
parameters get Aaron Rodgers TDs thrown in each game - Demonstrates ability to get
game
-specific data per stat, such asweather_conditions
- Uses
-
- Uses
BasketballTeamGameLogsParams
and makes aBasketballTeamGameLogs
request - Use the
team_id
andsince
parameters to get Cavaliers team game logs for the past week
- Uses
-
- Uses
FootballTotalPlayerStatParams
and makes aFootballTotalPlayerStat
request - Use the
player_id
,type
andstat
parameters to Adrian Peterson's total number of rushing attempts in the regular season - Demonstrates a fully populated player, so can access his
weight
etc
- Uses
-
- Uses
HockeyTotalTeamStatParams
and makes aHockeyTotalTeamStat
request - Use the
team_id
andstat
parameters to the total number of third period goals the Canadiens has scored
- Uses
-
- Uses
BasketballTopStatsParams
and makes aBasketballTopStats
request - Use the
type
,stat
, andplace
parameters to return the 3 best (highest) offensive rebounding performances in NBA - Demonstrates a fully populated game, so know when this was accomplished
- Uses
-
- Uses
BasketballTeamOutcomeStreaksParams
and makes aBasketballTeamOutcomeStreaks
request - Use the
outcome
andcurrent
parameters to return winning streaks that filters to those more than 2 games in length - Demonstrates a fully populated streak
- Uses
-
- Uses
HockeyTeamOutcomeStreaksParams
and makes aHockeyTeamOutcomeStreaks
request - Use the
team_id
andranked
parameters 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