sportradar-api 0.18.1 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87396dd744b5483dc483ad40a2210588cfb0740a4492b95925c2bba0281428a6
4
- data.tar.gz: e0ba45d5bf6a6fcf0bbd9d935c6fe798bd373bb1521422e5116394b4f3d67933
3
+ metadata.gz: f244f4735aed098ff6deba5da0b71e858dd2ad46f810af5ac13ab2eb939bab21
4
+ data.tar.gz: ae24d54e8a5212bc77128cd9a8b77a5df519b0bcf5b1f5c39219baa642a9011c
5
5
  SHA512:
6
- metadata.gz: 2d7af40902d848873622e44b07ba6d67885e080edca30648965be1193d2b0c12bc66f35258a6a7f5808de09d4f0cce5ae1afef725049d0149795ee23ba4633c2
7
- data.tar.gz: da5f6b58bc802ca07951a31b53e91ad1f13b51bca5246bf244ec9d90b2d570e9103a49d407600a8c569292275be67b3d0afc91143276393ce78c510eea68e989
6
+ metadata.gz: 7b9f802af3d7a9d027417bca43b5e3d647c536d42d8c096a80f1bb5fb5954ad9c52c0e9fcf93bc546b79820292a33d520b3eb6ac1e4f081f38c6e5bc00d70597
7
+ data.tar.gz: 261a12216c0f88484bfabb3b7d994aba7f3d0444a7cabe62f07c74d8a5b1b5e6d1269fd4bc49063d3ba2cee9bdf5ea2956d234ab6c040b6420c7256a23310bc9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.18.1)
4
+ sportradar-api (0.19.2)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
@@ -20,7 +20,7 @@ module Sportradar
20
20
 
21
21
  @teams_hash = {}
22
22
  @team_stats = {}
23
- @player_stats = {}
23
+ @player_stats = StatsShim.new(self)
24
24
 
25
25
  @quarters_hash = {}
26
26
  @drives_hash = {}
@@ -394,6 +394,10 @@ module Sportradar
394
394
  ingest_statistics(data)
395
395
  end
396
396
 
397
+ def get_summary
398
+ get_statistics
399
+ end
400
+
397
401
  def queue_statistics
398
402
  url, headers, options, timeout = api.get_request_info(path_statistics)
399
403
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_statistics)}
@@ -29,6 +29,10 @@ module Sportradar
29
29
  @return_yards = data.dig('summary', "return_yards")
30
30
  end
31
31
 
32
+ def dig(*args)
33
+ args.inject(self) { |memo, arg| memo.public_send(arg) }
34
+ end
35
+
32
36
  def turnovers
33
37
  @turnovers || passing.interceptions + fumbles&.lost_fumbles.to_i
34
38
  end
@@ -22,9 +22,9 @@ module Sportradar
22
22
  end
23
23
  def default_access_level
