nba v0.5.0 Nba.Stats
Provides a function for each stats.nba.com endpoint.
Examples
See what endpoints you can hit:
Nba.Stats.endpoints()
#=> [:assist_tracker:, :box_score:, :box_score_summary:, ...]
Each endpoint has a corresponding function with an arity of 0 that returns a list of the available query parameters for the endpoint.
Nba.Stats.player_profile()
#=> ["LeagueID", "PerMode", "PlayerID"]
If you need example keys for a query param, use Nba.Stats.keys_for/1
.
Note that you do not necessarily need to pass in values for all the keys listed.
Nba.Stats.keys_for("PerMode")
#=> ["Totals", "PerGame", "MinutesPer", "Per48", ...]
Now that you know what query params you can pass, let’s make
a call to the endpoint by passing in a map of query param
key/values. The functions with a !
raise an exception if the
API call results in an error.
Nba.Stats.player_profile(%{"PlayerID" => 1628366})
#=> {:ok, %{"CareerHighs" => ...}}
Nba.Stats.player_profile(%{"PlayerID" => "Go Bruins"})
#=> {:error, "The value 'Go Bruins' is not valid for PlayerID.; PlayerID is required"}
Nba.Stats.player_profile!(%{"PlayerID" => 1628366})
#=> %{"CareerHighs" => ...}
Nba.Stats.player_profile!(%{"PlayerID" => "Go Bruins"})
#=> ** (RuntimeError) The value 'Go Bruins' is not valid for PlayerID.; PlayerID is required
Link to this section Summary
Functions
Returns a list of atoms, one for each endpoint function in the Stats module
Returns a list of valid query param keys for an endpoint
Link to this section Functions
Returns a list of atoms, one for each endpoint function in the Stats module
Returns a list of valid query param keys for an endpoint