Class: Sportradar::Api::Soccer::Team

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

Instance Attribute 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) ⇒ Team

Returns a new instance of Team.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sportradar/api/soccer/team.rb', line 14

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

  @players_hash = {}
  @player_stats = {}
  @matches_hash = {}

  update(data, **opts)
end

Instance Attribute Details

#abbreviationObject (readonly) Also known as: alias

Returns the value of attribute abbreviation.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def abbreviation
  @abbreviation
end

#countryObject (readonly)

Returns the value of attribute country.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def country
  @country
end

#country_codeObject (readonly)

Returns the value of attribute country_code.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def country_code
  @country_code
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def id
  @id
end

#jerseysObject (readonly)

Returns the value of attribute jerseys.



12
13
14
# File 'lib/sportradar/api/soccer/team.rb', line 12

def jerseys
  @jerseys
end

#league_groupObject (readonly)

Returns the value of attribute league_group.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def league_group
  @league_group
end

#managerObject (readonly)

Returns the value of attribute manager.



12
13
14
# File 'lib/sportradar/api/soccer/team.rb', line 12

def manager
  @manager
end

#nameObject (readonly) Also known as: market, display_name, full_name

Returns the value of attribute name.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def name
  @name
end

#player_statsObject

Returns the value of attribute player_stats.



6
7
8
# File 'lib/sportradar/api/soccer/team.rb', line 6

def player_stats
  @player_stats
end

#qualifierObject (readonly)

Returns the value of attribute qualifier.



7
8
9
# File 'lib/sportradar/api/soccer/team.rb', line 7

def qualifier
  @qualifier
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



12
13
14
# File 'lib/sportradar/api/soccer/team.rb', line 12

def statistics
  @statistics
end

#team_statsObject (readonly)

Returns the value of attribute team_stats.



12
13
14
# File 'lib/sportradar/api/soccer/team.rb', line 12

def team_stats
  @team_stats
end

#tournament_idObject

Returns the value of attribute tournament_id.



6
7
8
# File 'lib/sportradar/api/soccer/team.rb', line 6

def tournament_id
  @tournament_id
end

#venueObject

Returns the value of attribute venue.



6
7
8
# File 'lib/sportradar/api/soccer/team.rb', line 6

def venue
  @venue
end

Instance Method Details

#apiObject



91
92
93
# File 'lib/sportradar/api/soccer/team.rb', line 91

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

#get_resultsObject



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

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

#get_rosterObject



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

def get_roster
  data = api.get_data(path_roster).to_h
  ingest_roster(data)
end

#get_scheduleObject



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

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

#get_season_stats(*args) ⇒ Object



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

def get_season_stats(*args)
  get_statistics
end

#get_statistics(season_id = self.season_id) ⇒ Object



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

def get_statistics(season_id = self.season_id)
  return unless season_id
  data = api.get_data(path_statistics(season_id)).to_h
  ingest_statistics(data)
end

#get_tournament_id(data, **opts) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sportradar/api/soccer/team.rb', line 63

def get_tournament_id(data, **opts)
  @tournament_id ||= if opts[:tournament]
    opts[:tournament].id
  elsif opts[:season]&.tournament_id
    opts[:season]&.tournament_id
  elsif opts[:match]&.tournament_id
    opts[:match]&.tournament_id
  elsif data['tournament_id']
    data['tournament_id']
  elsif data['tournament']
    data.dig('tournament', 'id')
  elsif data['season']
    data.dig('season', 'tournament_id')
  end
end

#ingest_results(data) ⇒ Object



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

def ingest_results(data)
  update(data)
  data
end

#ingest_roster(data) ⇒ Object



106
107
108
109
# File 'lib/sportradar/api/soccer/team.rb', line 106

def ingest_roster(data)
  update(data)
  data
end

#ingest_schedule(data) ⇒ Object



138
139
140
141
# File 'lib/sportradar/api/soccer/team.rb', line 138

def ingest_schedule(data)
  update(data)
  data
end

#ingest_statistics(data) ⇒ Object



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

def ingest_statistics(data)
  update(data)
  data
end

#matchesObject



87
88
89
# File 'lib/sportradar/api/soccer/team.rb', line 87

def matches
  @matches_hash.values
end

#path_baseObject



95
96
97
# File 'lib/sportradar/api/soccer/team.rb', line 95

def path_base
  "competitors/#{ id }"
end

#path_resultsObject



115
116
117
# File 'lib/sportradar/api/soccer/team.rb', line 115

def path_results
  "#{ path_base }/results"
end

#path_rosterObject



99
100
101
# File 'lib/sportradar/api/soccer/team.rb', line 99

def path_roster
  "#{ path_base }/profile"
end

#path_scheduleObject



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

def path_schedule
  "#{ path_base }/schedule"
end

#path_statistics(season_id = self.season_id) ⇒ Object



151
152
153
# File 'lib/sportradar/api/soccer/team.rb', line 151

def path_statistics(season_id = self.season_id)
  "seasons/#{ season_id }/#{ path_base }/statistics"
end

#playersObject



83
84
85
# File 'lib/sportradar/api/soccer/team.rb', line 83

def players
  @players_hash.values
end

#queue_resultsObject



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

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_rosterObject



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

def queue_roster
  url, headers, options, timeout = api.get_request_info(path_roster)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_roster)}
end

#queue_scheduleObject



142
143
144
145
# File 'lib/sportradar/api/soccer/team.rb', line 142

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_statisticsObject



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

def queue_statistics
  url, headers, options, timeout = api.get_request_info(path_statistics)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_statistics)}
end

#season_idObject



147
148
149
# File 'lib/sportradar/api/soccer/team.rb', line 147

def season_id
  @season&.id
end

#update(data, **opts) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sportradar/api/soccer/team.rb', line 28

def update(data, **opts)
  @id           = data['id'] if data['id']
  @league_group = opts[:league_group] || data['league_group'] || @league_group
  # get_tournament_id(data, **opts)

  if data["team"]
    update(data["team"])
  end

  @name         = data['name']              if data['name']
  @country      = data['country']           if data['country']
  @country_code = data['country_code']      if data['country_code']
  @abbreviation = data['abbreviation']      if data['abbreviation']
  @qualifier    = data['qualifier']         if data['qualifier']
  @venue        = Venue.new(data['venue'])  if data['venue']

  create_data(@players_hash, data['players'], klass: Player, api: api, team: self, **opts) if data['players']
  create_data(@players_hash, data['player_statistics'], klass: Player, api: api, team: self, **opts) if data['player_statistics']

  @team_stats    = data['team_statistics']   if data['team_statistics']

  # parse_players(data.dig('players'), opts[:match])   if data.dig('players')
  if opts[:match]
    opts[:match].update_stats(self, data['statistics']) if data['statistics']
  end

  create_data(@matches_hash, Soccer.parse_results(data['results']), klass: Match, api: api, team: self) if data['results']
  create_data(@matches_hash, data['schedule'],  klass: Match, api: api, team: self) if data['schedule']

  # TODO roster
  @jerseys      = data['jerseys']     if data['jerseys']
  @manager      = data['manager']     if data['manager']
  @statistics   = data['statistics']  if data['statistics']
end

#update_player_stats(player, stats, game = nil) ⇒ Object



79
80
81
# File 'lib/sportradar/api/soccer/team.rb', line 79

def update_player_stats(player, stats, game = nil)
  game ? game.update_player_stats(player, stats) : @player_stats.merge(player.id => stats.to_h.merge(player: player))
end