Class: Sportradar::Api::Soccer::Competition
- Defined in:
- lib/sportradar/api/soccer/competition.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#coverage_info ⇒ Object
readonly
Returns the value of attribute coverage_info.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#league_group ⇒ Object
readonly
Returns the value of attribute league_group.
-
#live_coverage ⇒ Object
readonly
Returns the value of attribute live_coverage.
-
#name ⇒ Object
(also: #display_name, #alias)
readonly
Returns the value of attribute name.
-
#season_coverage_info ⇒ Object
readonly
Returns the value of attribute season_coverage_info.
Class Method Summary collapse
Instance Method Summary collapse
- #api ⇒ Object
- #current_season ⇒ Object
- #get_info ⇒ Object
- #get_leaders ⇒ Object
- #get_live_standings ⇒ Object (also: #get_standings)
- #get_results ⇒ Object
- #get_seasons ⇒ Object
-
#group(name = nil) ⇒ Object
nil represents the complete team listing.
- #groups ⇒ Object
- #ingest_info(data) ⇒ Object
- #ingest_leaders(data) ⇒ Object
- #ingest_live_standings(data) ⇒ Object
- #ingest_results(data) ⇒ Object
- #ingest_seasons(data) ⇒ Object
-
#initialize(data = {}, league_group: nil, **opts) ⇒ Competition
constructor
A new instance of Competition.
- #matches ⇒ Object (also: #games)
-
#parse_info(data) ⇒ Object
parsing helpers.
- #parse_results(data) ⇒ Object
- #parse_season(data) ⇒ Object
- #parse_standings(data) ⇒ Object
-
#path_base ⇒ Object
url path helpers.
- #path_info ⇒ Object
- #path_leaders ⇒ Object
- #path_live_standings ⇒ Object
- #path_results ⇒ Object
- #path_seasons ⇒ Object
- #queue_info ⇒ Object
- #queue_leaders ⇒ Object
- #queue_live_standings ⇒ Object
- #queue_results ⇒ Object
- #queue_seasons ⇒ Object
- #schedule ⇒ Object
- #seasons ⇒ Object
- #standings(type = nil) ⇒ Object
- #update(data, **opts) ⇒ Object
- #year ⇒ Object
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) ⇒ Competition
Returns a new instance of Competition.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sportradar/api/soccer/competition.rb', line 9 def initialize(data = {}, league_group: nil, **opts) @response = data @id = data["id"] @api = opts[:api] @seasons_hash = {} @teams_hash = {} @standings_hash = {} @groups_hash = {} update(data, **opts) end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def category @category end |
#coverage_info ⇒ Object (readonly)
Returns the value of attribute coverage_info.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def coverage_info @coverage_info end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def id @id end |
#league_group ⇒ Object (readonly)
Returns the value of attribute league_group.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def league_group @league_group end |
#live_coverage ⇒ Object (readonly)
Returns the value of attribute live_coverage.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def live_coverage @live_coverage end |
#name ⇒ Object (readonly) Also known as: display_name, alias
Returns the value of attribute name.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def name @name end |
#season_coverage_info ⇒ Object (readonly)
Returns the value of attribute season_coverage_info.
5 6 7 |
# File 'lib/sportradar/api/soccer/competition.rb', line 5 def season_coverage_info @season_coverage_info end |
Class Method Details
.tournament_ids ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/sportradar/api/soccer/competition.rb', line 209 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
#api ⇒ Object
114 115 116 |
# File 'lib/sportradar/api/soccer/competition.rb', line 114 def api @api ||= Sportradar::Api::Soccer::Api.new end |
#current_season ⇒ Object
55 56 57 |
# File 'lib/sportradar/api/soccer/competition.rb', line 55 def current_season seasons.detect(&:current?) end |
#get_info ⇒ Object
178 179 180 181 |
# File 'lib/sportradar/api/soccer/competition.rb', line 178 def get_info data = api.get_data(path_info).to_h ingest_info(data) end |
#get_leaders ⇒ Object
195 196 197 198 |
# File 'lib/sportradar/api/soccer/competition.rb', line 195 def get_leaders data = api.get_data(path_leaders).to_h ingest_leaders(data) end |
#get_live_standings ⇒ Object Also known as: get_standings
126 127 128 129 |
# File 'lib/sportradar/api/soccer/competition.rb', line 126 def get_live_standings data = api.get_data(path_live_standings).to_h ingest_live_standings(data) end |
#get_results ⇒ Object
144 145 146 147 |
# File 'lib/sportradar/api/soccer/competition.rb', line 144 def get_results data = api.get_data(path_results).to_h ingest_results(data) end |
#get_seasons ⇒ Object
161 162 163 164 |
# File 'lib/sportradar/api/soccer/competition.rb', line 161 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/competition.rb', line 71 def group(name = nil) # nil represents the complete team listing @groups_hash[name] end |
#groups ⇒ Object
67 68 69 |
# File 'lib/sportradar/api/soccer/competition.rb', line 67 def groups @groups_hash.values end |
#ingest_info(data) ⇒ Object
182 183 184 185 186 |
# File 'lib/sportradar/api/soccer/competition.rb', line 182 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
199 200 201 202 203 |
# File 'lib/sportradar/api/soccer/competition.rb', line 199 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
131 132 133 134 135 |
# File 'lib/sportradar/api/soccer/competition.rb', line 131 def ingest_live_standings(data) update(data) # TODO parse the rest of the data. keys: ["tournament", "season", "standings"] data end |
#ingest_results(data) ⇒ Object
148 149 150 151 152 |
# File 'lib/sportradar/api/soccer/competition.rb', line 148 def ingest_results(data) update(data) # TODO parse the rest of the data. keys: ["tournament", "results"] data end |
#ingest_seasons(data) ⇒ Object
165 166 167 168 169 |
# File 'lib/sportradar/api/soccer/competition.rb', line 165 def ingest_seasons(data) update(data) # TODO parse the rest of the data. keys: ["tournament", "seasons"] data end |
#matches ⇒ Object Also known as: games
75 76 77 |
# File 'lib/sportradar/api/soccer/competition.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/competition.rb', line 81 def parse_info(data) if data['groups'] create_data(@groups_hash, data['groups'], klass: TeamGroup, api: api, competition: self, identifier: 'name') end end |
#parse_results(data) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/sportradar/api/soccer/competition.rb', line 101 def parse_results(data) if data['results'] merged_data = Soccer.parse_results(data['results']) create_data(@matches_hash, merged_data, klass: Match, api: api, competition: self) end end |
#parse_season(data) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sportradar/api/soccer/competition.rb', line 87 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, competition: self) end if data['current_season'] create_data(@seasons_hash, data['current_season'], klass: Season, api: api, competition: self, current: true) end if data['seasons'] create_data(@seasons_hash, data['seasons'], klass: Season, api: api, competition: self) end end |
#parse_standings(data) ⇒ Object
108 109 110 111 112 |
# File 'lib/sportradar/api/soccer/competition.rb', line 108 def parse_standings(data) if data['standings'] create_data(@standings_hash, data['standings'], klass: Standing, api: api, competition: self, identifier: 'type') end end |
#path_base ⇒ Object
url path helpers
119 120 121 |
# File 'lib/sportradar/api/soccer/competition.rb', line 119 def path_base "competitions/#{ id }" end |
#path_info ⇒ Object
175 176 177 |
# File 'lib/sportradar/api/soccer/competition.rb', line 175 def path_info "#{ path_base }/info" end |
#path_leaders ⇒ Object
192 193 194 |
# File 'lib/sportradar/api/soccer/competition.rb', line 192 def path_leaders "#{ path_base }/leaders" end |
#path_live_standings ⇒ Object
123 124 125 |
# File 'lib/sportradar/api/soccer/competition.rb', line 123 def path_live_standings "#{ path_base }/live_standings" end |
#path_results ⇒ Object
141 142 143 |
# File 'lib/sportradar/api/soccer/competition.rb', line 141 def path_results "#{ path_base }/results" end |
#path_seasons ⇒ Object
158 159 160 |
# File 'lib/sportradar/api/soccer/competition.rb', line 158 def path_seasons "#{ path_base }/seasons" end |
#queue_info ⇒ Object
187 188 189 190 |
# File 'lib/sportradar/api/soccer/competition.rb', line 187 def queue_info url, headers, , timeout = api.get_request_info(path_info) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_info)} end |
#queue_leaders ⇒ Object
204 205 206 207 |
# File 'lib/sportradar/api/soccer/competition.rb', line 204 def queue_leaders url, headers, , timeout = api.get_request_leaders(path_leaders) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_leaders)} end |
#queue_live_standings ⇒ Object
136 137 138 139 |
# File 'lib/sportradar/api/soccer/competition.rb', line 136 def queue_live_standings url, headers, , timeout = api.get_request_info(path_live_standings) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_live_standings)} end |
#queue_results ⇒ Object
153 154 155 156 |
# File 'lib/sportradar/api/soccer/competition.rb', line 153 def queue_results url, headers, , timeout = api.get_request_info(path_results) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_results)} end |
#queue_seasons ⇒ Object
170 171 172 173 |
# File 'lib/sportradar/api/soccer/competition.rb', line 170 def queue_seasons url, headers, , timeout = api.get_request_info(path_seasons) {url: url, headers: headers, params: , timeout: timeout, callback: method(:ingest_seasons)} end |
#schedule ⇒ Object
43 44 45 46 47 |
# File 'lib/sportradar/api/soccer/competition.rb', line 43 def schedule return self if @schedule_retrieved get_schedule self end |
#seasons ⇒ Object
39 40 41 |
# File 'lib/sportradar/api/soccer/competition.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/competition.rb', line 59 def standings(type = nil) if type @standings_hash[type] else @standings_hash.values end end |
#update(data, **opts) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sportradar/api/soccer/competition.rb', line 22 def update(data, **opts) # if data['tournament'] # update(data['tournament']) # end @name = data["name"] || @name @category = data['category'] || @category @gender = data['gender'] || @gender @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_standings(data) end |
#year ⇒ Object
49 50 51 52 53 |
# File 'lib/sportradar/api/soccer/competition.rb', line 49 def year if current_season&.year&.split('/')&.last 2000 + current_season.year.split('/').last.to_i end end |