24
24
  if (ENV['SPORTRADAR_ENV'] || ENV['SPORTRADAR_ENV_NFL'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
25
- 'o'
25
+ 'production'
26
26
  else
27
- 'ot'
27
+ 'trial'
28
28
  end
29
29
  end
30
30
 
@@ -35,11 +35,11 @@ module Sportradar
35
35
  end
36
36
 
37
37
  def request_url(path)
38
- "/nfl-#{access_level}#{version}/#{path}"
38
+ "/nfl/official/#{access_level}/v#{version}/en/#{path}"
39
39
  end
40
40
 
41
41
  def api_key
42
- if !['ot', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'o')
42
+ if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
43
43
  ::Sportradar::Api.api_key_params('nfl', 'production')
44
44
  else
45
45
  ::Sportradar::Api.api_key_params('nfl')
@@ -51,7 +51,7 @@ module Sportradar
51
51
  end
52
52
 
53
53
  def allowed_access_levels
54
- %w[rt o p s b t ot sim]
54
+ %w[production trial sim]
55
55
  end
56
56
 
57
57
  def allowed_seasons
@@ -159,13 +159,13 @@ module Sportradar
159
159
  "games/#{season_year}/#{nfl_season}/#{nfl_season_week}/schedule"
160
160
  end
161
161
  def path_weekly_depth_charts(nfl_season_week)
162
- "seasontd/#{season_year}/#{nfl_season}/#{nfl_season_week}/depth_charts"
162
+ "seasons/#{season_year}/#{nfl_season}/#{nfl_season_week}/depth_charts"
163
163
  end
164
164
  def path_weekly_depth_injuries(nfl_season_week)
165
- "seasontd/#{season_year}/#{nfl_season}/#{nfl_season_week}/injuries"
165
+ "seasons/#{season_year}/#{nfl_season}/#{nfl_season_week}/injuries"
166
166
  end
167
167
  def path_standings
168
- "seasontd/#{season_year}/standings"
168
+ "seasons/#{season_year}/standings"
169
169
  end
170
170
 
171
171
  # data retrieval
@@ -320,4 +320,14 @@ File.binwrite('nfl.bin', Marshal.dump(nfl))
320
320
  nfl = Sportradar::Api::Football::Nfl.new
321
321
  nfl.season = 2016
322
322
  res = nfl.get_weekly_depth_charts
323
- dc = nfl.instance_variable_get(:@depth_charts_hash)
323
+ dc = nfl.instance_variable_get(:@depth_charts_hash)
324
+
325
+
326
+ nfl = Sportradar::Api::Football::Nfl.new
327
+ nfl.season = 2021
328
+ nfl.get_schedule
329
+ g = nfl.games.sample
330
+ data = g.get_statistics
331
+ g.team_stats
332
+ g.team_stats.values.first.dig('rushing', 'yards')
333
+
@@ -15,6 +15,10 @@ module Sportradar
15
15
  set_stats
16
16
  end
17
17
 
18
+ def for_player(id)
19
+ @players && @players.detect { |stat| stat.player.id == id }
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def set_stats
@@ -0,0 +1,24 @@
1
+ module Sportradar
2
+ module Api
3
+ module Football
4
+ class StatsShim
5
+ attr_reader :game
6
+
7
+ def initialize(game)
8
+ @game = game
9
+ end
10
+
11
+ def dig(player_id, category, stat)
12
+ game.team_stats.each_value do |stats|
13
+ player = stats.public_send(category).for_player(player_id)
14
+ if player
15
+ return player.send(stat)
16
+ end
17
+ end
18
+ 0
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,4 @@
1
+ require "sportradar/api/football/stats_shim"
1
2
  require "sportradar/api/football/stat_pack"
2
3
  require "sportradar/api/football/stat_pack/defense"
3
4
  require "sportradar/api/football/stat_pack/extra_points"
@@ -13,7 +13,7 @@ sport.get_competitions
13
13
  comp = sport.competitions.first
14
14
 
15
15
  api = Sportradar::Api::Odds::PlayerOdds.api
16
- comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:234'}, api: api)
16
+ comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:109'}, api: api)
17
17
  data = comp.get_player_props
18
18
  comp.sport_events
19
19
  event = comp.sport_events.first
@@ -29,12 +29,23 @@ module Sportradar
29
29
 
30
30
  def get_player_props
31
31
  data = fetch_player_props
32
- create_data(@sport_events_hash, data["competition_sport_events_players_props"], klass: SportEvent, api: api)
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"]
39
+ end
40
+ else
41
+ data["competition_sport_events_players_props"]
42
+ end
43
+ create_data(@sport_events_hash, prop_data, klass: SportEvent, api: api)
33
44
  data
34
45
  end
35
46
 
36
- def fetch_player_props
37
- api.get_data(path_player_props)
47
+ def fetch_player_props(params = {})
48
+ api.get_data(path_player_props, params)
38
49
  end
39
50
 
40
51
  # url path helpers
@@ -30,8 +30,6 @@ module Sportradar
30
30
  def update(data, **opts)
31
31
  create_data(@player_props_hash, data['players_props'], klass: PlayerProp, api: api) if data['players_props']
32
32
  create_data(@player_markets_hash, data['players_markets'], klass: Market, api: api) if data['players_markets']
33
- rescue => e
34
- binding.pry
35
33
  end
36
34
 
37
35
  end
@@ -12,8 +12,8 @@ module Sportradar
12
12
  self
13
13
  end
14
14
 
15
- def get_data(url)
16
- data = get request_url(url)
15
+ def get_data(url, extra_params = {})
16
+ data = get(request_url(url), extra_params)
17
17
  if data.is_a?(::Sportradar::Api::Error)
18
18
  puts request_url(url)
19
19
  puts
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.18.1"
3
+ VERSION = "0.19.2"
4
4
  end
5
5
  end
@@ -50,7 +50,7 @@ module Sportradar
50
50
  module Api
51
51
 
52
52
  API_GALLERY = [
53
- {api: :nfl, version: 1},
53
+ {api: :nfl, version: 7},
54
54
  {api: :mlb, version: 7},
55
55
  {api: :nhl, version: 3},
56
56
  {api: :nba, version: 7},
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.18.1
4
+ version: 0.19.2
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-06-29 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -380,6 +380,7 @@ files:
380
380
  - lib/sportradar/api/football/stat_pack/punts.rb
381
381
  - lib/sportradar/api/football/stat_pack/receiving.rb
382
382
  - lib/sportradar/api/football/stat_pack/rushing.rb
383
+ - lib/sportradar/api/football/stats_shim.rb
383
384
  - lib/sportradar/api/football/team.rb
384
385
  - lib/sportradar/api/football/venue.rb
385
386
  - lib/sportradar/api/football/week.rb