-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhockey_penalties.rb
47 lines (36 loc) · 1007 Bytes
/
hockey_penalties.rb
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
36
37
38
39
40
41
42
43
44
45
46
47
# 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::HockeyPenaltiesParams.new
# use a slug, typically 'league-team_abbreviation'
query_params.team_id = 'nhl-buf'
# may need to adjust this depending on time of year
query_params.status = 'ended'
query_params.since = '2 weeks ago'
# fetch will automatically traverse the paginated response links
penalties = Stattleship::HockeyPenalties.fetch(params: query_params)
# the populated object
pp penalties.first
# can access friendly helpers
pp penalties.first.to_sentence
# "Zach Bogosian (Buffalo) - Slashing - 2 minutes - 11:39 of 1P - vs Ottawa 01/26/16"
# or, individual attributes
penalties.each do |penalty|
pp penalty.minutes
end
# 2
# 5
# 2
# 2
# 2
# 2
# 2
# 2
# 2
# 2
# 4
# ...