sportradar-api 0.16.0 → 0.17.5

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: 728ba648950b8cab5dee8e41e1e69ac24147bee213382aa0f5b8554430918d85
4
- data.tar.gz: 38d070d071f227dcbbee7813fd737800ba551662247cdfd0683eacbfad9bddd3
3
+ metadata.gz: 4d9ffed13743016f02a9ac62392123053147496c963fb0aa8b92db56a1049635
4
+ data.tar.gz: 47ec2f6de533b9fb7e6c2d682d5eafcfa2ced7a24ec6f87650b00a249b2aaaf0
5
5
  SHA512:
6
- metadata.gz: 0f51fe2a602f27a84639b040fb9220dc7fdb62c4cff598b7daee2f62f5124e94f2e3f28c7e34456a4c0bc9fccd8644289f791817c8c6fb60a8f09a4543921b9d
7
- data.tar.gz: 829d946e8e842d61b4842201327657b67400c60f6ffc95308c2fc2a46c68f0186fde2bc006aca677631356f3e7bb8a48705de8ac0720d902a53a34644d1b5bd7
6
+ metadata.gz: 618c909e2c31d13b4a510480ca7a3b7d820a0cc376b88ddee650b2f20257f1f2acbd1fa54f6c93a48d6b6c33726a9fdb13ed3febab29c8f5ca4ad208278be442
7
+ data.tar.gz: cc10fa981d3cf68d76182cbf9e65cab2b7a6a3bdf2ac1c22c0f51e01c4d712bce154ffdbd40f7bbc3e9c49187a6484a30a8491c9be598010e8766fe84364c875
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.15.1)
4
+ sportradar-api (0.17.5)
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 (6.1.3.2)
11
+ activesupport (6.1.6)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
@@ -19,7 +19,7 @@ GEM
19
19
  codeclimate-test-reporter (1.0.8)
20
20
  simplecov (<= 0.13)
21
21
  coderay (1.1.1)
22
- concurrent-ruby (1.1.8)
22
+ concurrent-ruby (1.1.10)
23
23
  coveralls (0.8.19)
24
24
  json (>= 1.8, < 3)
25
25
  simplecov (~> 0.12.0)
@@ -31,12 +31,16 @@ GEM
31
31
  docile (1.1.5)
32
32
  dotenv (2.7.6)
33
33
  hashdiff (0.3.4)
34
- httparty (0.16.2)
34
+ httparty (0.20.0)
35
+ mime-types (~> 3.0)
35
36
  multi_xml (>= 0.5.2)
36
- i18n (1.8.10)
37
+ i18n (1.10.0)
37
38
  concurrent-ruby (~> 1.0)
38
39
  json (2.1.0)
39
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)
40
44
  minitest (5.10.2)
41
45
  minitest-focus (1.1.2)
42
46
  minitest (>= 4, < 6)
@@ -65,7 +69,7 @@ GEM
65
69
  addressable (>= 2.3.6)
66
70
  crack (>= 0.3.2)
67
71
  hashdiff
68
- zeitwerk (2.4.2)
72
+ zeitwerk (2.5.4)
69
73
 
70
74
  PLATFORMS
71
75
  ruby
@@ -107,6 +107,7 @@ module Sportradar
107
107
  end
108
108
 
109
109
  def update(data, source: nil, **opts)
110
+ @response.merge!(data)
110
111
  # via pbp
111
112
  @status = data['status'] if data['status']
112
113
  @coverage = data['coverage'] if data['coverage']
@@ -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'))
@@ -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, :team
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
 
@@ -3,7 +3,7 @@ module Sportradar
3
3
  module Api
4
4
  class Images < Request
5
5
  attr_accessor :sport, :league, :access_level, :nfl_premium, :usat_premium, :event_id, :date, :live_image_request
6
- def initialize( sport, access_level: 't', league: nil, nfl_premium: false, usat_premium: false, event_id: nil, date: nil )
6
+ def initialize( sport, access_level: 't', league: nil, nfl_premium: false, usat_premium: false, event_id: nil, date: nil, year: nil )
7
7
  raise Sportradar::Api::Error::InvalidSport unless allowed_sports.include? sport
8
8
  @sport = sport
9
9
  raise Sportradar::Api::Error::InvalidLeague unless soccer_leagues.include?(league) || league.nil?
@@ -12,6 +12,7 @@ module Sportradar
12
12
  @usat_premium = usat_premium
