sportradar-api 0.16.1 → 0.17.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 +1 -1
- data/lib/sportradar/api/baseball/game.rb +1 -0
- data/lib/sportradar/api/baseball/lineup.rb +8 -0
- data/lib/sportradar/api/soccer/api.rb +9 -9
- data/lib/sportradar/api/soccer/competition.rb +305 -0
- data/lib/sportradar/api/soccer/match.rb +6 -8
- data/lib/sportradar/api/soccer/player.rb +5 -3
- data/lib/sportradar/api/soccer/season.rb +49 -14
- data/lib/sportradar/api/soccer.rb +36 -0
- data/lib/sportradar/api/version.rb +1 -1
- data/lib/sportradar/api.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a456ec84238b00a6b77763c51917de5e380335b1be878fb4755d335531d7401d
|
|
4
|
+
data.tar.gz: bf510aacb660110abf17d267776f83f83971b707eb13f24bffc50faea43c28f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff2cde29e9059572973754151c2a363dc840301b9547d096b6db5f8b132358dfb39032d676902ca350d6d219c03e773dc7685a2eb4d1ffbfc5f367ee54e3f69b
|
|
7
|
+
data.tar.gz: e2433afe0e456e364d62c9c69ca488b052e7982724b3102f3e41926daeced18ec0a403bb474627fba8ba51a49883ba20bcca802baee4962b7b71c2c9810d58db
|
data/Gemfile.lock
CHANGED
|
@@ -28,6 +28,14 @@ module Sportradar
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def full_home
|
|
32
|
+
@home_team_lineup
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def full_away
|
|
36
|
+
@away_team_lineup
|
|
37
|
+
end
|
|
38
|
+
|
|
31
39
|
def update_from_lineup_event(data)
|
|
32
40
|
if data.dig('team_id') == game.home_id
|
|
33
41
|
update_home(data, data.dig('order'))
|
|
@@ -4,11 +4,11 @@ module Sportradar
|
|
|
4
4
|
class Api < Request
|
|
5
5
|
attr_accessor :league_group, :access_level, :language_code, :error
|
|
6
6
|
|
|
7
|
-
def initialize(access_level: default_access_level,
|
|
7
|
+
def initialize(access_level: default_access_level, language_code: 'en', **args)
|
|
8
8
|
@league_group = league_group
|
|
9
9
|
@language_code = language_code
|
|
10
10
|
@access_level = access_level
|
|
11
|
-
raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? @league_group
|
|
11
|
+
# raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? @league_group
|
|
12
12
|
raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? @access_level
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -20,9 +20,9 @@ module Sportradar
|
|
|
20
20
|
end
|
|
21
21
|
def default_access_level
|
|
22
22
|
if (ENV['SPORTRADAR_SOCCER_ENV'] || ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
|
|
23
|
-
'
|
|
23
|
+
'production'
|
|
24
24
|
else
|
|
25
|
-
'
|
|
25
|
+
'trial'
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -33,14 +33,14 @@ module Sportradar
|
|
|
33
33
|
private
|
|
34
34
|
|
|
35
35
|
def request_url(path)
|
|
36
|
-
"/soccer
|
|
36
|
+
"/soccer/#{access_level}/v#{version}/#{language_code}/#{path}"
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def api_key
|
|
40
|
-
if !['
|
|
41
|
-
Sportradar::Api.api_key_params("soccer
|
|
40
|
+
if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
|
|
41
|
+
Sportradar::Api.api_key_params("soccer", 'production')
|
|
42
42
|
else
|
|
43
|
-
Sportradar::Api.api_key_params("soccer
|
|
43
|
+
Sportradar::Api.api_key_params("soccer")
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ module Sportradar
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def allowed_access_levels
|
|
52
|
-
%w[
|
|
52
|
+
%w[production trial sim]
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def allowed_leagues
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
module Sportradar
|
|
2
|
+
module Api
|
|
3
|
+
module Soccer
|
|
4
|
+
class Competition < Data
|
|
5
|
+
attr_reader :id, :league_group, :name, :category, :coverage_info, :live_coverage, :season_coverage_info
|
|
6
|
+
alias :display_name :name
|
|
7
|
+
alias :alias :name
|
|
8
|
+
|
|
9
|
+
def initialize(data = {}, league_group: nil, **opts)
|
|
10
|
+
@response = data
|
|
11
|
+
@id = data["id"]
|
|
12
|
+
@api = opts[:api]
|
|
13
|
+
|
|
14
|
+
@seasons_hash = {}
|
|
15
|
+
@teams_hash = {}
|
|
16
|
+
@standings_hash = {}
|
|
17
|
+
@groups_hash = {}
|
|
18
|
+
|
|
19
|
+
update(data, **opts)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def update(data, **opts)
|
|
23
|
+
# if data['tournament']
|
|
24
|
+
# update(data['tournament'])
|
|
25
|
+
# end
|
|
26
|
+
|
|
27
|
+
@name = data["name"] || @name
|
|
28
|
+
@category = data['category'] || @category
|
|
29
|
+
@gender = data['gender'] || @gender
|
|
30
|
+
@coverage_info = data['coverage_info'] || @coverage_info
|
|
31
|
+
@live_coverage = data.dig('coverage_info', 'live_coverage') || @live_coverage
|
|
32
|
+
|
|
33
|
+
# parse_info(data)
|
|
34
|
+
parse_season(data)
|
|
35
|
+
# parse_results(data)
|
|
36
|
+
# parse_standings(data)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def seasons
|
|
40
|
+
@seasons_hash.values
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def schedule
|
|
44
|
+
return self if @schedule_retrieved
|
|
45
|
+
get_schedule
|
|
46
|
+
self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def year
|
|
50
|
+
if current_season&.year&.split('/')&.last
|
|
51
|
+
2000 + current_season.year.split('/').last.to_i
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def current_season
|
|
56
|
+
seasons.detect(&:current?)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def standings(type = nil)
|
|
60
|
+
if type
|
|
61
|
+
@standings_hash[type]
|
|
62
|
+
else
|
|
63
|
+
@standings_hash.values
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def groups
|
|
68
|
+
@groups_hash.values
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def group(name = nil) # nil represents the complete team listing
|
|
72
|
+
@groups_hash[name]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def matches
|
|
76
|
+
@matches_hash.values
|
|
77
|
+
end
|
|
78
|
+
alias :games :matches
|
|
79
|
+
|
|
80
|
+
# parsing helpers
|
|
81
|
+
def parse_info(data)
|
|
82
|
+
if data['groups']
|
|
83
|
+
create_data(@groups_hash, data['groups'], klass: TeamGroup, api: api, competition: self, identifier: 'name')
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def parse_season(data)
|
|
88
|
+
if data['season_coverage_info']
|
|
89
|
+
@season_coverage_info = data['season_coverage_info'] if data['season_coverage_info']
|
|
90
|
+
data['season_coverage_info']['id'] ||= data['season_coverage_info'].delete('season_id')
|
|
91
|
+
create_data(@seasons_hash, data['season_coverage_info'], klass: Season, api: api, competition: self)
|
|
92
|
+
end
|
|
93
|
+
if data['current_season']
|
|
94
|
+
create_data(@seasons_hash, data['current_season'], klass: Season, api: api, competition: self, current: true)
|
|
95
|
+
end
|
|
96
|
+
if data['seasons']
|
|
97
|
+
create_data(@seasons_hash, data['seasons'], klass: Season, api: api, competition: self)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def parse_results(data)
|
|
102
|
+
if data['results']
|
|
103
|
+
merged_data = Soccer.parse_results(data['results'])
|
|
104
|
+
create_data(@matches_hash, merged_data, klass: Match, api: api, competition: self)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def parse_standings(data)
|
|
109
|
+
if data['standings']
|
|
110
|
+
create_data(@standings_hash, data['standings'], klass: Standing, api: api, competition: self, identifier: 'type')
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def api
|
|
115
|
+
@api ||= Sportradar::Api::Soccer::Api.new
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# url path helpers
|
|
119
|
+
def path_base
|
|
120
|
+
"competitions/#{ id }"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def path_live_standings
|
|
124
|
+
"#{ path_base }/live_standings"
|
|
125
|
+
end
|
|
126
|
+
def get_live_standings
|
|
127
|
+
data = api.get_data(path_live_standings).to_h
|
|
128
|
+
ingest_live_standings(data)
|
|
129
|
+
end
|
|
130
|
+
alias :get_standings :get_live_standings
|
|
131
|
+
def ingest_live_standings(data)
|
|
132
|
+
update(data)
|
|
133
|
+
# TODO parse the rest of the data. keys: ["tournament", "season", "standings"]
|
|
134
|
+
data
|
|
135
|
+
end
|
|
136
|
+
def queue_live_standings
|
|
137
|
+
url, headers, options, timeout = api.get_request_info(path_live_standings)
|
|
138
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_live_standings)}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def path_results
|
|
142
|
+
"#{ path_base }/results"
|
|
143
|
+
end
|
|
144
|
+
def get_results
|
|
145
|
+
data = api.get_data(path_results).to_h
|
|
146
|
+
ingest_results(data)
|
|
147
|
+
end
|
|
148
|
+
def ingest_results(data)
|
|
149
|
+
update(data)
|
|
150
|
+
# TODO parse the rest of the data. keys: ["tournament", "results"]
|
|
151
|
+
data
|
|
152
|
+
end
|
|
153
|
+
def queue_results
|
|
154
|
+
url, headers, options, timeout = api.get_request_info(path_results)
|
|
155
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_results)}
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def path_seasons
|
|
159
|
+
"#{ path_base }/seasons"
|
|
160
|
+
end
|
|
161
|
+
def get_seasons
|
|
162
|
+
data = api.get_data(path_seasons).to_h
|
|
163
|
+
ingest_seasons(data)
|
|
164
|
+
end
|
|
165
|
+
def ingest_seasons(data)
|
|
166
|
+
update(data)
|
|
167
|
+
# TODO parse the rest of the data. keys: ["tournament", "seasons"]
|
|
168
|
+
data
|
|
169
|
+
end
|
|
170
|
+
def queue_seasons
|
|
171
|
+
url, headers, options, timeout = api.get_request_info(path_seasons)
|
|
172
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_seasons)}
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def path_info
|
|
176
|
+
"#{ path_base }/info"
|
|
177
|
+
end
|
|
178
|
+
def get_info
|
|
179
|
+
data = api.get_data(path_info).to_h
|
|
180
|
+
ingest_info(data)
|
|
181
|
+
end
|
|
182
|
+
def ingest_info(data)
|
|
183
|
+
update(data)
|
|
184
|
+
# TODO parse the rest of the data. keys: ["tournament", "season", "round", "season_coverage_info", "coverage_info", "groups"]
|
|
185
|
+
data
|
|
186
|
+
end
|
|
187
|
+
def queue_info
|
|
188
|
+
url, headers, options, timeout = api.get_request_info(path_info)
|
|
189
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_info)}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def path_leaders
|
|
193
|
+
"#{ path_base }/leaders"
|
|
194
|
+
end
|
|
195
|
+
def get_leaders
|
|
196
|
+
data = api.get_data(path_leaders).to_h
|
|
197
|
+
ingest_leaders(data)
|
|
198
|
+
end
|
|
199
|
+
def ingest_leaders(data)
|
|
200
|
+
update(data)
|
|
201
|
+
# TODO parse the rest of the data. keys: ["tournament", "season_coverage_info", "top_points", "top_goals", "top_assists", "top_cards", "top_own_goals"]
|
|
202
|
+
data
|
|
203
|
+
end
|
|
204
|
+
def queue_leaders
|
|
205
|
+
url, headers, options, timeout = api.get_request_leaders(path_leaders)
|
|
206
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_leaders)}
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def self.tournament_ids
|
|
210
|
+
@tournament_ids ||= {
|
|
211
|
+
# Europe group
|
|
212
|
+
'eu.uefa_champions_league' => "sr:tournament:7",
|
|
213
|
+
'eu.la_liga' => "sr:tournament:8",
|
|
214
|
+
'eu.eng_premier_league' => "sr:tournament:17",
|
|
215
|
+
'eu.premier_league' => "sr:tournament:17",
|
|
216
|
+
'eu.serie_a' => "sr:tournament:23",
|
|
217
|
+
'eu.ligue_1' => "sr:tournament:34",
|
|
218
|
+
'eu.bundesliga' => "sr:tournament:35",
|
|
219
|
+
'eu.eredivisie' => "sr:tournament:37",
|
|
220
|
+
'eu.first_division_a' => "sr:tournament:38",
|
|
221
|
+
'eu.super_lig' => "sr:tournament:52",
|
|
222
|
+
'eu.super_league' => "sr:tournament:185",
|
|
223
|
+
'eu.rus_premier_league' => "sr:tournament:203",
|
|
224
|
+
'eu.ukr_premier_league' => "sr:tournament:218",
|
|
225
|
+
'eu.primeira_liga' => "sr:tournament:238",
|
|
226
|
+
'eu.uefa_super_cup' => "sr:tournament:465",
|
|
227
|
+
'eu.uefa_europa_league' => "sr:tournament:679",
|
|
228
|
+
'eu.uefa_youth_league' => "sr:tournament:2324",
|
|
229
|
+
# international (partial listing)
|
|
230
|
+
"intl.world_cup" => "sr:tournament:16",
|
|
231
|
+
"intl.copa_america" => "sr:tournament:133",
|
|
232
|
+
"intl.gold_cup" => "sr:tournament:140",
|
|
233
|
+
"intl.africa_cup_of_nations" => "sr:tournament:270",
|
|
234
|
+
"intl.womens_world_cup" => "sr:tournament:290",
|
|
235
|
+
"intl.olympic_games" => "sr:tournament:436",
|
|
236
|
+
"intl.olympic_games_women" => "sr:tournament:437",
|
|
237
|
+
# other groups below
|
|
238
|
+
}
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
self.tournament_ids.each do |tour_name, tour_id|
|
|
242
|
+
group_code, name = tour_name.split('.')
|
|
243
|
+
# define_singleton_method(name) { Sportradar::Api::Soccer::Tournament.new({'id' => tour_id}, league_group: group_code) }
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
__END__
|
|
252
|
+
|
|
253
|
+
{"id"=>"sr:tournament:17",
|
|
254
|
+
"name"=>"Premier League",
|
|
255
|
+
"sport"=>{"id"=>"sr:sport:1", "name"=>"Soccer"},
|
|
256
|
+
"category"=>{"id"=>"sr:category:1", "name"=>"England", "country_code"=>"ENG"},
|
|
257
|
+
"current_season"=>{"id"=>"sr:season:40942", "name"=>"Premier League 17/18", "start_date"=>"2017-08-11", "end_date"=>"2018-05-14", "year"=>"17/18"},
|
|
258
|
+
"season_coverage_info"=>{"season_id"=>"sr:season:40942", "scheduled"=>381, "played"=>70, "max_coverage_level"=>"platinum", "max_covered"=>70, "min_coverage_level"=>"platinum"}}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
group = Sportradar::Api::Soccer::Group.new(league_group: 'eu')
|
|
262
|
+
res = group.get_tournaments;
|
|
263
|
+
tour = group.tournaments.sample
|
|
264
|
+
tour.get_seasons
|
|
265
|
+
tour.get_results
|
|
266
|
+
res = tour.get_schedule
|
|
267
|
+
tour.matches.size
|
|
268
|
+
tour
|
|
269
|
+
|
|
270
|
+
group = Sportradar::Api::Soccer::Group.new(league_group: 'eu')
|
|
271
|
+
res = group.get_tournaments;
|
|
272
|
+
infos = group.tournaments.map{|tour| sleep 1; tour.get_info }
|
|
273
|
+
standings = group.tournaments.map{|tour| sleep 1; tour.get_standings }
|
|
274
|
+
results = group.tournaments.each{|tour| sleep 1; tour.get_results }.flat_map(&:matches)
|
|
275
|
+
standings = group.tournaments.map{|tour| sleep 1; (tour.get_standings rescue nil) }
|
|
276
|
+
|
|
277
|
+
{"UEFA Champions League"=>"sr:tournament:7",
|
|
278
|
+
"LaLiga"=>"sr:tournament:8",
|
|
279
|
+
"Premier League"=>"sr:tournament:218",
|
|
280
|
+
"Serie A"=>"sr:tournament:23",
|
|
281
|
+
"Ligue 1"=>"sr:tournament:34",
|
|
282
|
+
"Bundesliga"=>"sr:tournament:35",
|
|
283
|
+
"Eredivisie"=>"sr:tournament:37",
|
|
284
|
+
"First Division A"=>"sr:tournament:38",
|
|
285
|
+
"Super Lig"=>"sr:tournament:52",
|
|
286
|
+
"Super League"=>"sr:tournament:185",
|
|
287
|
+
"Primeira Liga"=>"sr:tournament:238",
|
|
288
|
+
"UEFA Super Cup"=>"sr:tournament:465",
|
|
289
|
+
"UEFA Europa League"=>"sr:tournament:679",
|
|
290
|
+
"UEFA Youth League"=>"sr:tournament:2324"}
|
|
291
|
+
|
|
292
|
+
sample_leagues = [:la_liga, :eng_premier_league, :bundesliga, :serie_a, :ligue_1]
|
|
293
|
+
tours = sample_leagues.map { |code| Sportradar::Api::Soccer::Tournament.send(code) }
|
|
294
|
+
tours.each{|t| sleep 1; t.get_info }
|
|
295
|
+
teams = tours.flat_map(&:groups).flat_map(&:teams)
|
|
296
|
+
teams.each { |t| sleep 1; t.get_roster }
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
sample_leagues = [:la_liga, :eng_premier_league, :bundesliga, :serie_a, :ligue_1];
|
|
300
|
+
tours = sample_leagues.map { |code| Sportradar::Api::Soccer::Tournament.send(code) };
|
|
301
|
+
tours.each{|t| sleep 1; t.get_info };
|
|
302
|
+
tours.flat_map(&:groups).flat_map(&:teams);
|
|
303
|
+
teams = tours.flat_map(&:groups).flat_map(&:teams);
|
|
304
|
+
teams.each { |t| sleep 1; t.get_roster };
|
|
305
|
+
teams.map {|t| ["#{t.tournament_id} #{t.name}",t.jerseys]}.to_h
|
|
@@ -10,18 +10,18 @@ module Sportradar
|
|
|
10
10
|
attr_reader :match_time, :stoppage_time
|
|
11
11
|
attr_reader :team_stats, :player_stats
|
|
12
12
|
|
|
13
|
-
def initialize(data = {},
|
|
13
|
+
def initialize(data = {}, season: nil, **opts)
|
|
14
14
|
@response = data
|
|
15
|
-
@id = data['id']
|
|
15
|
+
@id = data['id'] || data.dig("sport_event", 'id')
|
|
16
16
|
@api = opts[:api]
|
|
17
|
+
@season = season
|
|
17
18
|
@updates = {}
|
|
18
19
|
@changes = {}
|
|
19
20
|
|
|
20
|
-
@league_group = league_group || data['league_group'] || @api&.league_group
|
|
21
21
|
|
|
22
22
|
@timeline_hash = {}
|
|
23
23
|
@lineups_hash = {}
|
|
24
|
-
get_tournament_id(data, **opts)
|
|
24
|
+
# get_tournament_id(data, **opts)
|
|
25
25
|
@scoring_raw = Scoring.new(data, game: self)
|
|
26
26
|
@home = Team.new(data['home'].to_h, api: api, match: self)
|
|
27
27
|
@away = Team.new(data['away'].to_h, api: api, match: self)
|
|
@@ -34,8 +34,6 @@ module Sportradar
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def update(data, **opts)
|
|
37
|
-
@league_group = opts[:league_group] || data['league_group'] || @league_group
|
|
38
|
-
get_tournament_id(data, **opts)
|
|
39
37
|
if data["sport_event"]
|
|
40
38
|
update(data["sport_event"])
|
|
41
39
|
end
|
|
@@ -52,7 +50,7 @@ module Sportradar
|
|
|
52
50
|
if data['lineups']
|
|
53
51
|
create_data(@lineups_hash, data['lineups'], klass: Lineup, identifier: 'team', api: api)
|
|
54
52
|
end
|
|
55
|
-
if (stats = data.dig('statistics', '
|
|
53
|
+
if (stats = data.dig('statistics', 'totals', 'competitors'))
|
|
56
54
|
update_teams(stats)
|
|
57
55
|
end
|
|
58
56
|
|
|
@@ -252,7 +250,7 @@ module Sportradar
|
|
|
252
250
|
end
|
|
253
251
|
|
|
254
252
|
def path_base
|
|
255
|
-
"
|
|
253
|
+
"sport_events/#{ id }"
|
|
256
254
|
end
|
|
257
255
|
|
|
258
256
|
def path_summary
|
|
@@ -40,9 +40,11 @@ module Sportradar
|
|
|
40
40
|
@date_of_birth = Date.parse(data['date_of_birth']) if data['date_of_birth']
|
|
41
41
|
set_game_stats(data)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if data['statistics'] && @team
|
|
44
|
+
@team.update_player_stats(self, data['statistics'])
|
|
45
|
+
if opts[:match]
|
|
46
|
+
@team.update_player_stats(self, data['statistics'], opts[:match])
|
|
47
|
+
end
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
end
|
|
@@ -2,13 +2,14 @@ module Sportradar
|
|
|
2
2
|
module Api
|
|
3
3
|
module Soccer
|
|
4
4
|
class Season < Data
|
|
5
|
-
attr_reader :id, :league_group, :name, :category, :current_season, :season_coverage_info, :
|
|
5
|
+
attr_reader :id, :league_group, :name, :category, :current_season, :season_coverage_info, :competition, :start_date, :end_date
|
|
6
6
|
|
|
7
|
-
def initialize(data = {},
|
|
7
|
+
def initialize(data = {}, competition: nil, **opts)
|
|
8
8
|
@response = data
|
|
9
9
|
@id = data["id"]
|
|
10
10
|
@api = opts[:api]
|
|
11
|
-
@
|
|
11
|
+
@competition = competition
|
|
12
|
+
@matches_hash = {}
|
|
12
13
|
|
|
13
14
|
update(data, **opts)
|
|
14
15
|
end
|
|
@@ -17,7 +18,7 @@ module Sportradar
|
|
|
17
18
|
@league_group = opts[:league_group] || data['league_group'] || @league_group
|
|
18
19
|
@id = data['id'] || data['season_id'] || @id
|
|
19
20
|
@current = opts[:current] || @current
|
|
20
|
-
get_tournament_id(data, **opts)
|
|
21
|
+
# get_tournament_id(data, **opts)
|
|
21
22
|
|
|
22
23
|
@name = data['name'] || @name
|
|
23
24
|
@start_date = data['start_date'] || @start_date
|
|
@@ -28,26 +29,60 @@ module Sportradar
|
|
|
28
29
|
@max_coverage_level = data['max_coverage_level'] || @max_coverage_level
|
|
29
30
|
@max_covered = data['max_covered'] || @max_covered
|
|
30
31
|
@min_coverage_level = data['min_coverage_level'] || @min_coverage_level
|
|
31
|
-
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
@tournament_id ||= if opts[:tournament]
|
|
35
|
-
opts[:tournament].id
|
|
36
|
-
elsif data['tournament_id']
|
|
37
|
-
data['tournament_id']
|
|
38
|
-
elsif data['tournament']
|
|
39
|
-
data.dig('tournament', 'id')
|
|
40
|
-
end
|
|
33
|
+
parse_schedule(data)
|
|
41
34
|
end
|
|
42
35
|
|
|
36
|
+
# def get_tournament_id(data, **opts)
|
|
37
|
+
# @tournament_id ||= if opts[:tournament]
|
|
38
|
+
# opts[:tournament].id
|
|
39
|
+
# elsif data['tournament_id']
|
|
40
|
+
# data['tournament_id']
|
|
41
|
+
# elsif data['tournament']
|
|
42
|
+
# data.dig('tournament', 'id')
|
|
43
|
+
# end
|
|
44
|
+
# end
|
|
45
|
+
|
|
43
46
|
def current?
|
|
44
47
|
!!@current
|
|
45
48
|
end
|
|
46
49
|
|
|
50
|
+
def matches
|
|
51
|
+
@matches_hash.values
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def parse_schedule(data)
|
|
55
|
+
if data['schedules']
|
|
56
|
+
create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
47
60
|
def api
|
|
48
61
|
@api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
|
|
49
62
|
end
|
|
50
63
|
|
|
64
|
+
def path_base
|
|
65
|
+
"seasons/#{@id}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def path_schedule
|
|
69
|
+
"#{ path_base }/schedules"
|
|
70
|
+
end
|
|
71
|
+
def get_schedule
|
|
72
|
+
data = api.get_data(path_schedule).to_h
|
|
73
|
+
ingest_schedule(data)
|
|
74
|
+
end
|
|
75
|
+
def ingest_schedule(data)
|
|
76
|
+
@schedule_retrieved = true
|
|
77
|
+
update(data)
|
|
78
|
+
# TODO parse the rest of the data. keys: ["tournament", "sport_events"]
|
|
79
|
+
data
|
|
80
|
+
end
|
|
81
|
+
def queue_schedule
|
|
82
|
+
url, headers, options, timeout = api.get_request_info(path_schedule)
|
|
83
|
+
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
|
|
84
|
+
end
|
|
85
|
+
|
|
51
86
|
end
|
|
52
87
|
end
|
|
53
88
|
end
|
|
@@ -62,4 +97,4 @@ group = Sportradar::Api::Soccer::Group.new(league_group: 'eu')
|
|
|
62
97
|
res = group.get_tournaments;
|
|
63
98
|
tour = group.tournaments.sample
|
|
64
99
|
tour.get_seasons
|
|
65
|
-
tour
|
|
100
|
+
tour
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require_relative 'soccer/api'
|
|
2
2
|
require_relative 'soccer/group'
|
|
3
3
|
require_relative 'soccer/tournament'
|
|
4
|
+
require_relative 'soccer/competition'
|
|
4
5
|
require_relative 'soccer/standing'
|
|
5
6
|
require_relative 'soccer/team_group'
|
|
6
7
|
require_relative 'soccer/season'
|
|
@@ -20,6 +21,41 @@ module Sportradar
|
|
|
20
21
|
def self.parse_results(arr)
|
|
21
22
|
arr.map { |hash| hash["sport_event"].merge(hash["sport_event_status"]) }
|
|
22
23
|
end
|
|
24
|
+
|
|
25
|
+
def self.get_competitions
|
|
26
|
+
data = api.get_data(path_competitions).to_h
|
|
27
|
+
parse_competitions(data)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.parse_competitions(data)
|
|
31
|
+
if data['competitions']
|
|
32
|
+
data['competitions'].map do |hash|
|
|
33
|
+
Competition.new(hash, api: api)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.api
|
|
39
|
+
@api ||= Sportradar::Api::Soccer::Api.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# url path helpers
|
|
43
|
+
def self.path_competitions
|
|
44
|
+
"competitions"
|
|
45
|
+
end
|
|
46
|
+
|
|
23
47
|
end
|
|
24
48
|
end
|
|
25
49
|
end
|
|
50
|
+
|
|
51
|
+
__END__
|
|
52
|
+
|
|
53
|
+
comps = Sportradar::Api::Soccer.get_competitions;
|
|
54
|
+
comp = comps.detect { |comp| comp.id == 'sr:competition:27466' }
|
|
55
|
+
comp = comps.third;
|
|
56
|
+
comp.get_seasons;
|
|
57
|
+
season = comp.seasons.last;
|
|
58
|
+
resp = season.get_schedule;
|
|
59
|
+
season.matches.size;
|
|
60
|
+
match = season.matches.first;
|
|
61
|
+
data = match.get_summary
|
data/lib/sportradar/api.rb
CHANGED
|
@@ -63,7 +63,7 @@ module Sportradar
|
|
|
63
63
|
{api: :images, version: 3},
|
|
64
64
|
{api: :live_images, version: 1},
|
|
65
65
|
{api: :olympics, version: 2},
|
|
66
|
-
{api: :soccer, version:
|
|
66
|
+
{api: :soccer, version: 4},
|
|
67
67
|
{api: :ncaawb, version: 3},
|
|
68
68
|
{api: :mma, version: 1},
|
|
69
69
|
{api: :cricket, version: 1},
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sportradar-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Eggett
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-04-
|
|
11
|
+
date: 2022-04-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -408,6 +408,7 @@ files:
|
|
|
408
408
|
- lib/sportradar/api/soccer.rb
|
|
409
409
|
- lib/sportradar/api/soccer/README.md
|
|
410
410
|
- lib/sportradar/api/soccer/api.rb
|
|
411
|
+
- lib/sportradar/api/soccer/competition.rb
|
|
411
412
|
- lib/sportradar/api/soccer/event.rb
|
|
412
413
|
- lib/sportradar/api/soccer/fact.rb
|
|
413
414
|
- lib/sportradar/api/soccer/group.rb
|