sportradar-api 0.13.24 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: efcf47e5a6970b82c0795211958c277f99dcf61d
4
- data.tar.gz: 7b786d9ae02be5189fdecad0306621c701bdd3d5
2
+ SHA256:
3
+ metadata.gz: a456ec84238b00a6b77763c51917de5e380335b1be878fb4755d335531d7401d
4
+ data.tar.gz: bf510aacb660110abf17d267776f83f83971b707eb13f24bffc50faea43c28f0
5
5
  SHA512:
6
- metadata.gz: 4b810969dc532fc4d48ed7e508a8751d6e808bdc0bbafed3030c521cd2c61faa4ca71ec990201bdc28a02beddc7a37a9509bb77c1fd2e21f6d48e515f138492b
7
- data.tar.gz: 39e1ed6c33019876d4bd1b9ad58e0c6fc93149e3f927d049e74ca3ce41d6033615c0c9620414bec1710a3eaa2e5624350e64256e1244cc87e5fe6c898db4be3e
6
+ metadata.gz: ff2cde29e9059572973754151c2a363dc840301b9547d096b6db5f8b132358dfb39032d676902ca350d6d219c03e773dc7685a2eb4d1ffbfc5f367ee54e3f69b
7
+ data.tar.gz: e2433afe0e456e364d62c9c69ca488b052e7982724b3102f3e41926daeced18ec0a403bb474627fba8ba51a49883ba20bcca802baee4962b7b71c2c9810d58db
data/Gemfile.lock CHANGED
@@ -1,24 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.13.24)
4
+ sportradar-api (0.17.0)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.1.4)
11
+ activesupport (6.1.5)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (~> 0.7)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
16
17
  addressable (2.5.1)
17
18
  public_suffix (~> 2.0, >= 2.0.2)
18
19
  codeclimate-test-reporter (1.0.8)
19
20
  simplecov (<= 0.13)
20
21
  coderay (1.1.1)
21
- concurrent-ruby (1.0.5)
22
+ concurrent-ruby (1.1.9)
22
23
  coveralls (0.8.19)
23
24
  json (>= 1.8, < 3)
24
25
  simplecov (~> 0.12.0)
@@ -28,54 +29,29 @@ GEM
28
29
  crack (0.4.3)
29
30
  safe_yaml (~> 1.0.0)
30
31
  docile (1.1.5)
31
- dotenv (2.2.1)
32
- ffi (1.9.18)
33
- formatador (0.2.5)
34
- guard (2.14.1)
35
- formatador (>= 0.2.4)
36
- listen (>= 2.7, < 4.0)
37
- lumberjack (~> 1.0)
38
- nenv (~> 0.1)
39
- notiffany (~> 0.0)
40
- pry (>= 0.9.12)
41
- shellany (~> 0.0)
42
- thor (>= 0.18.1)
43
- guard-compat (1.2.1)
44
- guard-minitest (2.4.6)
45
- guard-compat (~> 1.2)
46
- minitest (>= 3.0)
32
+ dotenv (2.7.6)
47
33
  hashdiff (0.3.4)
48
- httparty (0.15.6)
34
+ httparty (0.20.0)
35
+ mime-types (~> 3.0)
49
36
  multi_xml (>= 0.5.2)
50
- i18n (0.9.5)
37
+ i18n (1.10.0)
51
38
  concurrent-ruby (~> 1.0)
52
39
  json (2.1.0)
53
- listen (3.1.5)
54
- rb-fsevent (~> 0.9, >= 0.9.4)
55
- rb-inotify (~> 0.9, >= 0.9.7)
56
- ruby_dep (~> 1.2)
57
- lumberjack (1.0.12)
58
40
  method_source (0.8.2)
41
+ mime-types (3.4.1)
42
+ mime-types-data (~> 3.2015)
43
+ mime-types-data (3.2022.0105)
59
44
  minitest (5.10.2)
60
45
  minitest-focus (1.1.2)
61
46
  minitest (>= 4, < 6)
62
47
  multi_xml (0.6.0)
63
- nenv (0.3.0)
64
- notiffany (0.1.1)
65
- nenv (~> 0.1)
66
- shellany (~> 0.0)
67
48
  pry (0.10.4)