13
13
  @event_id = event_id
14
14
  @date = date.strftime("%Y/%m/%d") if date
15
+ @yar = year
15
16
  raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
16
17
  @access_level = access_level
17
18
  end
@@ -24,8 +25,8 @@ module Sportradar
24
25
  response = get request_url("#{league}/#{image_type}/players/manifest")
25
26
  end
26
27
  elsif nfl_premium || usat_premium || sport == 'ncaafb' || sport == 'nba'
27
- year = Date.today.month < 8 ? Date.today.year - 1 : Date.today
28
- response = get request_url("#{image_type}/players/#{year}/manifest")
28
+ request_year = @year || (Date.today.month < 8 ? Date.today.year - 1 : Date.today.year)
29
+ response = get request_url("#{image_type}/players/#{request_year}/manifest")
29
30
  else
30
31
  response = get request_url("players/#{image_type}/manifests/all_assets")
31
32
  end
@@ -137,7 +138,7 @@ module Sportradar
137
138
  'ap_premium'
138
139
  elsif usat_premium
139
140
  'usat_premium'
140
- elsif sport == 'nba'
141
+ elsif ['nba', 'nhl'].include?(sport)
141
142
  'getty_premium'
142
143
  else
143
144
  'usat'
@@ -0,0 +1,49 @@
1
+ # Some snippets
2
+
3
+ ```ruby
4
+
5
+ odds = Sportradar::Api::Odds::PlayerOdds.new
6
+ data = odds.get_books
7
+ data = odds.get_sports
8
+ data = odds.get_event_mappings
9
+
10
+
11
+ sport = odds.sports.first
12
+ sport.get_competitions
13
+ comp = sport.competitions.first
14
+
15
+ api = Sportradar::Api::Odds::PlayerOdds.api
16
+ comp = Sportradar::Api::Odds::Competition.new({'id' => 'sr:competition:234'}, api: api)
17
+ data = comp.get_player_props
18
+ comp.sport_events
19
+ event = comp.sport_events.first
20
+
21
+ odds = Sportradar::Api::Odds::PlayerOdds.new
22
+ data = odds.get_sports
23
+ sport = odds.sports.first
24
+ sport.get_competitions
25
+ comp = sport.competitions.first
26
+
27
+ event = comp.sport_events.first
28
+ event.player_props
29
+ event.response
30
+ prop = event.player_props.first
31
+ prop.markets.count
32
+ market = prop.markets.first
33
+ market.response
34
+ market.name
35
+ bm = market.book_markets.first
36
+ outcome = bm.outcomes.first
37
+
38
+
39
+ # {"id"=>"sr:competition:8", "name"=>"LaLiga", "gender"=>"men", "markets"=>true, "futures"=>false, "player_props"=>true, "category"=>{"id"=>"sr:category:32", "name"=>"Spain", "country_code"=>"ESP"}},
40
+
41
+
42
+ ```
43
+
44
+ # Some links
45
+
46
+ https://api.sportradar.com/oddscomparison-player-props/trial/v2/en/books.xml?api_key=
47
+ https://api.sportradar.com/oddscomparison-player-props/trial/v2/en/sports/sr:sport:1/competitions.xml?api_key=
48
+ https://api.sportradar.com/oddscomparison-player-props/trial/v2/en/competitions/sr:competition:234/players_props.json?api_key=
49
+ https://api.sportradar.com/oddscomparison-player-props/trial/v2/en/sports.xml?api_key=
@@ -0,0 +1,60 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Api < Request
5
+ attr_accessor :access_level, :language_code, :error, :base_path
6
+
7
+ def initialize(base_path: base_path, access_level: default_access_level, language_code: 'en', **args)
8
+ @language_code = language_code
9
+ @access_level = access_level
10
+ @base_path = base_path
11
+ raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? @access_level
12
+ end
13
+
14
+ def default_season
15
+ 'reg'
16
+ end
17
+
18
+ def default_access_level
19
+ if (ENV['SPORTRADAR_ODDS_ENV'] || ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
20
+ 'production'
21
+ else
22
+ 'trial'
23
+ end
24
+ end
25
+
26
+ def content_format
27
+ 'json'
28
+ end
29
+
30
+ def inspect
31
+ self.class.name
32
+ end
33
+
34
+ private
35
+
36
+ def request_url(path)
37
+ "/#{base_path}/#{access_level}/v#{version}/#{language_code}/#{path}"
38
+ end
39
+
40
+ def api_key
41
+ if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
42
+ Sportradar::Api.api_key_params("odds", 'production')
43
+ else
44
+ Sportradar::Api.api_key_params("odds")
45
+ end
46
+ end
47
+
48
+ def version
49
+ Sportradar::Api.version('odds')
50
+ end
51
+
52
+ def allowed_access_levels
53
+ %w[production trial]
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,77 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Base < Data
5
+ attr_reader :api
6
+
7
+ def initialize
8
+ @api = self.class.api
9
+ @books_hash = {}
10
+ @sports_hash = {}
11
+ end
12
+
13
+ def books
14
+ @books_hash.values
15
+ end
16
+
17
+ def sports
18
+ @sports_hash.values
19
+ end
20
+
21
+ def get_books
22
+ data = api.get_data(path_books);
23
+ create_data(@books_hash, data['books'], klass: Book, api: api)
24
+ data
25
+ end
26
+
27
+ def get_sports
28
+ data = api.get_data(path_sports);
29
+ create_data(@sports_hash, data['sports'], klass: Sport, api: api)
30
+ data
31
+ end
32
+
33
+ def get_event_mappings
34
+ data = api.get_data(path_event_mappings)
35
+ end
36
+
37
+ def get_player_mappings
38
+ data = api.get_data(path_player_mappings)
39
+ end
40
+
41
+ def get_competitor_mappings
42
+ data = api.get_data(path_competitor_mappings)
43
+ end
44
+
45
+ # url path helpers
46
+ def path_base
47
+ ""
48
+ end
49
+
50
+ def path_books
51
+ "books"
52
+ end
53
+
54
+ def path_sports
55
+ "sports"
56
+ end
57
+
58
+ def path_event_mappings
59
+ 'sport_events/mappings'
60
+ end
61
+
62
+ def path_player_mappings
63
+ 'players/mappings'
64
+ end
65
+
66
+ def path_competitor_mappings
67
+ 'competitors/mappings'
68
+ end
69
+
70
+ def self.api
71
+ Api.new(base_path: api_base)
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,23 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Book < Data
5
+ attr_accessor :response, :id, :name
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+
12
+ @id = data['id']
13
+ @name = data['name']
14
+ end
15
+
16
+ def update(data, **opts)
17
+
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class BookMarket < Data
5
+ attr_accessor :response, :id, :book_id, :book_name, :removed, :external_sport_event_id, :external_market_id
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+
12
+ @id = data['external_market_id']
13
+ @market = opts[:market]
14
+ @outcomes_hash = {}
15
+
16
+ update(data, **opts)
17
+ end
18
+
19
+ def outcomes
20
+ @outcomes_hash.values
21
+ end
22
+
23
+ def update(data, **opts)
24
+ @book_id = data['id'] if data['id'] # "sr:book:17324",
25
+ @book_name = data['name'] if data['name'] # "MGM",
26
+ @removed = data['removed'] if data['removed'] # false,
27
+ @external_sport_event_id = data['external_sport_event_id'] if data['external_sport_event_id'] # "12959106",
28
+ @external_market_id = data['external_market_id'] if data['external_market_id'] # "773486499",
29
+
30
+ create_data(@outcomes_hash, data['outcomes'], klass: Outcome, api: @api) if data['outcomes']
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+
@@ -0,0 +1,52 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Competition < Data
5
+ attr_accessor :response, :api, :id, :name, :gender, :markets, :futures, :player_props
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+ @id = data['id']
12
+
13
+ @name = data['name']
14
+ @gender = data['gender']
15
+ @has_markets = data['markets'] # boolean
16
+ @has_futures = data['futures'] # boolean
17
+ @has_player_props = data['player_props'] # boolean
18
+
19
+ @sport_events_hash = {}
20
+ end
21
+
22
+ def update(data, **opts)
23
+
24
+ end
25
+
26
+ def sport_events
27
+ @sport_events_hash.values
28
+ end
29
+
30
+ def get_player_props
31
+ data = api.get_data(path_player_props)
32
+ create_data(@sport_events_hash, data["competition_sport_events_players_props"], klass: SportEvent, api: api)
33
+ data
34
+ end
35
+
36
+ # url path helpers
37
+ def path_base
38
+ "competitions/#{id}"
39
+ end
40
+
41
+ def path_player_props
42
+ "#{path_base}/players_props"
43
+ end
44
+
45
+ def path_player_props
46
+ "#{path_base}/players_props"
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,34 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Market < Data
5
+ attr_accessor :response, :id, :name
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+
12
+ @id = data['id']
13
+ @name = data['name']
14
+ @player = opts['player']
15
+
16
+ @book_markets_hash = {}
17
+
18
+ update(data, **opts)
19
+ end
20
+
21
+ def book_markets
22
+ @book_markets_hash.values
23
+ end
24
+
25
+ def update(data, **opts)
26
+ create_data(@book_markets_hash, data['books'], klass: BookMarket, api: @api, market: self, player: @player) if data['books']
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+
@@ -0,0 +1,35 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Outcome < Data
5
+ attr_accessor :response, :id
6
+ attr_accessor :type, :odds_decimal, :odds_american, :odds_fraction, :open_odds_decimal, :open_odds_american, :open_odds_fraction, :total, :open_total, :external_outcome_id, :removed
7
+
8
+
9
+ def initialize(data, **opts)
10
+ @response = data
11
+ @api = opts[:api]
12
+
13
+ @id = data['id']
14
+
15
+ update(data, **opts)
16
+ end
17
+
18
+ def update(data, **opts)
19
+ @type = data['type'] if data['type']
20
+ @odds_decimal = data['odds_decimal'] if data['odds_decimal']
21
+ @odds_american = data['odds_american'] if data['odds_american']
22
+ @odds_fraction = data['odds_fraction'] if data['odds_fraction']
23
+ @open_odds_decimal = data['open_odds_decimal'] if data['open_odds_decimal']
24
+ @open_odds_american = data['open_odds_american'] if data['open_odds_american']
25
+ @open_odds_fraction = data['open_odds_fraction'] if data['open_odds_fraction']
26
+ @total = data['total'] if data['total']
27
+ @open_total = data['open_total'] if data['open_total']
28
+ @external_outcome_id = data['external_outcome_id'] if data['external_outcome_id']
29
+ @removed = data['removed'] if data['removed']
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Player < Data
5
+ attr_accessor :response, :api, :id
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+ @id = data['id'] || data.dig('player', 'id')
12
+
13
+ @props_hash = {}
14
+
15
+ update(data['player']) if data['player']
16
+ update(data)
17
+ end
18
+
19
+ def update(data, **opts)
20
+ # @name ||= data['name'] if data['name']
21
+
22
+ create_data(@props_hash, data['markets'], klass: Player, api: api) if data['markets']
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,13 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class PlayerOdds < Base
5
+
6
+ def self.api_base
7
+ 'oddscomparison-player-props'
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class PlayerProp < Data
5
+ attr_accessor :response, :api, :id
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+ @id = data.dig("player", "id")
12
+
13
+ @markets_hash = {}
14
+
15
+ update(data, **opts)
16
+ end
17
+
18
+ def markets
19
+ @markets_hash.values
20
+ end
21
+
22
+ def update(data, **opts)
23
+ create_data(@markets_hash, data['markets'], klass: Market, api: api, player: data['player']) if data['markets']
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class PrematchOdds
5
+ #
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Probabilities
5
+ #
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class RegularOdds
5
+ #
6
+
7
+ def self.api_base
8
+ "oddscomparison-#{package}"
9
+ end
10
+
11
+ def self.package
12
+ # read ENV
13
+ 'us'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,47 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class Sport < Data
5
+ attr_accessor :response, :api, :id, :name, :type
6
+
7
+
8
+ def initialize(data, **opts)
9
+ @response = data
10
+ @api = opts[:api]
11
+
12
+ @id = data['id']
13
+ @name = data['name']
14
+ @type = data['type']
15
+
16
+ @competitions_hash = {}
17
+ end
18
+
19
+ def update(data, **opts)
20
+
21
+ end
22
+
23
+
24
+ def competitions
25
+ @competitions_hash.values
26
+ end
27
+
28
+ def get_competitions
29
+ data = api.get_data(path_competitions);
30
+ create_data(@competitions_hash, data['competitions'], klass: Sport, api: api)
31
+ data
32
+ end
33
+
34
+ # url path helpers
35
+ def path_base
36
+ "sports/#{id}"
37
+ end
38
+
39
+ def path_competitions
40
+ "#{path_base}/competitions"
41
+ end
42
+
43
+
44
+ end
45
+ end
46
+ end
47
+ end