sportradar-api 0.18.1 → 0.20.2
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 +1 -1
- data/lib/sportradar/api/football/game.rb +5 -1
- data/lib/sportradar/api/football/game_stats.rb +4 -0
- data/lib/sportradar/api/football/nfl/api.rb +5 -5
- data/lib/sportradar/api/football/nfl/team.rb +0 -4
- data/lib/sportradar/api/football/nfl.rb +14 -4
- data/lib/sportradar/api/football/player.rb +2 -2
- data/lib/sportradar/api/football/stat_pack.rb +4 -0
- data/lib/sportradar/api/football/stats_shim.rb +24 -0
- data/lib/sportradar/api/football/team.rb +3 -3
- data/lib/sportradar/api/football.rb +1 -0
- data/lib/sportradar/api/mma/api.rb +59 -0
- data/lib/sportradar/api/mma/competition.rb +62 -0
- data/lib/sportradar/api/mma/event.rb +1 -1
- data/lib/sportradar/api/mma/fight.rb +84 -45
- data/lib/sportradar/api/mma/fighter.rb +18 -18
- data/lib/sportradar/api/mma/judge.rb +2 -2
- data/lib/sportradar/api/mma/league.rb +1 -1
- data/lib/sportradar/api/mma/referee.rb +2 -2
- data/lib/sportradar/api/mma/result.rb +2 -2
- data/lib/sportradar/api/mma/roster.rb +1 -1
- data/lib/sportradar/api/mma/schedule.rb +1 -1
- data/lib/sportradar/api/mma/score.rb +2 -2
- data/lib/sportradar/api/mma/season.rb +102 -0
- data/lib/sportradar/api/mma/venue.rb +1 -1
- data/lib/sportradar/api/mma.rb +52 -167
- data/lib/sportradar/api/odds/README.md +1 -1
- data/lib/sportradar/api/odds/api.rb +1 -1
- data/lib/sportradar/api/odds/base.rb +18 -2
- data/lib/sportradar/api/odds/competition.rb +12 -4
- data/lib/sportradar/api/odds/sport_event.rb +0 -2
- data/lib/sportradar/api/request.rb +3 -2
- data/lib/sportradar/api/soccer/competition.rb +17 -0
- data/lib/sportradar/api/soccer/player.rb +5 -1
- data/lib/sportradar/api/soccer/season.rb +26 -0
- data/lib/sportradar/api/soccer/team.rb +12 -6
- data/lib/sportradar/api/version.rb +1 -1
- data/lib/sportradar/api.rb +2 -13
- metadata +6 -2
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Mma
|
|
4
|
+
class Season < Data
|
|
5
|
+
attr_reader :id, :name, :start_date, :end_date, :year, :competition_id
|
|
6
|
+
|
|
7
|
+
def initialize(data = {}, league_group: nil, **opts)
|
|
8
|
+
@response = data
|
|
9
|
+
@id = data["id"]
|
|
10
|
+
@api = opts[:api]
|
|
11
|
+
|
|
12
|
+
@fights_hash = {}
|
|
13
|
+
@fighters_hash = {}
|
|
14
|
+
|
|
15
|
+
update(data, **opts)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def update(data, **opts)
|
|
19
|
+
@name = data['name'] if data['name']
|
|
20
|
+
@start_date = Time.parse(data['start_date']) if data['start_date']
|
|
21
|
+
@end_date = Time.parse(data['end_date']) if data['end_date']
|
|
22
|
+
@year = data['year'] if data['year']
|
|
23
|
+
@competition_id = data['competition_id'] if data['competition_id']
|
|
24
|
+
|
|
25
|
+
parse_summary(data)
|
|
26
|
+
parse_competitors(data)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def fights
|
|
30
|
+
@fights_hash.values
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def fighters
|
|
34
|
+
@fighters_hash.values
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def future?
|
|
38
|
+
self.end_date > Time.now
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def parse_summary(data)
|
|
42
|
+
if data['summaries']
|
|
43
|
+
create_data(@fights_hash, data['summaries'], klass: Fight, api: api, season: self)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def parse_competitors(data)
|
|
48
|
+
if data['season_competitors']
|
|
49
|
+
create_data(@fighters_hash, data['season_competitors'], klass: Fighter, api: api, season: self)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def api
|
|
54
|
+
@api ||= Sportradar::Api::Mma::Api.new
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# url path helpers
|
|
58
|
+
def path_base
|
|
59
|
+
"seasons/#{ id }"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def path_summary
|
|
63
|
+
"#{ path_base }/summaries"
|
|
64
|
+
end
|
|
65
|
+
def get_summary
|
|
66
|
+
data = api.get_data(path_summary).to_h
|
|
67
|
+
ingest_summary(data)
|
|
68
|
+
end
|
|
69
|
+
def ingest_summary(data)
|
|
70
|
+
update(data)
|
|
71
|
+
# TODO parse the rest of the data. keys: ["tournament", "seasons"]
|
|
72
|
+
data
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def path_competitors
|
|
76
|
+
"#{ path_base }/competitors"
|
|
77
|
+
end
|
|
78
|
+
def get_competitors
|
|
79
|
+
data = api.get_data(path_competitors).to_h
|
|
80
|
+
ingest_competitors(data)
|
|
81
|
+
end
|
|
82
|
+
def ingest_competitors(data)
|
|
83
|
+
update(data)
|
|
84
|
+
# TODO parse the rest of the data. keys: ["tournament", "seasons"]
|
|
85
|
+
data
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
__END__
|
|
94
|
+
|
|
95
|
+
{
|
|
96
|
+
"id"=>"sr:season:54879",
|
|
97
|
+
"name"=>"UFC Contender Series, Las Vegas, Week 26 2018",
|
|
98
|
+
"start_date"=>"2018-06-26",
|
|
99
|
+
"end_date"=>"2018-06-28",
|
|
100
|
+
"year"=>"2018",
|
|
101
|
+
"competition_id"=>"sr:competition:25357"
|
|
102
|
+
}
|
data/lib/sportradar/api/mma.rb
CHANGED
|
@@ -1,182 +1,64 @@
|
|
|
1
|
+
require_relative "mma/api"
|
|
2
|
+
require_relative "mma/competition"
|
|
3
|
+
require_relative "mma/season"
|
|
4
|
+
require_relative "mma/schedule"
|
|
5
|
+
require_relative "mma/roster"
|
|
6
|
+
require_relative "mma/fighter"
|
|
7
|
+
require_relative "mma/event"
|
|
8
|
+
require_relative "mma/fight"
|
|
9
|
+
require_relative "mma/judge"
|
|
10
|
+
require_relative "mma/referee"
|
|
11
|
+
require_relative "mma/result"
|
|
12
|
+
require_relative "mma/score"
|
|
13
|
+
require_relative "mma/venue"
|
|
14
|
+
require_relative "mma/league"
|
|
15
|
+
|
|
1
16
|
module Sportradar
|
|
2
17
|
module Api
|
|
3
|
-
|
|
4
|
-
attr_accessor :league, :access_level, :simulation, :error
|
|
18
|
+
module Mma
|
|
5
19
|
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
|
|
9
|
-
@access_level = access_level
|
|
20
|
+
def self.parse_results(arr)
|
|
21
|
+
arr.map { |hash| hash["sport_event"].merge(hash["sport_event_status"]) }
|
|
10
22
|
end
|
|
11
23
|
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Sportradar::Api::Mma::Schedule.new(response['schedule'], api: self)
|
|
16
|
-
else
|
|
17
|
-
@error = response
|
|
18
|
-
end
|
|
24
|
+
def self.get_competitions
|
|
25
|
+
data = api.get_data(path_competitions).to_h
|
|
26
|
+
parse_competitions(data)
|
|
19
27
|
end
|
|
20
28
|
|
|
21
|
-
def
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
else
|
|
26
|
-
@error = response
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def statistics(event_id = "8f85ecc5-0d4d-470b-b357-075cc7e7bedd")
|
|
31
|
-
event_hash = {"id" => event_id } # => UFC 205 - McGregor/Alvarez
|
|
32
|
-
event = Event.new({ 'id' => event_id })
|
|
33
|
-
event.get_stats
|
|
34
|
-
end
|
|
35
|
-
def generate_simulation_event(event_id = "8f85ecc5-0d4d-470b-b357-075cc7e7bedd")
|
|
36
|
-
event = Event.new({ 'id' => event_id })
|
|
37
|
-
i = 0
|
|
38
|
-
base_path = "simulations/mma/#{event_id}"
|
|
39
|
-
FileUtils.mkdir_p(base_path)
|
|
40
|
-
loop do
|
|
41
|
-
t = Time.now
|
|
42
|
-
print "#{t}: Data pull #{i+=1}\r"
|
|
43
|
-
res = event.get_stats.body
|
|
44
|
-
File.write("#{base_path}/#{t.to_i}.xml", res)
|
|
45
|
-
wait = (t.to_i + 60 - Time.now.to_i)
|
|
46
|
-
wait.times do |j|
|
|
47
|
-
print "#{t}: Data pull #{i} complete, #{wait - j} seconds until next.\r"
|
|
48
|
-
sleep 1
|
|
29
|
+
def self.parse_competitions(data)
|
|
30
|
+
if data['competitions']
|
|
31
|
+
data['competitions'].map do |hash|
|
|
32
|
+
Competition.new(hash, api: api)
|
|
49
33
|
end
|
|
50
|
-
puts
|
|
51
34
|
end
|
|
52
35
|
end
|
|
53
36
|
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# def weekly_depth_charts(week = 1, year = Date.today.year, season = "reg" )
|
|
60
|
-
# response = get request_url("seasontd/#{ week_path(year, season, week) }/depth_charts")
|
|
61
|
-
# Sportradar::Api::Nfl::LeagueDepthChart.new response
|
|
62
|
-
# end
|
|
63
|
-
|
|
64
|
-
# def weekly_injuries(week = 1, year = Date.today.year, season = "reg")
|
|
65
|
-
# response = get request_url("seasontd/#{ week_path(year, season, week) }/injuries")
|
|
66
|
-
# Sportradar::Api::Nfl::Season.new response["season"] if response.success? && response["season"]
|
|
67
|
-
# end
|
|
68
|
-
|
|
69
|
-
# # gid = '8494fbf9-fe96-4d6d-81b2-5ed32347676f'
|
|
70
|
-
# # past_game_id = "0141a0a5-13e5-4b28-b19f-0c3923aaef6e"
|
|
71
|
-
# # future_game_id = "28290722-4ceb-4a4c-a4e5-1f9bec7283b3"
|
|
72
|
-
# def game_boxscore(game_id)
|
|
73
|
-
# check_simulation(game_id)
|
|
74
|
-
# response = get request_url("games/#{ game_id }/boxscore")
|
|
75
|
-
# Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"] # mostly done, just missing play statistics
|
|
76
|
-
# end
|
|
77
|
-
|
|
78
|
-
# def game_roster(game_id)
|
|
79
|
-
# check_simulation(game_id)
|
|
80
|
-
# response = get request_url("games/#{ game_id }/roster")
|
|
81
|
-
# Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"]
|
|
82
|
-
# end
|
|
83
|
-
|
|
84
|
-
# def game_statistics(game_data)
|
|
85
|
-
# # check_simulation(game_id)
|
|
86
|
-
# base = "#{ year }/#{ mma_season }/#{ mma_season_week }/#{ away_team}/#{ home_team }/statistics"
|
|
87
|
-
# response = get_data(base)
|
|
88
|
-
# Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"]
|
|
89
|
-
# ## Need to properly implement statistics
|
|
90
|
-
# end
|
|
91
|
-
|
|
92
|
-
# def play_by_play(game_id)
|
|
93
|
-
# check_simulation(game_id)
|
|
94
|
-
# response = get request_url("games/#{ game_id }/pbp")
|
|
95
|
-
# Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"]
|
|
96
|
-
# # need to get into quarters, drives, plays, stats more still
|
|
97
|
-
# end
|
|
98
|
-
|
|
99
|
-
# # player_id = "ede260be-5ae6-4a06-887b-e4a130932705"
|
|
100
|
-
# def player_profile(player_id)
|
|
101
|
-
# response = get request_url("players/#{ player_id }/profile")
|
|
102
|
-
# Sportradar::Api::Nfl::Player.new response["player"] if response.success? && response["player"]
|
|
103
|
-
# end
|
|
104
|
-
|
|
105
|
-
# # team_id = "97354895-8c77-4fd4-a860-32e62ea7382a"
|
|
106
|
-
# def seasonal_statistics(team_id, year = Date.today.year, season = "reg")
|
|
107
|
-
# raise Sportradar::Api::Error::InvalidLeague unless allowed_seasons.include? season
|
|
108
|
-
# response = get request_url("seasontd/#{ year }/#{ season }/teams/#{ team_id }/statistics")
|
|
109
|
-
# Sportradar::Api::Nfl::Season.new response["season"] if response.success? && response["season"]
|
|
110
|
-
# # TODO: Object map team & player records - statistics
|
|
111
|
-
# end
|
|
112
|
-
|
|
113
|
-
# def team_profile(team_id)
|
|
114
|
-
# response = get request_url("teams/#{ team_id }/profile")
|
|
115
|
-
# Sportradar::Api::Nfl::Team.new response["team"] if response.success? && response["team"]
|
|
116
|
-
# end
|
|
117
|
-
|
|
118
|
-
# def league_hierarchy
|
|
119
|
-
# response = get request_url("league/hierarchy")
|
|
120
|
-
# Sportradar::Api::Nfl::Hierarchy.new response["league"] if response.success? && response["league"]
|
|
121
|
-
# end
|
|
122
|
-
|
|
123
|
-
# def standings(year = Date.today.year)
|
|
124
|
-
# response = get request_url("seasontd/#{ year }/standings")
|
|
125
|
-
# Sportradar::Api::Nfl::Season.new response["season"] if response.success? && response["season"]
|
|
126
|
-
# # TODO Needs implement rankings/records/stats on team
|
|
127
|
-
# end
|
|
128
|
-
|
|
129
|
-
# def daily_change_log(date = Date.today)
|
|
130
|
-
# response = get request_url("league/#{date_path(date)}/changes")
|
|
131
|
-
# Sportradar::Api::Nfl::Changelog.new response["league"]["changelog"] if response.success? && response["league"] && response["league"]["changelog"]
|
|
132
|
-
# end
|
|
133
|
-
|
|
134
|
-
# def simulation_games
|
|
135
|
-
# [
|
|
136
|
-
# # "f45b4a31-b009-4039-8394-42efbc6d5532",
|
|
137
|
-
# # "5a7042cb-fe7a-4838-b93f-6b8c167ec384",
|
|
138
|
-
# # "7f761bb5-7963-43ea-a01b-baf4f5d50fe3"
|
|
139
|
-
# ]
|
|
140
|
-
# end
|
|
141
|
-
|
|
142
|
-
# def active_simulation
|
|
143
|
-
# game = simulation_games.lazy.map {|game_id| game_boxscore game_id }.find{ |game| game.status == 'inprogress'}
|
|
144
|
-
# if game
|
|
145
|
-
# puts "Live Game: #{game.summary.home.full_name} vs #{game.summary.away.full_name}. Q#{game.quarter} #{game.clock}. game_id='#{game.id}'"
|
|
146
|
-
# game
|
|
147
|
-
# else
|
|
148
|
-
# puts "No active simulation"
|
|
149
|
-
# end
|
|
150
|
-
# end
|
|
151
|
-
|
|
152
|
-
def get_data(url)
|
|
153
|
-
get request_url(url)
|
|
37
|
+
# url path helpers
|
|
38
|
+
def self.path_competitions
|
|
39
|
+
"competitions"
|
|
154
40
|
end
|
|
155
41
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
# @simulation = true if simulation_games.include?(game_id)
|
|
160
|
-
# end
|
|
161
|
-
|
|
162
|
-
def request_url(path)
|
|
163
|
-
"/mma-#{access_level}#{version}/#{path}"
|
|
42
|
+
def self.get_seasons
|
|
43
|
+
data = api.get_data(path_seasons).to_h
|
|
44
|
+
parse_seasons(data)
|
|
164
45
|
end
|
|
165
46
|
|
|
166
|
-
def
|
|
167
|
-
if
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
47
|
+
def self.parse_seasons(data)
|
|
48
|
+
if data['seasons']
|
|
49
|
+
data['seasons'].map do |hash|
|
|
50
|
+
Season.new(hash, api: api)
|
|
51
|
+
end
|
|
171
52
|
end
|
|
172
53
|
end
|
|
173
54
|
|
|
174
|
-
|
|
175
|
-
|
|
55
|
+
# url path helpers
|
|
56
|
+
def self.path_seasons
|
|
57
|
+
"seasons"
|
|
176
58
|
end
|
|
177
59
|
|
|
178
|
-
def
|
|
179
|
-
|
|
60
|
+
def self.api
|
|
61
|
+
@api ||= Sportradar::Api::Mma::Api.new
|
|
180
62
|
end
|
|
181
63
|
|
|
182
64
|
end
|
|
@@ -185,11 +67,14 @@ end
|
|
|
185
67
|
|
|
186
68
|
__END__
|
|
187
69
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
70
|
+
comps = Sportradar::Api::Mma.get_competitions;
|
|
71
|
+
comp = comps.first
|
|
72
|
+
comp.get_seasons
|
|
73
|
+
sea = comp.seasons.first
|
|
74
|
+
|
|
75
|
+
seasons = Sportradar::Api::Mma.get_seasons
|
|
76
|
+
sea = seasons.detect { |s| s.id == "sr:season:94429" }
|
|
77
|
+
sea.get_competitors
|
|
78
|
+
sea.get_summary
|
|
79
|
+
fight = sea.fights.detect { |f| f.id == "sr:sport_event:34102625" }
|
|
80
|
+
fight.title
|
|
@@ -13,7 +13,7 @@ sport.get_competitions
|
|
|
13
13
|
comp = sport.competitions.first
|
|
14
14
|
|
|
15
15
|
api = Sportradar::Api::Odds::PlayerOdds.api
|
|
16
|
-
comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:
|
|
16
|
+
comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:109'}, api: api)
|
|
17
17
|
data = comp.get_player_props
|
|
18
18
|
comp.sport_events
|
|
19
19
|
event = comp.sport_events.first
|
|
@@ -4,7 +4,7 @@ module Sportradar
|
|
|
4
4
|
class Api < Request
|
|
5
5
|
attr_accessor :access_level, :language_code, :error, :base_path
|
|
6
6
|
|
|
7
|
-
def initialize(base_path
|
|
7
|
+
def initialize(base_path:, access_level: default_access_level, language_code: 'en', **args)
|
|
8
8
|
@language_code = language_code
|
|
9
9
|
@access_level = access_level
|
|
10
10
|
@base_path = base_path
|
|
@@ -31,11 +31,27 @@ module Sportradar
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def get_event_mappings
|
|
34
|
-
data = api.get_data(path_event_mappings)
|
|
34
|
+
data = api.get_data(path_event_mappings).fetch('mappings', [])
|
|
35
|
+
if data.size == 1000
|
|
36
|
+
new_data = data
|
|
37
|
+
while new_data.size == 1000
|
|
38
|
+
new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
|
|
39
|
+
data += new_data
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
{'mappings' => data }
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
def get_player_mappings
|
|
38
|
-
data = api.get_data(path_player_mappings)
|
|
46
|
+
data = api.get_data(path_player_mappings).fetch('mappings', [])
|
|
47
|
+
if data.size == 1000
|
|
48
|
+
new_data = data
|
|
49
|
+
while new_data.size == 1000
|
|
50
|
+
new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
|
|
51
|
+
data += new_data
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
{'mappings' => data }
|
|
39
55
|
end
|
|
40
56
|
|
|
41
57
|
def get_competitor_mappings
|
|
@@ -28,13 +28,21 @@ module Sportradar
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def get_player_props
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
prop_data = fetch_player_props.fetch('competition_sport_events_players_props', [])
|
|
32
|
+
if prop_data.size > 0
|
|
33
|
+
new_data = prop_data
|
|
34
|
+
while new_data.size > 0
|
|
35
|
+
new_data = fetch_player_props(start: prop_data.size).fetch('competition_sport_events_players_props', [])
|
|
36
|
+
prop_data += new_data
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
data = {'competition_sport_events_players_props' => prop_data }
|
|
40
|
+
create_data(@sport_events_hash, prop_data, klass: SportEvent, api: api)
|
|
33
41
|
data
|
|
34
42
|
end
|
|
35
43
|
|
|
36
|
-
def fetch_player_props
|
|
37
|
-
api.get_data(path_player_props)
|
|
44
|
+
def fetch_player_props(params = {})
|
|
45
|
+
api.get_data(path_player_props, params)
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
# url path helpers
|
|
@@ -30,8 +30,6 @@ module Sportradar
|
|
|
30
30
|
def update(data, **opts)
|
|
31
31
|
create_data(@player_props_hash, data['players_props'], klass: PlayerProp, api: api) if data['players_props']
|
|
32
32
|
create_data(@player_markets_hash, data['players_markets'], klass: Market, api: api) if data['players_markets']
|
|
33
|
-
rescue => e
|
|
34
|
-
binding.pry
|
|
35
33
|
end
|
|
36
34
|
|
|
37
35
|
end
|
|
@@ -12,8 +12,8 @@ module Sportradar
|
|
|
12
12
|
self
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def get_data(url)
|
|
16
|
-
data = get
|
|
15
|
+
def get_data(url, extra_params = {})
|
|
16
|
+
data = get(request_url(url), extra_params)
|
|
17
17
|
if data.is_a?(::Sportradar::Api::Error)
|
|
18
18
|
puts request_url(url)
|
|
19
19
|
puts
|
|
@@ -56,6 +56,7 @@ module Sportradar
|
|
|
56
56
|
puts response.inspect
|
|
57
57
|
Sportradar::Api::Error.new(response.code, response.message, response)
|
|
58
58
|
else
|
|
59
|
+
File.write("response.json", JSON.pretty_generate(response.to_h)) if ENV['SPORTRADAR_LOG']
|
|
59
60
|
response
|
|
60
61
|
end
|
|
61
62
|
end
|
|
@@ -52,10 +52,27 @@ module Sportradar
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
def hierarchy
|
|
56
|
+
self.get_seasons
|
|
57
|
+
season = self.latest_season
|
|
58
|
+
season.get_competitors
|
|
59
|
+
season.competitors
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def teams
|
|
63
|
+
season = self.latest_season
|
|
64
|
+
season.get_competitors if season.competitors.empty?
|
|
65
|
+
season.competitors
|
|
66
|
+
end
|
|
67
|
+
|
|
55
68
|
def current_season
|
|
56
69
|
seasons.detect(&:current?)
|
|
57
70
|
end
|
|
58
71
|
|
|
72
|
+
def latest_season
|
|
73
|
+
seasons.max_by(&:end_date)
|
|
74
|
+
end
|
|
75
|
+
|
|
59
76
|
def standings(type = nil)
|
|
60
77
|
if type
|
|
61
78
|
@standings_hash[type]
|
|
@@ -3,7 +3,7 @@ module Sportradar
|
|
|
3
3
|
module Soccer
|
|
4
4
|
class Player < Data
|
|
5
5
|
|
|
6
|
-
attr_reader :id, :league_group, :name, :type, :nationality, :country_code, :height, :weight, :jersey_number, :preferred_foot, :stats, :game_stats, :date_of_birth, :matches_played, :starter
|
|
6
|
+
attr_reader :id, :league_group, :name, :type, :nationality, :country_code, :height, :weight, :jersey_number, :preferred_foot, :stats, :game_stats, :date_of_birth, :matches_played, :starter, :team
|
|
7
7
|
alias :position :type
|
|
8
8
|
|
|
9
9
|
def initialize(data = {}, league_group: nil, **opts)
|
|
@@ -116,6 +116,10 @@ module Sportradar
|
|
|
116
116
|
@name.split()[0].delete(',')
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
def injured?
|
|
120
|
+
false
|
|
121
|
+
end
|
|
122
|
+
|
|
119
123
|
def api
|
|
120
124
|
@api || Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
121
125
|
end
|
|
@@ -10,6 +10,7 @@ module Sportradar
|
|
|
10
10
|
@api = opts[:api]
|
|
11
11
|
@competition = competition
|
|
12
12
|
@matches_hash = {}
|
|
13
|
+
@competitors_hash = {}
|
|
13
14
|
|
|
14
15
|
update(data, **opts)
|
|
15
16
|
end
|
|
@@ -31,6 +32,7 @@ module Sportradar
|
|
|
31
32
|
@min_coverage_level = data['min_coverage_level'] || @min_coverage_level
|
|
32
33
|
|
|
33
34
|
parse_schedule(data)
|
|
35
|
+
parse_competitors(data)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
# def get_tournament_id(data, **opts)
|
|
@@ -51,12 +53,22 @@ module Sportradar
|
|
|
51
53
|
@matches_hash.values
|
|
52
54
|
end
|
|
53
55
|
|
|
56
|
+
def competitors
|
|
57
|
+
@competitors_hash.values
|
|
58
|
+
end
|
|
59
|
+
|
|
54
60
|
def parse_schedule(data)
|
|
55
61
|
if data['schedules']
|
|
56
62
|
create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self)
|
|
57
63
|
end
|
|
58
64
|
end
|
|
59
65
|
|
|
66
|
+
def parse_competitors(data)
|
|
67
|
+
if data['season_competitors']
|
|
68
|
+
create_data(@competitors_hash, data['season_competitors'], klass: Team, api: api, competition: @competition, season: self)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
60
72
|
def api
|
|
61
73
|
@api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
62
74
|
end
|
|
@@ -78,6 +90,20 @@ module Sportradar
|
|
|
78
90
|
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
79
91
|
data
|
|
80
92
|
end
|
|
93
|
+
|
|
94
|
+
def path_competitors
|
|
95
|
+
"#{ path_base }/competitors"
|
|
96
|
+
end
|
|
97
|
+
def get_competitors
|
|
98
|
+
data = api.get_data(path_competitors).to_h
|
|
99
|
+
ingest_competitors(data)
|
|
100
|
+
end
|
|
101
|
+
def ingest_competitors(data)
|
|
102
|
+
@competitors_retrieved = true
|
|
103
|
+
update(data)
|
|
104
|
+
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
105
|
+
data
|
|
106
|
+
end
|
|
81
107
|
def queue_schedule
|
|
82
108
|
url, headers, options, timeout = api.get_request_info(path_schedule)
|
|
83
109
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
@@ -15,6 +15,7 @@ module Sportradar
|
|
|
15
15
|
@response = data
|
|
16
16
|
@id = data['id']
|
|
17
17
|
@api = opts[:api]
|
|
18
|
+
@season = opts[:season]
|
|
18
19
|
@league_group = league_group || data['league_group'] || @api&.league_group
|
|
19
20
|
|
|
20
21
|
@players_hash = {}
|
|
@@ -27,7 +28,7 @@ module Sportradar
|
|
|
27
28
|
def update(data, **opts)
|
|
28
29
|
@id = data['id'] if data['id']
|
|
29
30
|
@league_group = opts[:league_group] || data['league_group'] || @league_group
|
|
30
|
-
get_tournament_id(data, **opts)
|
|
31
|
+
# get_tournament_id(data, **opts)
|
|
31
32
|
|
|
32
33
|
if data["team"]
|
|
33
34
|
update(data["team"])
|
|
@@ -92,7 +93,7 @@ module Sportradar
|
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def path_base
|
|
95
|
-
"
|
|
96
|
+
"competitors/#{ id }"
|
|
96
97
|
end
|
|
97
98
|
|
|
98
99
|
def path_roster
|
|
@@ -143,11 +144,16 @@ module Sportradar
|
|
|
143
144
|
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
144
145
|
end
|
|
145
146
|
|
|
146
|
-
def
|
|
147
|
-
|
|
147
|
+
def season_id
|
|
148
|
+
@season&.id
|
|
148
149
|
end
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
|
|
151
|
+
def path_statistics(season_id = self.season_id)
|
|
152
|
+
"seasons/#{ season_id }/#{ path_base }/statistics"
|
|
153
|
+
end
|
|
154
|
+
def get_statistics(season_id = self.season_id)
|
|
155
|
+
return unless season_id
|
|
156
|
+
data = api.get_data(path_statistics(season_id)).to_h
|
|
151
157
|
ingest_statistics(data)
|
|
152
158
|
end
|
|
153
159
|
def get_season_stats(*args)
|
data/lib/sportradar/api.rb
CHANGED
|
@@ -27,17 +27,6 @@ require "sportradar/api/images/ref"
|
|
|
27
27
|
require "sportradar/api/images/tag"
|
|
28
28
|
|
|
29
29
|
require "sportradar/api/mma"
|
|
30
|
-
require "sportradar/api/mma/schedule"
|
|
31
|
-
require "sportradar/api/mma/roster"
|
|
32
|
-
require "sportradar/api/mma/fighter"
|
|
33
|
-
require "sportradar/api/mma/event"
|
|
34
|
-
require "sportradar/api/mma/fight"
|
|
35
|
-
require "sportradar/api/mma/judge"
|
|
36
|
-
require "sportradar/api/mma/referee"
|
|
37
|
-
require "sportradar/api/mma/result"
|
|
38
|
-
require "sportradar/api/mma/score"
|
|
39
|
-
require "sportradar/api/mma/venue"
|
|
40
|
-
require "sportradar/api/mma/league"
|
|
41
30
|
|
|
42
31
|
|
|
43
32
|
require "sportradar/api/content"
|
|
@@ -50,7 +39,7 @@ module Sportradar
|
|
|
50
39
|
module Api
|
|
51
40
|
|
|
52
41
|
API_GALLERY = [
|
|
53
|
-
{api: :nfl, version:
|
|
42
|
+
{api: :nfl, version: 7},
|
|
54
43
|
{api: :mlb, version: 7},
|
|
55
44
|
{api: :nhl, version: 3},
|
|
56
45
|
{api: :nba, version: 7},
|
|
@@ -65,7 +54,7 @@ module Sportradar
|
|
|
65
54
|
{api: :olympics, version: 2},
|
|
66
55
|
{api: :soccer, version: 4},
|
|
67
56
|
{api: :ncaawb, version: 3},
|
|
68
|
-
{api: :mma, version:
|
|
57
|
+
{api: :mma, version: 2},
|
|
69
58
|
{api: :cricket, version: 1},
|
|
70
59
|
{api: :wnba, version: 3},
|
|
71
60
|
{api: :ncaamh, version: 3},
|