Class: Sportradar::Api::Soccer::Tournament

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/soccer/tournament.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#all_attributes, #attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(data = {}, league_group: nil, **opts) ⇒ Tournament

Returns a new instance of Tournament.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sportradar/api/soccer/tournament.rb', line 9

def initialize(data = {}, league_group: nil, **opts)
  @response     = data
  @id           = data["id"]
  @api          = opts[:api]
  @league_group = league_group || data['league_group'] || @api&.league_group

  @matches_hash   = {}
  @seasons_hash   = {}
  @teams_hash     = {}
  @standings_hash = {}
  @groups_hash    = {}

  update(data, **opts)
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def category
  @category
end

#coverage_infoObject (readonly)

Returns the value of attribute coverage_info.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def coverage_info
  @coverage_info
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def id
  @id
end

#league_groupObject (readonly)

Returns the value of attribute league_group.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def league_group
  @league_group
end

#live_coverageObject (readonly)

Returns the value of attribute live_coverage.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def live_coverage
  @live_coverage
end

#nameObject (readonly) Also known as: display_name, alias

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def name
  @name
end

#season_coverage_infoObject (readonly)

Returns the value of attribute season_coverage_info.



5
6
7
# File 'lib/sportradar/api/soccer/tournament.rb', line 5

def season_coverage_info
  @season_coverage_info
end

Class Method Details

.tournament_idsObject



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/sportradar/api/soccer/tournament.rb', line 235

def self.tournament_ids
  @tournament_ids ||= {
    # Europe group
    'eu.uefa_champions_league'  => "sr:tournament:7",
    'eu.la_liga'                => "sr:tournament:8",
    'eu.eng_premier_league'     => "sr:tournament:17",
    'eu.premier_league'         => "sr:tournament:17",
    'eu.serie_a'                => "sr:tournament:23",
    'eu.ligue_1'                => "sr:tournament:34",
    'eu.bundesliga'             => "sr:tournament:35",
    'eu.eredivisie'             => "sr:tournament:37",
    'eu.first_division_a'       => "sr:tournament:38",
    'eu.super_lig'              => "sr:tournament:52",
    'eu.super_league'           => "sr:tournament:185",
    'eu.rus_premier_league'     => "sr:tournament:203",
    'eu.ukr_premier_league'     => "sr:tournament:218",
    'eu.primeira_liga'          => "sr:tournament:238",
    'eu.uefa_super_cup'         => "sr:tournament:465",
    'eu.uefa_europa_league'     => "sr:tournament:679",
    'eu.uefa_youth_league'      => "sr:tournament:2324",
    # international (partial listing)
    "intl.world_cup"              => "sr:tournament:16",
    "intl.copa_america"           => "sr:tournament:133",
    "intl.gold_cup"               => "sr:tournament:140",
    "intl.africa_cup_of_nations"  => "sr:tournament:270",
    "intl.womens_world_cup"       => "sr:tournament:290",
    "intl.olympic_games"          => "sr:tournament:436",
    "intl.olympic_games_women"    => "sr:tournament:437",
    # other groups below
  }
end

Instance Method Details

#apiObject



122
123
124
# File 'lib/sportradar/api/soccer/tournament.rb', line 122

def api
  @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
end

#current_seasonObject



57
58
59
# File 'lib/sportradar/api/soccer/tournament.rb', line 57

def current_season
  seasons.detect(&:current?)
end

#get_infoObject



204
205
206
207
# File 'lib/sportradar/api/soccer/tournament.rb', line 204

def get_info
  data = api.get_data(path_info).to_h
  ingest_info(data)
end

#get_leadersObject



221
222
223
224
# File 'lib/sportradar/api/soccer/tournament.rb', line 221

def get_leaders
  data = api.get_data(path_leaders).to_h
  ingest_leaders(data)
end

#get_live_standingsObject Also known as: get_standings



134
135
136
137
# File 'lib/sportradar/api/soccer/tournament.rb', line 134

def get_live_standings
  data = api.get_data(path_live_standings).to_h
  ingest_live_standings(data)
end

#get_resultsObject



152
153
154
155
# File 'lib/sportradar/api/soccer/tournament.rb', line 152