68
49
  coderay (~> 1.1.0)
69
50
  method_source (~> 0.8.1)
70
51
  slop (~> 3.4)
71
52
  public_suffix (2.0.5)
72
53
  rake (10.5.0)
73
- rb-fsevent (0.9.8)
74
- rb-inotify (0.9.10)
75
- ffi (>= 0.5.0, < 2)
76
- ruby_dep (1.5.0)
77
54
  safe_yaml (1.0.4)
78
- shellany (0.0.1)
79
55
  simplecov (0.12.0)
80
56
  docile (~> 1.1.0)
81
57
  json (>= 1.8, < 3)
@@ -85,15 +61,15 @@ GEM
85
61
  term-ansicolor (1.6.0)
86
62
  tins (~> 1.0)
87
63
  thor (0.19.4)
88
- thread_safe (0.3.6)
89
64
  tins (1.14.0)
90
- tzinfo (1.2.5)
91
- thread_safe (~> 0.1)
65
+ tzinfo (2.0.4)
66
+ concurrent-ruby (~> 1.0)
92
67
  vcr (3.0.3)
93
68
  webmock (3.0.1)
94
69
  addressable (>= 2.3.6)
95
70
  crack (>= 0.3.2)
96
71
  hashdiff
72
+ zeitwerk (2.5.4)
97
73
 
98
74
  PLATFORMS
99
75
  ruby
@@ -103,8 +79,6 @@ DEPENDENCIES
103
79
  codeclimate-test-reporter
104
80
  coveralls
105
81
  dotenv
106
- guard
107
- guard-minitest
108
82
  minitest (~> 5.0)
109
83
  minitest-focus
110
84
  pry
@@ -115,4 +89,4 @@ DEPENDENCIES
115
89
  webmock
116
90
 
117
91
  BUNDLED WITH
118
- 1.15.3
92
+ 1.17.2
@@ -43,6 +43,10 @@ module Sportradar
43
43
  {}
44
44
  end
45
45
 
46
+ def period
47
+ @innings
48
+ end
49
+
46
50
  def tied?
47
51
  @score[away_id].to_i == @score[home_id].to_i
48
52
  end
@@ -103,6 +107,7 @@ module Sportradar
103
107
  end
104
108
 
105
109
  def update(data, source: nil, **opts)
110
+ @response.merge!(data)
106
111
  # via pbp
107
112
  @status = data['status'] if data['status']
108
113
  @coverage = data['coverage'] if data['coverage']
@@ -350,6 +355,10 @@ module Sportradar
350
355
  }.freeze[self.count['inning_half']]
351
356
  end
352
357
 
358
+ def clock
359
+ half_short
360
+ end
361
+
353
362
  def postponed?
354
363
  'postponed' == status
355
364
  end
@@ -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'))
@@ -27,9 +27,9 @@ module Sportradar
27
27
  end
28
28
  def default_access_level
