sportradar-api 0.16.1 → 0.17.5.pre

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: 03f6248dd4fefe7ad9dd9d6d51cde0e074458af60f6cccc5605c5e1ed122cf3c
4
- data.tar.gz: 91b960f18557bf9f174d4558ff9a0b13b4b71d91405e4ffc48b60eea0e04ff37
3
+ metadata.gz: baa0128f3db1c19f750c7be30d6c99e7962a60cf18d7edca8efb104126834dcc
4
+ data.tar.gz: 1a342baf45ebb6f364c139bc2e17061e21e33d15f9b1050b2b3b358525280480
5
5
  SHA512:
6
- metadata.gz: dbafa97a79e3514e7c5d26fed96ccc2a614cc8e4e924ebfef36563cc8486376e80bda2520a756417619a60631b28579d80dc391c8949dff12cbbb3f70b69b881
7
- data.tar.gz: 45585e585a00f67e95620b9d38aee76889912cf26774f6b8dfec0c38af0f10fcf5e5b2a9a31548f1d308ec1e0dbc2ba6b8a589241941afcfd989b60db1dab5b4
6
+ metadata.gz: 597526f4a1eacdcd0f1bb9f9ef37da58e1ee3f9e3fe354723f27963f5eaa8e4fff3d690fb4e9d0032dc10d30e45c0bebf679f9e03d6b8e5df736065ef5ec9eac
7
+ data.tar.gz: bf2c269d1f7a1f8870766886bed107663e0d447173a1efdbeec49effeb9149745c3e6ce191ea69f7214ea2f8fb0519dd819814c66602fdbc8d3a5cc8fcc2e5d1
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.16.1)
4
+ sportradar-api (0.17.5.pre)
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.5)
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.9)
22
+ concurrent-ruby (1.1.10)
23
23
  coveralls (0.8.19)
24
24
  json (>= 1.8, < 3)
25
25
  simplecov (~> 0.12.0)
@@ -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'))
@@ -24,7 +24,7 @@ module Sportradar
24
24
  response = get request_url("#{league}/#{image_type}/players/manifest")
25
25
  end
26
26
  elsif nfl_premium || usat_premium || sport == 'ncaafb' || sport == 'nba'
27
- year = Date.today.month < 8 ? Date.today.year - 1 : Date.today
27
+ year = Date.today.month < 8 ? Date.today.year - 1 : Date.today.year
28
28
  response = get request_url("#{image_type}/players/#{year}/manifest")
29
29
  else
30
30
  response = get request_url("players/#{image_type}/manifests/all_assets")
@@ -137,7 +137,7 @@ module Sportradar
137
137
  'ap_premium'
138
138
  elsif usat_premium
139
139
  'usat_premium'
140
- elsif sport == 'nba'
140
+ elsif ['nba', 'nhl'].include?(sport)
141
141
  'getty_premium'
142
142
  else
143
143
  '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=9jcc4ts95ukg6q86wfjjtr7e
48
+ https://api.sportradar.com/oddscomparison-player-props/trial/v2/en/competitions/sr:competition:234/players_props.json?api_key=9jcc4ts95ukg6q86wfjjtr7e
49
+ https://api.sportradar.com/oddscomparison-player-props/trial/v2/en/sports.xml?api_key=9jcc4ts95ukg6q86wfjjtr7e
@@ -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
@@ -0,0 +1,40 @@
1
+ module Sportradar
2
+ module Api
3
+ module Odds
4
+ class SportEvent < 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('sport_event', 'id')
12
+
13
+ @player_props_hash = {}
14
+ @player_markets_hash = {}
15
+
16
+ update(data)
17
+ # update(data['sport_event']) if data['sport_event']
18
+ # update(data['players_props']) if data['players_props']
19
+ # update(data['players_markets']) if data['players_markets']
20
+ end
21
+
22
+ def player_props
23
+ @player_props_hash.values
24
+ end
25
+
26
+ def player_markets
27
+ @player_markets_hash.values
28
+ end
29
+
30
+ def update(data, **opts)
31
+ create_data(@player_props_hash, data['players_props'], klass: PlayerProp, api: api) if data['players_props']
32
+ create_data(@player_markets_hash, data['players_markets'], klass: Market, api: api) if data['players_markets']
33
+ rescue => e
34
+ binding.pry
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end