sportradar-api 0.19.2 → 0.19.4

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
2
  SHA256:
3
- metadata.gz: f244f4735aed098ff6deba5da0b71e858dd2ad46f810af5ac13ab2eb939bab21
4
- data.tar.gz: ae24d54e8a5212bc77128cd9a8b77a5df519b0bcf5b1f5c39219baa642a9011c
3
+ metadata.gz: cd632c76f639fcdd6627dbc2323fc85ee6b8fe20d3eb37b3f4ee1855590e2d54
4
+ data.tar.gz: acaf3b496f64a18051969bd18a84de9dc8c717535c371cbd297329b5be804b6f
5
5
  SHA512:
6
- metadata.gz: 7b9f802af3d7a9d027417bca43b5e3d647c536d42d8c096a80f1bb5fb5954ad9c52c0e9fcf93bc546b79820292a33d520b3eb6ac1e4f081f38c6e5bc00d70597
7
- data.tar.gz: 261a12216c0f88484bfabb3b7d994aba7f3d0444a7cabe62f07c74d8a5b1b5e6d1269fd4bc49063d3ba2cee9bdf5ea2956d234ab6c040b6420c7256a23310bc9
6
+ metadata.gz: a3d9a2d3b120f76804a9287ff0f5d734dccc674451bcaf48b71542849c62ac9e97480c43de38d886a564a3e30ee86075ce57152f68cf70524b508d6856dc7f9b
7
+ data.tar.gz: ce834768c971a60c379029efa678a687c3465e0a4d2d75af51158068cc10e9436eca4014ddd2757cb018c0c3a611a10b107ada473b351391fde73b2512da1cea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.19.2)
4
+ sportradar-api (0.19.4)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
@@ -2,7 +2,7 @@ module Sportradar
2
2
  module Api
3
3
  module Football
4
4
  class Player < Data
5
- attr_accessor :response, :id, :preferred_name, :number, :name_full, :name_first, :name_last, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :depth, :api, :stats
5
+ attr_accessor :response, :id, :preferred_name, :number, :name_full, :name_first, :name_last, :position, :birth_place, :college, :height, :weight, :averages, :totals, :draft, :depth, :api, :stats, :team
6
6
 
7
7
  def initialize(data, **opts)
8
8
  @response = data
@@ -124,4 +124,4 @@ t = ncaafb.teams.sample
124
124
  data = t.get_season_stats(2016);
125
125
  t.get_roster;
126
126
  t.players.sample
127
- t.players.sample.totals
127
+ t.players.sample.totals
@@ -31,11 +31,27 @@ module Sportradar
31
31
  end
32
32
 
33
33
  def get_event_mappings
34
- data = api.get_data(path_event_mappings)
34
+ data = api.get_data(path_event_mappings).fetch('mappings', [])
35
+ if data.size == 1000
36
+ new_data = data
37
+ while new_data.size == 1000
38
+ new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
39
+ data += new_data
40
+ end
41
+ end
42
+ {'mappings' => data }
35
43
  end
36
44
 
37
45
  def get_player_mappings
38
- data = api.get_data(path_player_mappings)
46
+ data = api.get_data(path_player_mappings).fetch('mappings', [])
47
+ if data.size == 1000
48
+ new_data = data
49
+ while new_data.size == 1000
50
+ new_data = api.get_data(path_player_mappings, start: data.size).fetch('mappings', [])
51
+ data += new_data
52
+ end
53
+ end
54
+ {'mappings' => data }
39
55
  end
40
56
 
41
57
  def get_competitor_mappings
@@ -28,18 +28,15 @@ module Sportradar
28
28
  end
29
29
 
30
30
  def get_player_props
31
- data = fetch_player_props
32
- prop_data = if data["competition_sport_events_players_props"].size == 10
33
- arr = data["competition_sport_events_players_props"]
34
- data = fetch_player_props(start: 10)
35
- arr += data["competition_sport_events_players_props"]
36
- if data["competition_sport_events_players_props"].size == 10
37
- data = fetch_player_props(start: 20)
38
- arr += data["competition_sport_events_players_props"]
31
+ prop_data = fetch_player_props.fetch('competition_sport_events_players_props', [])
32
+ if prop_data.size == 10
33
+ new_data = prop_data
34
+ while new_data.size == 10
35
+ new_data = fetch_player_props(start: prop_data.size).fetch('competition_sport_events_players_props', [])
36
+ prop_data += new_data
39
37
  end
40
- else
41
- data["competition_sport_events_players_props"]
42
38
  end
39
+ data = {'competition_sport_events_players_props' => prop_data }
43
40
  create_data(@sport_events_hash, prop_data, klass: SportEvent, api: api)
44
41
  data
45
42
  end
@@ -52,10 +52,27 @@ module Sportradar
52
52
  end
53
53
  end
54
54
 
55
+ def hierarchy
56
+ self.get_seasons
57
+ season = self.latest_season
58
+ season.get_competitors
59
+ season.competitors
60
+ end
61
+
62
+ def teams
63
+ season = self.latest_season
64
+ season.get_competitors if season.competitors.empty?
65
+ season.competitors
66
+ end
67
+
55
68
  def current_season
56
69
  seasons.detect(&:current?)
57
70
  end
58
71
 