29
29
  if (ENV['SPORTRADAR_ENV_MLB'] || ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
30
- 'p'
30
+ 'production'
31
31
  else
32
- 't'
32
+ 'trial'
33
33
  end
34
34
  end
35
35
 
@@ -40,11 +40,11 @@ module Sportradar
40
40
  private
41
41
 
42
42
  def request_url(path)
43
- "/mlb-#{access_level}#{version}/#{path}"
43
+ "/mlb/#{access_level}/v#{version}/en/#{path}"
44
44
  end
45
45
 
46
46
  def api_key
47
- if !['t', 'sim'].include?(access_level)
47
+ if !['trial', 'sim'].include?(access_level)
48
48
  Sportradar::Api.api_key_params('mlb', 'production')
49
49
  elsif 'sim' == access_level
50
50
  Sportradar::Api.api_key_params('mlb', 'simulation')
@@ -58,7 +58,7 @@ module Sportradar
58
58
  end
59
59
 
60
60
  def allowed_access_levels
61
- %w[p t sim]
61
+ %w[production trial sim]
62
62
  end
63
63
 
64
64
  def allowed_seasons
@@ -128,7 +128,7 @@ module Sportradar
128
128
  "teams/#{ id }"
129
129
  end
130
130
  def path_base_stats(season_year = api.default_year, default_season = api.default_season)
131
- "seasontd/#{season_year}/#{default_season}/teams/#{id}"
131
+ "seasons/#{season_year}/#{default_season}/teams/#{id}"
132
132
  end
133
133
  def path_roster
134
134
  "#{ path_base }/profile"
@@ -2,7 +2,7 @@ module Sportradar
2
2
  module Api
3
3
  module Basketball
4
4
  class Game < Data
5
- attr_accessor :response, :id, :title, :home_id, :away_id, :score, :status, :coverage, :scheduled, :venue, :broadcast, :clock, :duration, :attendance, :team_stats, :player_stats, :changes, :media_timeouts
5
+ attr_accessor :response, :id, :title, :home_id, :away_id, :score, :status, :coverage, :time_zone, :scheduled, :venue, :broadcast, :clock, :duration, :attendance, :team_stats, :player_stats, :changes, :media_timeouts
6
6
 
7
7
  attr_accessor :period
8
8
  @all_hash = {}
@@ -94,6 +94,7 @@ module Sportradar
94
94
  @away = team_class.new(data['away'], api: api, game: self) if data['away']
95
95
  @title = data['title'] || @title || (home && away && "#{home.full_name} vs #{away.full_name}")
96
96
 
97
+ @time_zone = data.dig("time_zones", "venue") if data.dig("time_zones", "venue")
97
98
  @duration = data['duration'] if data['duration']
98
99
  @clock = data['clock'] if data['clock']
99
100
  @attendance = data['attendance'] if data['attendance']
@@ -22,9 +22,9 @@ module Sportradar
22
22
  end
23
23
  def default_access_level
24
24
  if (ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
25
- 'p'
25
+ 'production'
26
26
  else
27
- 't'
27
+ 'trial'
28
28
  end
29
29
  end
30
30
 
@@ -35,11 +35,11 @@ module Sportradar
35
35
  private
36
36
 
37
37
  def request_url(path)
38
- "/nba-#{access_level}#{version}/#{path}"
38
+ "/nba/#{access_level}/v#{version}/en/#{path}"
39
39
  end
40
40
 
41
41
  def api_key
42
- if !['t', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'p')
42
+ if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
43
43
  Sportradar::Api.api_key_params('nba', 'production')
44
44
  else
45
45
  Sportradar::Api.api_key_params('nba')
@@ -51,7 +51,7 @@ module Sportradar
51
51
  end
52
52
 
53
53
  def allowed_access_levels
54
- %w[p t sim]
54
+ %w[production trial sim]
55
55
  end
56
56
 
57
57
  def allowed_seasons
@@ -3,7 +3,7 @@ module Sportradar
3
3
  module Basketball
4
4
  class Nba
5
5
  class Player < Data
6
- attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :stats
6
+ attr_accessor :response, :id, :number, :full_name, :first_name, :last_name, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :stats, :team, :not_playing_reason, :not_playing_description
7
7
  # @all_hash = {}
8
8
  # def self.new(data, **opts)
9
9
  # existing = @all_hash[data['id']]
@@ -57,6 +57,8 @@ module Sportradar
57
57
  @experience = data['experience'] if data['experience'] # "3",
58
58
  @birth_place = data['birth_place'].gsub(',,', ', ') if data['birth_place'] # "Benin City,, NGA",
59
59
  @updated = data['updated'] if data['updated'] # "2016-07-08T12:11:59+00:00",
60
+ @not_playing_reason = data['not_playing_reason'] if data['not_playing_reason'] # "Inactive - Injury/Illness"
61
+ @not_playing_description = data['not_playing_description'] if data['not_playing_description'] # "Left Ankle; Sprain"
60
62
 
61
63
  # NBA specific below
62
64
 
@@ -194,6 +194,7 @@ end
194
194
  __END__
195
195
 
196
196
  st = sr.standings;
197
+ sc = sr.schedule;
197
198
  sr = Sportradar::Api::Basketball::Nba.new
198
199
  lh = sr.hierarchy;
199
200
  t = lh.teams.first;
@@ -132,7 +132,7 @@ module Sportradar
132
132
  "teams/#{ id }"
133
133
  end
134
134
  def path_base_stats(season_year = api.default_year, default_season = api.default_season)
135
- "seasontd/#{season_year}/#{default_season}/teams/#{id}"
135
+ "seasons/#{season_year}/#{default_season}/teams/#{id}"
136
136
  end
137
137
  def path_roster
138
138
  "#{ path_base }/profile"
@@ -23,7 +23,8 @@ module Sportradar
23
23
  else
24
24
  response = get request_url("#{league}/#{image_type}/players/manifest")
25
25
  end
26
- elsif nfl_premium || usat_premium || sport == 'ncaafb'
26
+ elsif nfl_premium || usat_premium || sport == 'ncaafb' || sport == 'nba'
27
+ year = Date.today.month < 8 ? Date.today.year - 1 : Date.today
27
28
  response = get request_url("#{image_type}/players/#{year}/manifest")
28
29
  else
29
30
  response = get request_url("players/#{image_type}/manifests/all_assets")
@@ -136,6 +137,8 @@ module Sportradar
136
137
  'ap_premium'
137
138
  elsif usat_premium
138
139
  'usat_premium'
140
+ elsif sport == 'nba'
141
+ 'getty_premium'
139
142
  else
140
143
  'usat'
141
144
  # REUTERS IS JUST FOR SOCCER sport == 'mlb' ? 'usat' : 'reuters'
@@ -143,11 +146,12 @@ module Sportradar
143
146
  end
144
147
 
145
148
  def version
146
- if uses_v3_api? || nfl_premium || usat_premium
147
- 3
148
- elsif uses_v2_api?
149
- Sportradar::Api.version('images')
150
- end
149
+ # if uses_v3_api? || nfl_premium || usat_premium || sport == 'nba'
150
+ # 3
151
+ # elsif uses_v2_api?
152
+ # Sportradar::Api.version('images')
153
+ # end
154
+ 3
151
155
  end
152
156
 
153
157
  def image_type
@@ -175,7 +179,7 @@ module Sportradar
175
179
  end
176
180
 
177
181
  def v3_api_sports
178
- ['mlb', 'soccer', 'cricket', 'f1', 'rugby', 'tennis', 'ncaafb', ]
182
+ ['mlb', 'soccer', 'cricket', 'f1', 'rugby', 'tennis', 'ncaafb', 'nba' ]
179
183
  end
180
184
 
181
185
  def soccer_leagues
@@ -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, league_group:, language_code: 'en')
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
- 'x'
23
+ 'production'
24
24
  else
25
- 'xt'
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-#{access_level}#{version}/#{league_group}/#{language_code}/#{path}"
36
+ "/soccer/#{access_level}/v#{version}/#{language_code}/#{path}"
37
37
  end
38
38
 
39
39
  def api_key
40
- if !['xt', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'x')
41
- Sportradar::Api.api_key_params("soccer-#{@league_group}", 'production')
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-#{@league_group}")
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[x xt sim]
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 = {}, league_group: nil, **opts)
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', 'teams'))
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
- "matches/#{ id }"
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
- @team.update_player_stats(self, data['statistics']) if data['statistics'] && @team
44
- if opts[:match]
45
- @team.update_player_stats(self, data, opts[:match])
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
@@ -96,6 +98,14 @@ module Sportradar
96
98
  @name || [@first_name, @last_name].join(' ')
