-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbasketball_game_logs.rb
More file actions
35 lines (25 loc) · 1.06 KB
/
basketball_game_logs.rb
File metadata and controls
35 lines (25 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Set your STATTLESHIP_ACCESS_TOKEN from https://www.stattleship.com in the examples/.env file
require 'dotenv'
Dotenv.load
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'stattleship')
require 'pp'
# Construct params for the fetch
query_params = Stattleship::Params::BasketballGameLogsParams.new
# use a slug, typically 'league-firstname-lastname'
query_params.player_id = 'nba-stephen-curry'
# may need to adjust this depending on time of year/NBA season
query_params.season_id = 'nba-2015-2016'
query_params.interval_type = 'nbachampionship'
query_params.since = 'june 2016'
# fetch will automatically traverse the paginated response links
game_logs = Stattleship::BasketballGameLogs.fetch(params: query_params)
# the populated object
pp game_logs.first
# can access friendly helpers
pp game_logs.first.to_sentence
# "Stephen Curry 8 FGM, 44.4 FG%, 25 PTS, 7 RBD, 11 A, 2 STL, 1 BLK (Warriors vs Bulls January 20, 2016 at 7:00pm)"
# or, individual attributes
game_logs.each do |game_log|
pp game_log.three_pointers_made
end