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

#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

#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

Class Method Details

.tournament_idsObject



232
233
234
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
# File 'lib/sportradar/api/soccer/tournament.rb', line 232

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



119
120
121
# File 'lib/sportradar/api/soccer/tournament.rb', line 119

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

#current_seasonObject



55
56
57
# File 'lib/sportradar/api/soccer/tournament.rb', line 55

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

#get_infoObject



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

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

#get_leadersObject



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

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

#get_live_standingsObject Also known as: get_standings



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

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

#get_resultsObject



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

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

#get_scheduleObject



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

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

#get_seasonsObject



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

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



71
72
73
# File 'lib/sportradar/api/soccer/tournament.rb', line 71

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

#groupsObject



67
68
69
# File 'lib/sportradar/api/soccer/tournament.rb', line 67

def groups
  @groups_hash.values
end

#ingest_info(data) ⇒ Object



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

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



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

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



136
137
138
139
140
# File 'lib/sportradar/api/soccer/tournament.rb', line 136

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

#ingest_results(data) ⇒ Object



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

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

#ingest_schedule(data) ⇒ Object



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

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



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

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

#matchesObject Also known as: games



75
76
77
# File 'lib/sportradar/api/soccer/tournament.rb', line 75

def matches
  @matches_hash.values
end

#parse_info(data) ⇒ Object

parsing helpers



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

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



100
101
102
103
104
105
# File 'lib/sportradar/api/soccer/tournament.rb', line 100

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



107
108
109
110
111
# File 'lib/sportradar/api/soccer/tournament.rb', line 107

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



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

def parse_season(data)
  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



113
114
115
116
117
# File 'lib/sportradar/api/soccer/tournament.rb', line 113

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



124
125
126
# File 'lib/sportradar/api/soccer/tournament.rb', line 124

def path_base
  "tournaments/#{ id }"
end

#path_infoObject



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

def path_info
  "#{ path_base }/info"
end

#path_leadersObject



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

def path_leaders
  "#{ path_base }/leaders"
end

#path_live_standingsObject



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

def path_live_standings
  "#{ path_base }/live_standings"
end

#path_resultsObject



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

def path_results
  "#{ path_base }/results"
end

#path_scheduleObject



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

def path_schedule
  "#{ path_base }/schedule"
end

#path_seasonsObject



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

def path_seasons
  "#{ path_base }/seasons"
end

#queue_infoObject



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

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



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

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



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

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



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

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



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

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



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

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



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

def schedule
  return self if @schedule_retrieved
  get_schedule
  self
end

#seasonsObject



39
40
41
# File 'lib/sportradar/api/soccer/tournament.rb', line 39

def seasons
  @seasons_hash.values
end

#standings(type = nil) ⇒ Object



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

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
# 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

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

#yearObject



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

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