97
99
  end
98
100
 
101
+ def birth_date
102
+ @date_of_birth
103
+ end
104
+
105
+ def jersey
106
+ @jersey_number
107
+ end
108
+
99
109
  def first_name
100
110
  @name.split()[1]
101
111
  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, :tournament_id
5
+ attr_reader :id, :league_group, :name, :category, :current_season, :season_coverage_info, :competition, :start_date, :end_date
6
6
 
7
- def initialize(data = {}, league_group: nil, **opts)
7
+ def initialize(data = {}, competition: nil, **opts)
8
8
  @response = data
9
9
  @id = data["id"]
10
10
  @api = opts[:api]
11
- @league_group = league_group || data['league_group'] || @api&.league_group
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
- def get_tournament_id(data, **opts)
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
@@ -150,6 +150,9 @@ module Sportradar
150
150
  data = api.get_data(path_statistics(tourn_id)).to_h
151
151
  ingest_statistics(data)
152
152
  end
153
+ def get_season_stats(*args)
154
+ get_statistics
155
+ end
153
156
  def ingest_statistics(data)
154
157
  update(data)
155
158
  data
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.13.24"
3
+ VERSION = "0.17.0"
4
4
  end
5
5
  end
@@ -51,19 +51,19 @@ module Sportradar
51
51
 
52
52
  API_GALLERY = [
53
53
  {api: :nfl, version: 1},
54
- {api: :mlb, version: 6},
54
+ {api: :mlb, version: 7},
55
55
  {api: :nhl, version: 3},
56
- {api: :nba, version: 3},
56
+ {api: :nba, version: 7},
57
57
  {api: :ncaamb, version: 3},
58
58
  {api: :ncaafb, version: 1},
59
59
  {api: :golf, version: 2},
60
60
  {api: :nascar, version: 3},
61
61
  {api: :odds, version: 1},
62
62
  {api: :content, version: 3},
63
- {api: :images, version: 2},
63
+ {api: :images, version: 3},
64
64
  {api: :live_images, version: 1},
65
65
  {api: :olympics, version: 2},
66
- {api: :soccer, version: 3},
66
+ {api: :soccer, version: 4},
67
67
  {api: :ncaawb, version: 3},
68
68
  {api: :mma, version: 1},
69
69
  {api: :cricket, version: 1},
@@ -83,7 +83,11 @@ module Sportradar
83
83
  end
84
84
 
85
85
  def self.api_key(api, access_level = 'trial')
86
- ENV.fetch("SPORTRADAR_#{api.to_s.upcase.gsub('-', '_')}#{"_#{access_level.upcase}" if access_level != 'trial'}", "api_key missing for #{api}")
86
+ ENV.fetch("SPORTRADAR_#{api.to_s.upcase.gsub('-', '_')}#{"_#{access_level.upcase}" if access_level != 'trial'}",
87
+ ENV.fetch("SPORTRADAR_#{api.to_s.upcase}_API_KEY",
88
+ "api_key missing for #{api}"
89
+ )
90
+ )
87
91
  end
88
92
 
89
93
  def self.version(api)
@@ -32,8 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency "vcr"
33
33
  spec.add_development_dependency "webmock"
34
34
  spec.add_development_dependency "pry"
35
- spec.add_development_dependency "guard"
36
- spec.add_development_dependency "guard-minitest"
37
35
  spec.add_development_dependency "coveralls"
38
36
  spec.add_development_dependency "simplecov"
39
37
  spec.add_development_dependency "codeclimate-test-reporter"
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.13.24
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Eggett
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,34 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: guard
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: guard-minitest
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
98
  name: coveralls
127
99
  requirement: !ruby/object:Gem::Requirement
@@ -436,6 +408,7 @@ files:
436
408
  - lib/sportradar/api/soccer.rb
437
409
  - lib/sportradar/api/soccer/README.md
438
410
  - lib/sportradar/api/soccer/api.rb
411
+ - lib/sportradar/api/soccer/competition.rb
439
412
  - lib/sportradar/api/soccer/event.rb
440
413
  - lib/sportradar/api/soccer/fact.rb
441
414
  - lib/sportradar/api/soccer/group.rb
@@ -455,7 +428,7 @@ homepage: https://github.com/beneggett/sportradar-api
455
428
  licenses: []
456
429
  metadata:
457
430
  allowed_push_host: https://rubygems.org
458
- post_install_message:
431
+ post_install_message:
459
432
  rdoc_options: []
460
433
  require_paths:
461
434
  - lib
@@ -470,9 +443,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
470
443
  - !ruby/object:Gem::Version
471
444
  version: '0'
472
445
  requirements: []
473
- rubyforge_project:
474
- rubygems_version: 2.6.11
475
- signing_key:
446
+ rubygems_version: 3.0.3.1
447
+ signing_key:
476
448
  specification_version: 4
477
449
  summary: Sportradar API client
478
450
  test_files: []