def get_results
  data = api.get_data(path_results).to_h
  ingest_results(data)
end

#get_scheduleObject



169
170
171
172
# File 'lib/sportradar/api/soccer/tournament.rb', line 169

def get_schedule
  data = api.get_data(path_schedule).to_h
  ingest_schedule(data)
end

#get_seasonsObject



187
188
189
190
# File 'lib/sportradar/api/soccer/tournament.rb', line 187

def get_seasons
  data = api.get_data(path_seasons).to_h
  ingest_seasons(data)
end

#group(name = nil) ⇒ Object

nil represents the complete team listing



73
74
75
# File 'lib/sportradar/api/soccer/tournament.rb', line 73

def group(name = nil) # nil represents the complete team listing
  @groups_hash[name]
end

#groupsObject



69
70
71
# File 'lib/sportradar/api/soccer/tournament.rb', line 69

def groups
  @groups_hash.values
end

#ingest_info(data) ⇒ Object



208
209
210
211
212
# File 'lib/sportradar/api/soccer/tournament.rb', line 208

def ingest_info(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "season", "round", "season_coverage_info", "coverage_info", "groups"]
  data
end

#ingest_leaders(data) ⇒ Object



225
226
227
228
229
# File 'lib/sportradar/api/soccer/tournament.rb', line 225

def ingest_leaders(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "season_coverage_info", "top_points", "top_goals", "top_assists", "top_cards", "top_own_goals"]
  data
end

#ingest_live_standings(data) ⇒ Object



139
140
141
142
143
# File 'lib/sportradar/api/soccer/tournament.rb', line 139

def ingest_live_standings(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "season", "standings"]
  data
end

#ingest_results(data) ⇒ Object



156
157
158
159
160
# File 'lib/sportradar/api/soccer/tournament.rb', line 156

def ingest_results(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "results"]
  data
end

#ingest_schedule(data) ⇒ Object



173
174
175
176
177
178
# File 'lib/sportradar/api/soccer/tournament.rb', line 173

def ingest_schedule(data)
  @schedule_retrieved = true
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "sport_events"]
  data
end

#ingest_seasons(data) ⇒ Object



191
192
193
194
195
# File 'lib/sportradar/api/soccer/tournament.rb', line 191

def ingest_seasons(data)
  update(data)
  # TODO parse the rest of the data. keys: ["tournament", "seasons"]
  data
end

#matchesObject Also known as: games



77
78
79
# File 'lib/sportradar/api/soccer/tournament.rb', line 77

def matches
  @matches_hash.values
end

#parse_info(data) ⇒ Object

parsing helpers



83
84
85
86
87
# File 'lib/sportradar/api/soccer/tournament.rb', line 83

def parse_info(data)
  if data['groups']
    create_data(@groups_hash, data['groups'], klass: TeamGroup, api: api, tournament: self, identifier: 'name')
  end
end

#parse_results(data) ⇒ Object



103
104
105
106
107
108
# File 'lib/sportradar/api/soccer/tournament.rb', line 103

def parse_results(data)
  if data['results']
    merged_data = Soccer.parse_results(data['results'])
    create_data(@matches_hash, merged_data, klass: Match, api: api, tournament: self)
  end
end

#parse_schedule(data) ⇒ Object



110
111
112
113
114
# File 'lib/sportradar/api/soccer/tournament.rb', line 110

def parse_schedule(data)
  if data['sport_events']
    create_data(@matches_hash, data['sport_events'], klass: Match, api: api, tournament: self)
  end
end

#parse_season(data) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/sportradar/api/soccer/tournament.rb', line 89

def parse_season(data)
  if data['season_coverage_info']
    @season_coverage_info = data['season_coverage_info'] if data['season_coverage_info']
    data['season_coverage_info']['id'] ||= data['season_coverage_info'].delete('season_id')
    create_data(@seasons_hash, data['season_coverage_info'], klass: Season, api: api, tournament: self)
  end
  if data['current_season']
    create_data(@seasons_hash, data['current_season'], klass: Season, api: api, tournament: self, current: true)
  end
  if data['seasons']
    create_data(@seasons_hash, data['seasons'], klass: Season, api: api, tournament: self)
  end