72
+ def latest_season
73
+ seasons.max_by(&:end_date)
74
+ end
75
+
59
76
  def standings(type = nil)
60
77
  if type
61
78
  @standings_hash[type]
@@ -3,7 +3,7 @@ module Sportradar
3
3
  module Soccer
4
4
  class Player < Data
5
5
 
6
- attr_reader :id, :league_group, :name, :type, :nationality, :country_code, :height, :weight, :jersey_number, :preferred_foot, :stats, :game_stats, :date_of_birth, :matches_played, :starter
6
+ attr_reader :id, :league_group, :name, :type, :nationality, :country_code, :height, :weight, :jersey_number, :preferred_foot, :stats, :game_stats, :date_of_birth, :matches_played, :starter, :team
7
7
  alias :position :type
8
8
 
9
9
  def initialize(data = {}, league_group: nil, **opts)
@@ -116,6 +116,10 @@ module Sportradar
116
116
  @name.split()[0].delete(',')
117
117
  end
118
118
 
119
+ def injured?
120
+ false
121
+ end
122
+
119
123
  def api
120
124
  @api || Sportradar::Api::Soccer::Api.new(league_group: @league_group)
121
125
  end
@@ -10,6 +10,7 @@ module Sportradar
10
10
  @api = opts[:api]
11
11
  @competition = competition
12
12
  @matches_hash = {}
13
+ @competitors_hash = {}
13
14
 
14
15
  update(data, **opts)
15
16
  end
@@ -31,6 +32,7 @@ module Sportradar
31
32
  @min_coverage_level = data['min_coverage_level'] || @min_coverage_level
32
33
 
33
34
  parse_schedule(data)
35
+ parse_competitors(data)
34
36
  end
35
37
 
36
38
  # def get_tournament_id(data, **opts)
@@ -51,12 +53,22 @@ module Sportradar
51
53
  @matches_hash.values
52
54
  end
53
55
 
56
+ def competitors
57
+ @competitors_hash.values
58
+ end
59
+
54
60
  def parse_schedule(data)
55
61
  if data['schedules']
56
62
  create_data(@matches_hash, data['schedules'], klass: Match, api: api, competition: @competition, season: self)
57
63
  end
58
64
  end
59
65
 
66
+ def parse_competitors(data)
67
+ if data['season_competitors']
68
+ create_data(@competitors_hash, data['season_competitors'], klass: Team, api: api, competition: @competition, season: self)
69
+ end
70
+ end
71
+
60
72
  def api
61
73
  @api ||= Sportradar::Api::Soccer::Api.new(league_group: @league_group)
62
74
  end
@@ -78,6 +90,20 @@ module Sportradar
78
90
  # TODO parse the rest of the data. keys: ["tournament", "sport_events"]
79
91
  data
80
92
  end
93
+
94
+ def path_competitors
95
+ "#{ path_base }/competitors"
96
+ end
97
+ def get_competitors
98
+ data = api.get_data(path_competitors).to_h
99
+ ingest_competitors(data)
100
+ end
101
+ def ingest_competitors(data)
102
+ @competitors_retrieved = true
103
+ update(data)
104
+ # TODO parse the rest of the data. keys: ["tournament", "sport_events"]
105
+ data
106
+ end
81
107
  def queue_schedule
82
108
  url, headers, options, timeout = api.get_request_info(path_schedule)
83
109
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
@@ -15,6 +15,7 @@ module Sportradar
15
15
  @response = data
16
16
  @id = data['id']
17
17
  @api = opts[:api]
18
+ @season = opts[:season]
18
19
  @league_group = league_group || data['league_group'] || @api&.league_group
19
20
 
20
21
  @players_hash = {}
@@ -27,7 +28,7 @@ module Sportradar
27
28
  def update(data, **opts)
28
29
  @id = data['id'] if data['id']
29
30
  @league_group = opts[:league_group] || data['league_group'] || @league_group
30
- get_tournament_id(data, **opts)
31
+ # get_tournament_id(data, **opts)
31
32
 
32
33
  if data["team"]
33
34
  update(data["team"])
@@ -92,7 +93,7 @@ module Sportradar
92
93
  end
93
94
 
94
95
  def path_base
95
- "teams/#{ id }"
96
+ "competitors/#{ id }"
96
97
  end
97
98
 
98
99
  def path_roster
@@ -143,11 +144,16 @@ module Sportradar
143
144
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
144
145
  end
145
146
 
146
- def path_statistics(tourn_id = self.tournament_id)
147
- "tournaments/#{ tourn_id }/#{ path_base }/statistics"
147
+ def season_id
148
+ @season&.id
148
149
  end
149
- def get_statistics(tourn_id = self.tournament_id)
150
- data = api.get_data(path_statistics(tourn_id)).to_h
150
+
151
+ def path_statistics(season_id = self.season_id)
152
+ "seasons/#{ season_id }/#{ path_base }/statistics"
153
+ end
154
+ def get_statistics(season_id = self.season_id)
155
+ return unless season_id
156
+ data = api.get_data(path_statistics(season_id)).to_h
151
157
  ingest_statistics(data)
152
158
  end
153
159
  def get_season_stats(*args)
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.19.2"
3
+ VERSION = "0.19.4"
4
4
  end
5
5
  end
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.19.2
4
+ version: 0.19.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Eggett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-10 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler