sportradar-api 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +1 -0
- data/lib/sportradar/api/baseball/events/lineup.rb +3 -3
- data/lib/sportradar/api/baseball/events/warming_up.rb +4 -0
- data/lib/sportradar/api/baseball/game.rb +45 -9
- data/lib/sportradar/api/baseball/lineup.rb +23 -15
- data/lib/sportradar/api/baseball/mlb/api.rb +75 -0
- data/lib/sportradar/api/baseball/mlb.rb +234 -43
- data/lib/sportradar/api/baseball/player.rb +1 -1
- data/lib/sportradar/api/baseball/team.rb +1 -1
- data/lib/sportradar/api/baseball.rb +1 -21
- data/lib/sportradar/api/basketball/game.rb +1 -1
- data/lib/sportradar/api/basketball/nba/api.rb +71 -0
- data/lib/sportradar/api/basketball/nba/conference.rb +10 -3
- data/lib/sportradar/api/basketball/nba/division.rb +11 -4
- data/lib/sportradar/api/basketball/nba/game.rb +1 -1
- data/lib/sportradar/api/basketball/nba/player.rb +1 -1
- data/lib/sportradar/api/basketball/nba/team.rb +1 -1
- data/lib/sportradar/api/basketball/nba.rb +145 -74
- data/lib/sportradar/api/basketball/ncaamb/api.rb +77 -0
- data/lib/sportradar/api/basketball/ncaamb/conference.rb +6 -1
- data/lib/sportradar/api/basketball/ncaamb/division.rb +3 -1
- data/lib/sportradar/api/basketball/ncaamb/game.rb +5 -5
- data/lib/sportradar/api/basketball/ncaamb/hierarchy.rb +1 -1
- data/lib/sportradar/api/basketball/ncaamb/player.rb +1 -1
- data/lib/sportradar/api/basketball/ncaamb/team.rb +1 -1
- data/lib/sportradar/api/basketball/ncaamb/tournament.rb +1 -1
- data/lib/sportradar/api/basketball/ncaamb.rb +165 -82
- data/lib/sportradar/api/basketball.rb +2 -2
- data/lib/sportradar/api/config.rb +2 -2
- data/lib/sportradar/api/content/article.rb +1 -1
- data/lib/sportradar/api/content/article_list.rb +1 -1
- data/lib/sportradar/api/content.rb +8 -4
- data/lib/sportradar/api/football/drive.rb +20 -5
- data/lib/sportradar/api/football/event.rb +3 -0
- data/lib/sportradar/api/football/game.rb +21 -4
- data/lib/sportradar/api/football/game_stats.rb +14 -10
- data/lib/sportradar/api/football/ncaafb/api.rb +4 -4
- data/lib/sportradar/api/football/ncaafb/drive.rb +58 -2
- data/lib/sportradar/api/football/ncaafb/game.rb +26 -0
- data/lib/sportradar/api/football/ncaafb/play.rb +124 -2
- data/lib/sportradar/api/football/ncaafb/team.rb +9 -0
- data/lib/sportradar/api/football/ncaafb.rb +3 -2
- data/lib/sportradar/api/football/nfl/api.rb +4 -4
- data/lib/sportradar/api/football/nfl/depth_chart.rb +53 -0
- data/lib/sportradar/api/football/nfl/drive.rb +7 -3
- data/lib/sportradar/api/football/nfl/game.rb +3 -0
- data/lib/sportradar/api/football/nfl/league_depth_chart.rb +41 -0
- data/lib/sportradar/api/football/nfl/play.rb +15 -0
- data/lib/sportradar/api/football/nfl/team_depth_chart.rb +44 -0
- data/lib/sportradar/api/football/nfl.rb +39 -9
- data/lib/sportradar/api/football/play.rb +111 -9
- data/lib/sportradar/api/football/play_statistics.rb +397 -0
- data/lib/sportradar/api/football/player.rb +2 -1
- data/lib/sportradar/api/football/quarter.rb +8 -1
- data/lib/sportradar/api/football/scoring.rb +5 -10
- data/lib/sportradar/api/football/situation.rb +18 -2
- data/lib/sportradar/api/football/team.rb +9 -3
- data/lib/sportradar/api/football/week.rb +4 -4
- data/lib/sportradar/api/football.rb +4 -0
- data/lib/sportradar/api/images.rb +6 -6
- data/lib/sportradar/api/version.rb +1 -1
- metadata +9 -4
- data/lib/sportradar/api/baseball/mlb/hierarchy.rb +0 -273
- data/lib/sportradar/api/basketball/nba/hierarchy.rb +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a544bed7327664085716d731056ce27741ae3235
|
|
4
|
+
data.tar.gz: d48e44f4d80b63b24a482ac6e40bb4f55382f5cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 440c2f9bffb27fb8c11d4ccb7d76cfcd6eca961e77b1dafe7d445bb95e685b8391051a38c0a1c8af2b999bd7cbaf4ac5a5be073586e6c084821770fa18e78f28
|
|
7
|
+
data.tar.gz: 548e34be5cc5b946a92b792df65200f66c852c24ec5f9ff933f2f5d595a416df7fcb623cbe01e69dd54cf7a67693d1f352b6b765949495d5d85377ace8900ee0
|
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
sportradar-api (0.
|
|
4
|
+
sportradar-api (0.12.0)
|
|
5
5
|
activesupport
|
|
6
6
|
httparty (>= 0.14.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activesupport (5.1.
|
|
11
|
+
activesupport (5.1.4)
|
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
13
|
i18n (~> 0.7)
|
|
14
14
|
minitest (~> 5.1)
|
|
@@ -45,9 +45,9 @@ GEM
|
|
|
45
45
|
guard-compat (~> 1.2)
|
|
46
46
|
minitest (>= 3.0)
|
|
47
47
|
hashdiff (0.3.4)
|
|
48
|
-
httparty (0.15.
|
|
48
|
+
httparty (0.15.6)
|
|
49
49
|
multi_xml (>= 0.5.2)
|
|
50
|
-
i18n (0.8.
|
|
50
|
+
i18n (0.8.6)
|
|
51
51
|
json (2.1.0)
|
|
52
52
|
listen (3.1.5)
|
|
53
53
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
data/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
[](https://travis-ci.org/beneggett/sportradar-api)
|
|
3
3
|
[](https://codeclimate.com/github/beneggett/sportradar-api)
|
|
4
4
|
[](https://coveralls.io/github/beneggett/sportradar-api?branch=master)
|
|
5
|
+
[](https://gemnasium.com/github.com/beneggett/sportradar-api)
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
# Sportradar API
|
|
@@ -19,12 +19,12 @@ module Sportradar
|
|
|
19
19
|
@preferred_name = data["preferred_name"]
|
|
20
20
|
@jersey_number = data["jersey_number"]
|
|
21
21
|
|
|
22
|
-
update(data)
|
|
22
|
+
# update(data)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def update(data, **opts)
|
|
26
|
-
lineup = event.half_inning.inning.game.lineup
|
|
27
|
-
lineup.update_from_lineup_event(data)
|
|
26
|
+
# lineup = event.half_inning.inning.game.lineup
|
|
27
|
+
# lineup.update_from_lineup_event(data)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def data_key
|
|
@@ -116,8 +116,8 @@ module Sportradar
|
|
|
116
116
|
@scheduled = Time.parse(data["scheduled"]) if data["scheduled"]
|
|
117
117
|
@venue = Venue.new(data['venue']) if data['venue']
|
|
118
118
|
@broadcast = Broadcast.new(data['broadcast']) if !data['broadcast'].to_h.empty?
|
|
119
|
-
@home = Team.new(data['home'], api: api, game: self) if data['home']
|
|
120
|
-
@away = Team.new(data['away'], api: api, game: self) if data['away']
|
|
119
|
+
@home = Team.new(data['home'] || data.dig('scoring', 'home'), api: api, game: self) if data['home'] || data.dig('scoring', 'home')
|
|
120
|
+
@away = Team.new(data['away'] || data.dig('scoring', 'away'), api: api, game: self) if data['away'] || data.dig('scoring', 'away')
|
|
121
121
|
@title = data['title'] || @title || (home && away && "#{home.full_name} vs #{away.full_name}")
|
|
122
122
|
|
|
123
123
|
@duration = data['duration'] if data['duration']
|
|
@@ -131,7 +131,7 @@ module Sportradar
|
|
|
131
131
|
update_bases(data)
|
|
132
132
|
parse_pitchers(data) if data['home'] && data['away']
|
|
133
133
|
|
|
134
|
-
lineup.update(data, source: source)
|
|
134
|
+
lineup.update(data, source: source) unless source == :pbp
|
|
135
135
|
if data['scoring']
|
|
136
136
|
parse_score(data['scoring'])
|
|
137
137
|
elsif data.dig('home', 'hits')
|
|
@@ -179,9 +179,9 @@ module Sportradar
|
|
|
179
179
|
@inning_over = true
|
|
180
180
|
@bases = DEFAULT_BASES.dup
|
|
181
181
|
half, inn = if count['inning_half'] == 'B'
|
|
182
|
-
['
|
|
182
|
+
['E', count['inning']]
|
|
183
183
|
elsif count['inning_half'] == 'T'
|
|
184
|
-
['
|
|
184
|
+
['M', count['inning']]
|
|
185
185
|
else
|
|
186
186
|
[nil, 1]
|
|
187
187
|
end
|
|
@@ -290,7 +290,7 @@ module Sportradar
|
|
|
290
290
|
|
|
291
291
|
# status helpers
|
|
292
292
|
|
|
293
|
-
def realtime_state
|
|
293
|
+
def realtime_state(full_word: false)
|
|
294
294
|
if future?
|
|
295
295
|
'Scheduled'
|
|
296
296
|
elsif delayed?
|
|
@@ -300,7 +300,7 @@ module Sportradar
|
|
|
300
300
|
elsif postponed?
|
|
301
301
|
'Postponed'
|
|
302
302
|
else
|
|
303
|
-
|
|
303
|
+
full_word ? inning_word : inning_short
|
|
304
304
|
end
|
|
305
305
|
end
|
|
306
306
|
|
|
@@ -308,10 +308,44 @@ module Sportradar
|
|
|
308
308
|
if !count.empty?
|
|
309
309
|
inning_half = self.count['inning_half']
|
|
310
310
|
inning = self.count['inning']
|
|
311
|
-
"#{
|
|
311
|
+
"#{inning_half || 'T'}#{(inning || 1)}"
|
|
312
312
|
end
|
|
313
313
|
end
|
|
314
314
|
|
|
315
|
+
def inning_short
|
|
316
|
+
if !count.empty?
|
|
317
|
+
inning_half = self.count['inning_half']
|
|
318
|
+
inning = self.count['inning']
|
|
319
|
+
"#{half_short} #{(inning || 1).ordinalize}"
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def inning_word
|
|
324
|
+
if !count.empty?
|
|
325
|
+
inning_half = self.count['inning_half']
|
|
326
|
+
inning = self.count['inning']
|
|
327
|
+
"#{half_word} #{(inning || 1).ordinalize}"
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def half_word
|
|
332
|
+
{
|
|
333
|
+
'B' => 'Bottom',
|
|
334
|
+
'T' => 'Top',
|
|
335
|
+
'M' => 'Middle',
|
|
336
|
+
'E' => 'End',
|
|
337
|
+
}.freeze[self.count['inning_half']]
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def half_short
|
|
341
|
+
{
|
|
342
|
+
'B' => 'Bot',
|
|
343
|
+
'T' => 'Top',
|
|
344
|
+
'M' => 'Mid',
|
|
345
|
+
'E' => 'End',
|
|
346
|
+
}.freeze[self.count['inning_half']]
|
|
347
|
+
end
|
|
348
|
+
|
|
315
349
|
def postponed?
|
|
316
350
|
'postponed' == status
|
|
317
351
|
end
|
|
@@ -395,6 +429,8 @@ module Sportradar
|
|
|
395
429
|
innings = data['innings'].each { |inning| inning['id'] = "#{data['id']}-#{inning['number']}" }
|
|
396
430
|
create_data(@innings_hash, innings, klass: Inning, api: api, game: self) if data['innings']
|
|
397
431
|
extract_count(data)
|
|
432
|
+
lineup.update(data, source: :pbp)
|
|
433
|
+
# update lineups
|
|
398
434
|
check_newness(:pitches, pitches.last&.id)
|
|
399
435
|
check_newness(:events, events.last&.description)
|
|
400
436
|
check_newness(:score, @score)
|
|
@@ -429,7 +465,7 @@ module Sportradar
|
|
|
429
465
|
end
|
|
430
466
|
|
|
431
467
|
def api
|
|
432
|
-
@api || Sportradar::Api::Baseball::Mlb.new
|
|
468
|
+
@api || Sportradar::Api::Baseball::Mlb::Api.new
|
|
433
469
|
end
|
|
434
470
|
|
|
435
471
|
def sim!
|
|
@@ -10,6 +10,14 @@ module Sportradar
|
|
|
10
10
|
def update(data, source: nil)
|
|
11
11
|
case source
|
|
12
12
|
when :pbp
|
|
13
|
+
@home = initial_lineup.dup
|
|
14
|
+
@away = initial_lineup.dup
|
|
15
|
+
lineups = game.events.select {|ev| ev.lineup }.map(&:lineup)
|
|
16
|
+
lineups.each do |line|
|
|
17
|
+
player_data = line.response
|
|
18
|
+
player_data['id'] = player_data.delete('player_id')
|
|
19
|
+
update_from_lineup_event(player_data)
|
|
20
|
+
end
|
|
13
21
|
when :summary
|
|
14
22
|
@roster = (data.dig('home', 'roster') || []) + (data.dig('away', 'roster') || [])
|
|
15
23
|
return unless data.dig('home', 'lineup') && data.dig('away', 'lineup')
|
|
@@ -21,10 +29,10 @@ module Sportradar
|
|
|
21
29
|
end
|
|
22
30
|
|
|
23
31
|
def update_from_lineup_event(data)
|
|
24
|
-
if data.dig('
|
|
25
|
-
update_home(
|
|
26
|
-
elsif data.dig('
|
|
27
|
-
update_away(
|
|
32
|
+
if data.dig('team_id') == game.home_id
|
|
33
|
+
update_home(data, data.dig('order'))
|
|
34
|
+
elsif data.dig('team_id') == game.away_id
|
|
35
|
+
update_away(data, data.dig('order'))
|
|
28
36
|
end
|
|
29
37
|
end
|
|
30
38
|
|
|
@@ -69,27 +77,27 @@ module Sportradar
|
|
|
69
77
|
def next_batters(team, number_of_upcoming_batters = 3)
|
|
70
78
|
if team == 'home'
|
|
71
79
|
last_at_bat = game.at_bats.select{|at_bat| at_bat.event.half_inning.half == 'B'}.last
|
|
72
|
-
if last_at_bat
|
|
73
|
-
last_position = @
|
|
80
|
+
if last_at_bat
|
|
81
|
+
last_position = @home.detect{|htl| htl['id'] == last_at_bat.hitter_id}&.dig('order')
|
|
74
82
|
upcoming = home.rotate(last_position || 0)
|
|
75
|
-
else
|
|
83
|
+
else # first inning
|
|
76
84
|
upcoming = home
|
|
77
85
|
end
|
|
78
86
|
elsif team == 'away'
|
|
79
87
|
last_at_bat = game.at_bats.select{|at_bat| at_bat.event.half_inning.half == 'T'}.last
|
|
80
|
-
if last_at_bat
|
|
81
|
-
last_position = @
|
|
88
|
+
if last_at_bat
|
|
89
|
+
last_position = @away.detect{|atl| atl['id'] == last_at_bat.hitter_id}&.dig('order')
|
|
82
90
|
upcoming = away.rotate(last_position || 0)
|
|
83
|
-
else
|
|
91
|
+
else # first inning
|
|
84
92
|
upcoming = away
|
|
85
93
|
end
|
|
86
94
|
end
|
|
87
95
|
upcoming[0..(number_of_upcoming_batters - 1)]
|
|
88
|
-
rescue => e
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
# rescue => e
|
|
97
|
+
# i ||= 0
|
|
98
|
+
# game.get_summary
|
|
99
|
+
# i += 1
|
|
100
|
+
# retry unless i > 2
|
|
93
101
|
end
|
|
94
102
|
|
|
95
103
|
private
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Baseball
|
|
4
|
+
class Mlb
|
|
5
|
+
class Api < Request
|
|
6
|
+
attr_accessor :league, :access_level, :simulation, :error
|
|
7
|
+
|
|
8
|
+
def initialize(access_level = default_access_level)
|
|
9
|
+
@league = 'mlb'
|
|
10
|
+
raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
|
|
11
|
+
@access_level = access_level
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def sim!
|
|
15
|
+
@version = 5
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def default_year
|
|
20
|
+
Date.today.year
|
|
21
|
+
end
|
|
22
|
+
def default_date
|
|
23
|
+
Date.today
|
|
24
|
+
end
|
|
25
|
+
def default_season
|
|
26
|
+
'reg'
|
|
27
|
+
end
|
|
28
|
+
def default_access_level
|
|
29
|
+
if (ENV['SPORTRADAR_ENV'] || ENV['SPORTRADAR_ENV_MLB'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
|
|
30
|
+
'p'
|
|
31
|
+
else
|
|
32
|
+
't'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def content_format
|
|
37
|
+
'json'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def request_url(path)
|
|
43
|
+
"/mlb-#{access_level}#{version}/#{path}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def api_key
|
|
47
|
+
if !['t', 'sim'].include?(access_level)
|
|
48
|
+
Sportradar::Api.api_key_params('mlb', 'production')
|
|
49
|
+
elsif 'sim' == access_level
|
|
50
|
+
Sportradar::Api.api_key_params('mlb', 'simulation')
|
|
51
|
+
else
|
|
52
|
+
Sportradar::Api.api_key_params('mlb')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def version
|
|
57
|
+
@version || Sportradar::Api.version('mlb')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def allowed_access_levels
|
|
61
|
+
%w[p t sim]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def allowed_seasons
|
|
65
|
+
["pre", "reg", "pst"]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
__END__
|
|
75
|
+
# mlb = Sportradar::Api::Baseball::Mlb::Hierarchy.new
|
|
@@ -1,29 +1,96 @@
|
|
|
1
1
|
module Sportradar
|
|
2
2
|
module Api
|
|
3
3
|
module Baseball
|
|
4
|
-
class Mlb <
|
|
5
|
-
attr_accessor :
|
|
4
|
+
class Mlb < Data
|
|
5
|
+
attr_accessor :response, :id, :name, :alias, :year, :type
|
|
6
|
+
def all_attributes
|
|
7
|
+
[:name, :alias, :leagues, :divisions, :teams]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(data = {}, **opts)
|
|
11
|
+
# @response = data
|
|
12
|
+
@api = opts[:api]
|
|
13
|
+
@id = data['id']
|
|
14
|
+
@season = opts[:year]
|
|
15
|
+
@type = opts[:type]
|
|
16
|
+
|
|
17
|
+
@leagues_hash = {}
|
|
18
|
+
@games_hash = {}
|
|
19
|
+
@teams_hash = {}
|
|
20
|
+
|
|
21
|
+
update(data, **opts)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def update(data, source: nil, **opts)
|
|
25
|
+
# update stuff
|
|
26
|
+
@id = data.dig('league', 'id') if data.dig('league', 'id')
|
|
27
|
+
@name = data.dig('league', 'name') if data.dig('league', 'name')
|
|
28
|
+
@alias = data.dig('league', 'alias') if data.dig('league', 'alias')
|
|
29
|
+
|
|
30
|
+
@year = data.dig('season', 'year') if data.dig('season', 'year')
|
|
31
|
+
@type = data.dig('season', 'type') if data.dig('season', 'type')
|
|
32
|
+
|
|
33
|
+
@leagues_hash = create_data({}, data['leagues'], klass: League, hierarchy: self, api: api) if data['leagues']
|
|
34
|
+
@teams_hash = create_data({}, data['teams'], klass: Team, hierarchy: self, api: api) if data['teams']
|
|
35
|
+
if data['games'] && !data['games'].empty?
|
|
36
|
+
if data['games'].first.keys == ['game']
|
|
37
|
+
data['games'].map! { |hash| hash['game'] }
|
|
38
|
+
end
|
|
39
|
+
@games_hash = create_data({}, data['games'], klass: Game, hierarchy: self, api: api)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
6
42
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@access_level = access_level
|
|
43
|
+
def schedule
|
|
44
|
+
get_schedule if games.empty?
|
|
45
|
+
self
|
|
11
46
|
end
|
|
12
47
|
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
-
|
|
48
|
+
def standings
|
|
49
|
+
get_standings if teams.first&.record.nil?
|
|
50
|
+
self
|
|
16
51
|
end
|
|
17
52
|
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
53
|
+
def hierarchy
|
|
54
|
+
get_hierarchy if divisions.empty?
|
|
55
|
+
self
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def daily_schedule
|
|
59
|
+
# TODO
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def games
|
|
63
|
+
@games_hash.values
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def leagues
|
|
67
|
+
@leagues_hash.values
|
|
68
|
+
end
|
|
69
|
+
def divisions
|
|
70
|
+
leagues.flat_map(&:divisions)
|
|
71
|
+
end
|
|
72
|
+
def teams
|
|
73
|
+
teams = divisions.flat_map(&:teams)
|
|
74
|
+
if teams.empty?
|
|
75
|
+
if @teams_hash.empty?
|
|
76
|
+
get_hierarchy
|
|
77
|
+
divisions.flat_map(&:teams)
|
|
78
|
+
else
|
|
79
|
+
@teams_hash.values
|
|
80
|
+
end
|
|
81
|
+
else
|
|
82
|
+
teams
|
|
25
83
|
end
|
|
26
|
-
|
|
84
|
+
end
|
|
85
|
+
def team(team_id)
|
|
86
|
+
teams.detect { |team| team.id == team_id }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# api stuff
|
|
92
|
+
def api
|
|
93
|
+
@api || Sportradar::Api::Baseball::Mlb::Api.new
|
|
27
94
|
end
|
|
28
95
|
|
|
29
96
|
def default_year
|
|
@@ -35,50 +102,174 @@ module Sportradar
|
|
|
35
102
|
def default_season
|
|
36
103
|
'reg'
|
|
37
104
|
end
|
|
38
|
-
def
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
end
|
|
105
|
+
def season_year
|
|
106
|
+
@year || default_year
|
|
107
|
+
end
|
|
108
|
+
def mlb_season
|
|
109
|
+
@type || default_season
|
|
44
110
|
end
|
|
45
111
|
|
|
46
|
-
|
|
47
|
-
|
|
112
|
+
|
|
113
|
+
# url paths
|
|
114
|
+
def path_base
|
|
115
|
+
"league"
|
|
116
|
+
end
|
|
117
|
+
def path_schedule
|
|
118
|
+
"games/#{season_year}/#{mlb_season}/schedule"
|
|
119
|
+
end
|
|
120
|
+
def path_series
|
|
121
|
+
"series/#{season_year}/#{mlb_season}/schedule"
|
|
122
|
+
end
|
|
123
|
+
def path_rankings
|
|
124
|
+
"seasontd/#{season_year}/#{mlb_season}/rankings"
|
|
125
|
+
end
|
|
126
|
+
def path_hierarchy
|
|
127
|
+
"#{ path_base }/hierarchy"
|
|
128
|
+
end
|
|
129
|
+
def path_depth_charts
|
|
130
|
+
"#{ path_base }/depth_charts"
|
|
131
|
+
end
|
|
132
|
+
def path_standings
|
|
133
|
+
"seasontd/#{season_year}/#{mlb_season}/standings"
|
|
134
|
+
end
|
|
135
|
+
def path_daily_summary(date)
|
|
136
|
+
"games/#{date.year}/#{date.month}/#{date.day}/summary"
|
|
137
|
+
end
|
|
138
|
+
def path_daily_boxscore(date)
|
|
139
|
+
"#{ path_base }/games/#{date.year}/#{date.month}/#{date.day}/boxscore"
|
|
48
140
|
end
|
|
49
141
|
|
|
50
|
-
private
|
|
51
142
|
|
|
52
|
-
|
|
53
|
-
|
|
143
|
+
# data retrieval
|
|
144
|
+
|
|
145
|
+
## schedule
|
|
146
|
+
def get_schedule
|
|
147
|
+
data = api.get_data(path_schedule).to_h
|
|
148
|
+
ingest_schedule(data)
|
|
54
149
|
end
|
|
55
150
|
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
151
|
+
def ingest_schedule(data)
|
|
152
|
+
update(data, source: :games)
|
|
153
|
+
data
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def queue_schedule
|
|
157
|
+
url, headers, options, timeout = api.get_request_info(path_schedule)
|
|
158
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
## hierarchy
|
|
162
|
+
def get_hierarchy
|
|
163
|
+
data = api.get_data(path_hierarchy).to_h
|
|
164
|
+
ingest_hierarchy(data)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def ingest_hierarchy(data)
|
|
168
|
+
update(data, source: :teams)
|
|
169
|
+
data
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def queue_hierarchy
|
|
173
|
+
url, headers, options, timeout = api.get_request_info(path_hierarchy)
|
|
174
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_hierarchy)}
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
## depth_charts
|
|
178
|
+
def get_depth_charts
|
|
179
|
+
data = api.get_data(path_depth_charts).to_h
|
|
180
|
+
ingest_depth_charts(data)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def ingest_depth_charts(data)
|
|
184
|
+
update(data, source: :teams)
|
|
185
|
+
data
|
|
64
186
|
end
|
|
65
187
|
|
|
66
|
-
def
|
|
67
|
-
|
|
188
|
+
def queue_depth_charts
|
|
189
|
+
url, headers, options, timeout = api.get_request_info(path_depth_charts)
|
|
190
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_depth_charts)}
|
|
68
191
|
end
|
|
69
192
|
|
|
70
|
-
|
|
71
|
-
|
|
193
|
+
## standings
|
|
194
|
+
def get_standings
|
|
195
|
+
data = api.get_data(path_standings).to_h
|
|
196
|
+
ingest_standings(data)
|
|
72
197
|
end
|
|
73
198
|
|
|
74
|
-
def
|
|
75
|
-
|
|
199
|
+
def ingest_standings(data)
|
|
200
|
+
update(data.dig('league','season'), source: :teams)
|
|
201
|
+
data
|
|
76
202
|
end
|
|
77
203
|
|
|
204
|
+
def queue_standings
|
|
205
|
+
url, headers, options, timeout = api.get_request_info(path_standings)
|
|
206
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_standings)}
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
## depth_charts
|
|
210
|
+
def get_depth_charts
|
|
211
|
+
data = api.get_data(path_depth_charts).to_h
|
|
212
|
+
ingest_depth_charts(data)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def ingest_depth_charts(data)
|
|
216
|
+
update(data, source: :teams)
|
|
217
|
+
data
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def queue_depth_charts
|
|
221
|
+
url, headers, options, timeout = api.get_request_info(path_depth_charts)
|
|
222
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_depth_charts)}
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
## daily summary
|
|
226
|
+
def get_daily_summary(date = Date.today)
|
|
227
|
+
data = api.get_data(path_daily_summary(date)).to_h
|
|
228
|
+
ingest_daily_summary(data)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def ingest_daily_summary(data)
|
|
232
|
+
update(data.dig('league'), source: :games)
|
|
233
|
+
data
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def queue_daily_summary(date = Date.today)
|
|
237
|
+
url, headers, options, timeout = api.get_request_info(path_daily_summary(date))
|
|
238
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_daily_summary)}
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
## venues
|
|
242
|
+
# def get_venues
|
|
243
|
+
# data = api.get_data(path_venues).to_h
|
|
244
|
+
# ingest_venues(data)
|
|
245
|
+
# end
|
|
246
|
+
|
|
247
|
+
# def ingest_venues(data)
|
|
248
|
+
# update(data, source: :teams)
|
|
249
|
+
# data
|
|
250
|
+
# end
|
|
251
|
+
|
|
252
|
+
# def queue_venues
|
|
253
|
+
# url, headers, options, timeout = api.get_request_info(path_venues)
|
|
254
|
+
# {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_venues)}
|
|
255
|
+
# end
|
|
256
|
+
|
|
78
257
|
end
|
|
79
258
|
end
|
|
80
259
|
end
|
|
81
260
|
end
|
|
82
261
|
|
|
83
262
|
__END__
|
|
84
|
-
|
|
263
|
+
|
|
264
|
+
mlb = Sportradar::Api::Baseball::Mlb::Hierarchy.new
|
|
265
|
+
res = mlb.get_daily_summary;
|
|
266
|
+
res = mlb.get_hierarchy;
|
|
267
|
+
res = mlb.get_schedule;
|
|
268
|
+
t = mlb.teams.first;
|
|
269
|
+
t.get_season_stats;
|
|
270
|
+
t.players.sample
|
|
271
|
+
|
|
272
|
+
res = mlb.get_schedule;
|
|
273
|
+
g = mlb.games.sort_by(&:scheduled).first
|
|
274
|
+
|
|
275
|
+
portradar::Api::Baseball::Mlb::Hierarchy.new
|