end

#parse_standings(data) ⇒ Object



116
117
118
119
120
# File 'lib/sportradar/api/soccer/tournament.rb', line 116

def parse_standings(data)
  if data['standings']
    create_data(@standings_hash, data['standings'], klass: Standing, api: api, tournament: self, identifier: 'type')
  end
end

#path_baseObject

url path helpers



127
128
129
# File 'lib/sportradar/api/soccer/tournament.rb', line 127

def path_base
  "tournaments/#{ id }"
end

#path_infoObject



201
202
203
# File 'lib/sportradar/api/soccer/tournament.rb', line 201

def path_info
  "#{ path_base }/info"
end

#path_leadersObject



218
219
220
# File 'lib/sportradar/api/soccer/tournament.rb', line 218

def path_leaders
  "#{ path_base }/leaders"
end

#path_live_standingsObject



131
132
133
# File 'lib/sportradar/api/soccer/tournament.rb', line 131

def path_live_standings
  "#{ path_base }/live_standings"
end

#path_resultsObject



149
150
151
# File 'lib/sportradar/api/soccer/tournament.rb', line 149

def path_results
  "#{ path_base }/results"
end

#path_scheduleObject



166
167
168
# File 'lib/sportradar/api/soccer/tournament.rb', line 166

def path_schedule
  "#{ path_base }/schedule"
end

#path_seasonsObject



184
185
186
# File 'lib/sportradar/api/soccer/tournament.rb', line 184

def path_seasons
  "#{ path_base }/seasons"
end

#queue_infoObject



213
214
215
216
# File 'lib/sportradar/api/soccer/tournament.rb', line 213

def queue_info
  url, headers, options, timeout = api.get_request_info(path_info)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_info)}
end

#queue_leadersObject



230
231
232
233
# File 'lib/sportradar/api/soccer/tournament.rb', line 230

def queue_leaders
  url, headers, options, timeout = api.get_request_leaders(path_leaders)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_leaders)}
end

#queue_live_standingsObject



144
145
146
147
# File 'lib/sportradar/api/soccer/tournament.rb', line 144

def queue_live_standings
  url, headers, options, timeout = api.get_request_info(path_live_standings)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_live_standings)}
end

#queue_resultsObject



161
162
163
164
# File 'lib/sportradar/api/soccer/tournament.rb', line 161

def queue_results
  url, headers, options, timeout = api.get_request_info(path_results)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_results)}
end

#queue_scheduleObject



179
180
181
182
# File 'lib/sportradar/api/soccer/tournament.rb', line 179

def queue_schedule
  url, headers, options, timeout = api.get_request_info(path_schedule)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
end

#queue_seasonsObject



196
197
198
199
# File 'lib/sportradar/api/soccer/tournament.rb', line 196

def queue_seasons
  url, headers, options, timeout = api.get_request_info(path_seasons)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_seasons)}
end

#scheduleObject



45
46
47
48
49
# File 'lib/sportradar/api/soccer/tournament.rb', line 45

def schedule
  return self if @schedule_retrieved
  get_schedule
  self
end

#seasonsObject



41
42
43
# File 'lib/sportradar/api/soccer/tournament.rb', line 41

def seasons
  @seasons_hash.values
end

#standings(type = nil) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/sportradar/api/soccer/tournament.rb', line 61

def standings(type = nil)
  if type
    @standings_hash[type]
  else
    @standings_hash.values
  end
end

#update(data, **opts) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sportradar/api/soccer/tournament.rb', line 24

def update(data, **opts)
  if data['tournament']
    update(data['tournament'])
  end

  @name           = data["name"]          || @name
  @category       = data['category']      || @category
  @coverage_info  = data['coverage_info'] || @coverage_info
  @live_coverage  = data.dig('coverage_info', 'live_coverage') || @live_coverage

  parse_info(data)
  parse_season(data)
  parse_results(data)
  parse_schedule(data)
  parse_standings(data)
end

#yearObject



51
52
53
54
55
# File 'lib/sportradar/api/soccer/tournament.rb', line 51

def year
  if current_season&.year&.split('/')&.last
    2000 + current_season.year.split('/').last.to_i
  end
end