sportradar-api 0.19.4 → 0.20.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
2
  SHA256:
3
- metadata.gz: cd632c76f639fcdd6627dbc2323fc85ee6b8fe20d3eb37b3f4ee1855590e2d54
4
- data.tar.gz: acaf3b496f64a18051969bd18a84de9dc8c717535c371cbd297329b5be804b6f
3
+ metadata.gz: efdb1c2b6c7dfaab41b0f12a3ce3f36ba5c887a9165f4e9f55cf93da6e06ffc0
4
+ data.tar.gz: fae52f1e64953e51d8329dcb8273de67cd83e156fe8f0c3b33200abe37c1fd34
5
5
  SHA512:
6
- metadata.gz: a3d9a2d3b120f76804a9287ff0f5d734dccc674451bcaf48b71542849c62ac9e97480c43de38d886a564a3e30ee86075ce57152f68cf70524b508d6856dc7f9b
7
- data.tar.gz: ce834768c971a60c379029efa678a687c3465e0a4d2d75af51158068cc10e9436eca4014ddd2757cb018c0c3a611a10b107ada473b351391fde73b2512da1cea
6
+ metadata.gz: cbb4cdd8825d33afa1b392641884a3cbd954769e257a31142ed5ea22a6c3b6ec495bd9472ff7af0317693cdd9e5f168187de3cb36fa8ffc461ad7f47011c7510
7
+ data.tar.gz: d731a41a12e03aa9f9e3353a896fefaa93c5719bba6a9029439ffa2f17e10cea20e5e7aa8383e136c549d215095cec5d03daf6edb6720b16b79610627064454d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.19.4)
4
+ sportradar-api (0.20.0)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
@@ -14,10 +14,6 @@ module Sportradar
14
14
  Player
15
15
  end
16
16
 
17
- def path_season_stats(year = season_year, season = nfl_season)
18
- "seasontd/#{year}/#{nfl_season}/teams/#{ id }/statistics"
19
- end
20
-
21
17
  def api
22
18
  @api || Sportradar::Api::Football::Nfl::Api.new
23
19
  end
@@ -15,7 +15,7 @@ module Sportradar
15
15
  return player.send(stat)
16
16
  end
17
17
  end
18
- 0
18
+ nil
19
19
  end
20
20
 
21
21
  end
@@ -139,13 +139,13 @@ module Sportradar
139
139
  "teams/#{ id }"
140
140
  end
141
141
  def path_base_stats(year = season_year, season = default_season)
142
- "seasontd/#{year}/#{season}/teams/#{id}"
142
+ "seasons/#{year}/#{season}/teams/#{id}"
143
143
  end
144
144
  def path_roster
145
145
  "#{ path_base }/profile" # nfl is profile, ncaa is roster
146
146
  end
147
- def path_season_stats
148
- "#{ path_base_stats }/statistics"
147
+ def path_season_stats(year = season_year, season = default_season)
148
+ "#{ path_base_stats(year, season) }/statistics"
149
149
  end
150
150
 
151
151
 
@@ -0,0 +1,59 @@
1
+ module Sportradar
2
+ module Api
3
+ module Mma
4
+ class Api < Request
5
+ attr_accessor :league_group, :access_level, :language_code, :error
6
+
7
+ def initialize(access_level: default_access_level, language_code: 'en', **args)
8
+ @league_group = league_group
9
+ @language_code = language_code
10
+ @access_level = access_level
11
+ # raise Sportradar::Api::Error::InvalidLeague unless allowed_leagues.include? @league_group
12
+ raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? @access_level
13
+ end
14
+
15
+ def default_year
16
+ Date.today.year
17
+ end
18
+ # def default_season
19
+ # 'reg'
20
+ # end
21
+ def default_access_level
22
+ if (ENV['SPORTRADAR_ENV_MMA'] || ENV['SPORTRADAR_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV']) == 'production'
23
+ 'production'
24
+ else
25
+ 'trial'
26
+ end
27
+ end
28
+
29
+ def content_format
30
+ 'json'
31
+ end
32
+
33
+ private
34
+
35
+ def request_url(path)
36
+ "/mma/#{access_level}/v#{version}/#{language_code}/#{path}"
37
+ end
38
+
39
+ def api_key
40
+ if !['trial', 'sim'].include?(access_level) || (access_level == 'sim' && default_access_level == 'production')
41
+ Sportradar::Api.api_key_params("mma", 'production')
42
+ else
43
+ Sportradar::Api.api_key_params("mma")
44
+ end
45
+ end
46
+
47
+ def version
48
+ Sportradar::Api.version('mma')
49
+ end
50
+
51
+ def allowed_access_levels
52
+ %w[production trial]
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,62 @@
1
+ module Sportradar
2
+ module Api
3
+ module Mma
4
+ class Competition < Data
5
+ attr_reader :id, :name, :parent_id, :category
6
+
7
+ def initialize(data = {}, league_group: nil, **opts)
8
+ @response = data
9
+ @id = data["id"]
10
+ @api = opts[:api]
11
+
12
+ @name = data['name'] if data['name']
13
+ @parent_id = data['parent_id'] if data['parent_id']
14
+ @category = data['category'] if data['category']
15
+
16
+ @seasons_hash = {}
17
+
18
+ update(data, **opts)
19
+ end
20
+
21
+ def update(data, **opts)
22
+ parse_season(data)
23
+ end
24
+
25
+ def parse_season(data)
26
+ if data['seasons']
27
+ create_data(@seasons_hash, data['seasons'], klass: Season, api: api, competition: self)
28
+ end
29
+ end
30
+
31
+ def seasons
32
+ @seasons_hash.values
33
+ end
34
+
35
+ def api
36
+ @api ||= Sportradar::Api::Mma::Api.new
37
+ end
38
+
39
+ # url path helpers
40
+ def path_base
41
+ "competitions/#{ id }"
42
+ end
43
+
44
+ def path_seasons
45
+ "#{ path_base }/seasons"
46
+ end
47
+ def get_seasons
48
+ data = api.get_data(path_seasons).to_h
49
+ ingest_seasons(data)
50
+ end
51
+ def ingest_seasons(data)
52
+ update(data)
53
+ # TODO parse the rest of the data. keys: ["tournament", "seasons"]
54
+ data
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ __END__
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Event < Data
5
5
  attr_accessor :response, :id, :name, :scheduled, :venue, :league
6
6
 
@@ -1,80 +1,119 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Fight < Data
5
- attr_accessor :response, :id, :event, :accolade, :scheduled_rounds, :weight_class, :result
6
- @all_hash = {}
7
- def self.new(data, **opts)
8
- existing = @all_hash[data['id']]
9
- if existing
10
- existing.update(data)
11
- # existing.add_event(opts[:event])
12
- # existing
13
- else
14
- @all_hash[data['id']] = super
15
- end
16
- end
17
- def self.all
18
- @all_hash.values
19
- end
5
+ attr_accessor :response, :id, :season, :start_time, :start_time_confirmed, :sport_event_context, :coverage, :venue, :status, :match_status, :winner_id, :final_round, :final_round_length, :end_method, :winner, :scheduled_length, :weight_class, :title_fight, :statistics
20
6
 
21
7
  def initialize(data, **opts)
22
8
  @response = data
23
9
  @api = opts[:api]
24
- @event = opts[:event]
10
+ @season = opts[:season]
25
11
  @fighters_hash = {}
26
12
 
27
13
  @id = data['id']
14
+ @statistics = {}
28
15
 
29
16
  update(data)
30
17
  end
31
18
 
32
19
  def fighters
33
- @fighters_hash ||= update_fighters(response)
34
20
  @fighters_hash.values
35
21
  end
36
22
 
37
- def score
38
- result.scores
39
- end
40
-
41
23
  def update(data, **opts)
42
- @accolade = data['accolade'] if data['accolade']
43
- @scheduled_rounds = data['scheduled_rounds'] if data['scheduled_rounds'] # "3",
44
- @weight_class = data['weight_class'] if data['weight_class'] # {"id"=>"LW", "weight"=>"146-155", "description"=>"Lightweight"},
24
+ if data["summaries"]
25
+ update(data["summaries"][0])
26
+ end
27
+ if data["sport_event"]
28
+ update(data["sport_event"])
29
+ end
30
+ if data["sport_event_status"]
31
+ update(data["sport_event_status"])
32
+ end
33
+
34
+ @id = data['id'] if data['id'] && !@id
35
+ @start_time = Time.parse(data['start_time']) if data['start_time']
36
+ @start_time_confirmed = data['start_time_confirmed'] if data['start_time_confirmed']
37
+ @sport_event_context = data['sport_event_context'] if data['sport_event_context']
38
+ @coverage = data['coverage'] if data['coverage']
39
+ @venue = data['venue'] if data['venue']
40
+
41
+ @status = data['status'] if data['status']
42
+ @match_status = data['match_status'] if data['match_status']
43
+ @winner_id = data['winner_id'] if data['winner_id']
44
+ @final_round = data['final_round'] if data['final_round']
45
+ @final_round_length = data['final_round_length'] if data['final_round_length']
46
+ @end_method = data['method'] if data['method']
47
+ @winner = data['winner'] if data['winner']
48
+ @scheduled_length = data['scheduled_length'] if data['scheduled_length']
49
+ @weight_class = data['weight_class'] if data['weight_class']
50
+ @title_fight = data['title_fight'] if data['title_fight']
45
51
 
46
- @referee = Referee.new(data['referee'], fight: self, api: api) if data['referee']
47
- @result = Result.new(data['result'], fight: self, api: api) if data['result']
48
52
 
49
- update_fighters(data) if data['fighters']
53
+ update_fighters(data) if data['competitors']
54
+ update_statistics(data['statistics']) if data["statistics"]
50
55
 
51
56
  self
52
57
  end
53
58
 
59
+ def season_id
60
+ @season&.id || @sport_event_context&.dig('season', 'id')
61
+ end
62
+
63
+ def starts_at
64
+ @start_time
65
+ end
66
+
67
+ def coverage_level
68
+ 'live' if @coverage&.dig('live')
69
+ end
70
+
71
+ def title
72
+ fighters.map(&:display_name).join(' vs ')
73
+ end
74
+
75
+ def scheduled
76
+ @start_time
77
+ end
78
+
54
79
  def update_fighters(data)
55
- create_data(@fighters_hash, response.dig('fighters', 'fighter'), klass: Fighter, api: api, fight: self)
80
+ if data['competitors']
81
+ create_data(@fighters_hash, data['competitors'], klass: Fighter, api: api, fight: self)
82
+ end
83
+ end
84
+
85
+ def update_statistics(data)
86
+ @statistics['totals'] = structure_stats(data["totals"]) if data["totals"]
87
+ if data['periods']
88
+ data['periods'].each do |round|
89
+ @statistics[round['number']] = structure_stats(round)
90
+ end
91
+ end
56
92
  end
93
+
94
+ def structure_stats(data)
95
+ data['competitors'].map { |comp_data| [comp_data['id'], comp_data.merge(comp_data.delete('statistics'))] }.to_h
96
+ end
97
+
57
98
  def api
58
- @api ||= Sportradar::Api::Mma.new
99
+ @api ||= Sportradar::Api::Mma::Api.new
59
100
  end
60
101
 
61
102
 
62
- # def path_base
63
- # "games/#{ id }"
64
- # end
65
- # def path_box
66
- # "#{ path_base }/boxscore"
67
- # end
68
- # def path_pbp
69
- # "#{ path_base }/pbp"
70
- # end
103
+ def path_base
104
+ "sport_events/#{ id }"
105
+ end
71
106
 
72
- # def get_box
73
- # data = api.get_data(path_box)['game']
74
- # update(data)
75
- # @quarter = data.delete('quarter')
76
- # data
77
- # end
107
+ def path_summary
108
+ "#{ path_base }/summary"
109
+ end
110
+
111
+ def get_summary
112
+ data = api.get_data(path_summary)
113
+ update(data)
114
+
115
+ data
116
+ end
78
117
 
79
118
  # def get_pbp
80
119
  # data = api.get_data(path_pbp)['game']
@@ -1,22 +1,8 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Fighter < Data
5
- attr_accessor :response, :id, :height, :weight, :reach, :stance, :first_name, :nick_name, :last_name, :record, :born, :out_of
6
- @all_hash = {}
7
- def self.new(data, **opts)
8
- existing = @all_hash[data['id']]
9
- if existing
10
- existing.update(data, **opts)
11
- existing.add_fight(opts[:fight])
12
- existing
13
- else
14
- @all_hash[data['id']] = super
15
- end
16
- end
17
- def self.all
18
- @all_hash.values
19
- end
5
+ attr_accessor :response, :id, :height, :weight, :reach, :stance, :name, :first_name, :nick_name, :last_name, :record, :born, :out_of, :qualifier, :abbreviation
20
6
 
21
7
  def initialize(data, **opts)
22
8
  @response = data
@@ -36,8 +22,21 @@ module Sportradar
36
22
  @fights_hash[fight.id] = fight if fight
37
23
  end
38
24
 
25
+ def display_name
26
+ if first_name && last_name
27
+ "#{first_name} #{last_name}"
28
+ else
29
+ @name || @short_name
30
+ end
31
+ end
39
32
 
40
33
  def update(data, **opts)
34
+ @name = data['name'] if data['name']
35
+ @abbreviation = data['abbreviation'] if data['abbreviation']
36
+ @short_name = data['short_name'] if data['short_name']
37
+
38
+ @qualifier = data['qualifier'] if data['qualifier'] # "72",
39
+ @abbreviation = data['abbreviation'] if data['abbreviation'] # "72",
41
40
  @height = data['height'] if data['height'] # "72",
42
41
  @weight = data['weight'] if data['weight'] # "170",
43
42
  @reach = data['reach'] if data['reach'] # "",
@@ -45,6 +44,7 @@ module Sportradar
45
44
  @first_name = data['first_name'] if data['first_name'] # "Sai",
46
45
  @nick_name = data['nick_name'] if data['nick_name'] # "The Boss",
47
46
  @last_name = data['last_name'] if data['last_name'] # "Wang",
47
+ @name = data['name'] if data['name'] # "Wang, Sai",
48
48
  @record = data['record'] if data['record'] # {"wins"=>"6", "losses"=>"4", "draws"=>"1", "no_contests"=>"0"},
49
49
  @born = data['born'] if data['born'] # {"date"=>"1988-01-16", "country_code"=>"UNK", "country"=>"Unknown", "state"=>"", "city"=>""},
50
50
  @out_of = data['out_of'] if data['out_of'] # {"country_code"=>"UNK", "country"=>"Unknown", "state"=>"", "city"=>""}}
@@ -65,7 +65,7 @@ module Sportradar
65
65
  self
66
66
  end
67
67
  def api
68
- @api ||= Sportradar::Api::Mma.new
68
+ @api ||= Sportradar::Api::Mma::Api.new
69
69
  end
70
70
 
71
71
 
@@ -92,4 +92,4 @@ e = sc.events.sample;
92
92
  e.fights.first.fighters.first.born
93
93
 
94
94
  fighter_hash = {'id' => "259117dc-c443-4086-8c1d-abd082e3d4b9" } # => Conor McGregor
95
- f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
95
+ f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Judge < Data
5
5
  attr_accessor :response, :id, :first_name, :last_name
6
6
  @all_hash = {}
@@ -67,4 +67,4 @@ e = sc.events.sample;
67
67
  e.fights.first.fighters.first.born
68
68
 
69
69
  fighter_hash = {'id' => "259117dc-c443-4086-8c1d-abd082e3d4b9" } # => Conor McGregor
70
- f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
70
+ f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class League < Data
5
5
  attr_accessor :response, :id, :event, :name, :alias
6
6
  @all_hash = {}
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Referee < Data
5
5
  attr_accessor :response, :id, :first_name, :last_name
6
6
  @all_hash = {}
@@ -67,4 +67,4 @@ e = sc.events.sample;
67
67
  e.fights.first.fighters.first.born
68
68
 
69
69
  fighter_hash = {'id' => "259117dc-c443-4086-8c1d-abd082e3d4b9" } # => Conor McGregor
70
- f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
70
+ f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Result < Data
5
5
  attr_accessor :response, :id, :round, :time, :outcome, :submission, :endstrike, :endtarget, :endposition, :winner, :draw
6
6
 
@@ -65,4 +65,4 @@ e = sc.events.sample;
65
65
  e.fights.first.fighters.first.born
66
66
 
67
67
  fighter_hash = {'id' => "259117dc-c443-4086-8c1d-abd082e3d4b9" } # => Conor McGregor
68
- f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
68
+ f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Roster < Data
5
5
  attr_accessor :response, :id, :name, :scheduled, :venue
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Schedule < Data
5
5
  attr_accessor :response, :id, :name, :scheduled, :venue
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Score < Data
5
5
  attr_accessor :response, :id, :first_name, :last_name, :winner_score, :loser_score
6
6
  # @all_hash = {}
@@ -80,4 +80,4 @@ e = sc.events.sample;
80
80
  e.fights.first.fighters.first.born
81
81
 
82
82
  fighter_hash = {'id' => "259117dc-c443-4086-8c1d-abd082e3d4b9" } # => Conor McGregor
83
- f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
83
+ f = Sportradar::Api::Mma::Fighter.new(fighter_hash)
@@ -0,0 +1,102 @@
1
+ module Sportradar
2
+ module Api
3
+ module Mma
4
+ class Season < Data
5
+ attr_reader :id, :name, :start_date, :end_date, :year, :competition_id
6
+
7
+ def initialize(data = {}, league_group: nil, **opts)
8
+ @response = data
9
+ @id = data["id"]
10
+ @api = opts[:api]
11
+
12
+ @fights_hash = {}
13
+ @fighters_hash = {}
14
+
15
+ update(data, **opts)
16
+ end
17
+
18
+ def update(data, **opts)
19
+ @name = data['name'] if data['name']
20
+ @start_date = Time.parse(data['start_date']) if data['start_date']
21
+ @end_date = Time.parse(data['end_date']) if data['end_date']
22
+ @year = data['year'] if data['year']
23
+ @competition_id = data['competition_id'] if data['competition_id']
24
+
25
+ parse_summary(data)
26
+ parse_competitors(data)
27
+ end
28
+
29
+ def fights
30
+ @fights_hash.values
31
+ end
32
+
33
+ def fighters
34
+ @fighters_hash.values
35
+ end
36
+
37
+ def future?
38
+ self.end_date > Time.now
39
+ end
40
+
41
+ def parse_summary(data)
42
+ if data['summaries']
43
+ create_data(@fights_hash, data['summaries'], klass: Fight, api: api, season: self)
44
+ end
45
+ end
46
+
47
+ def parse_competitors(data)
48
+ if data['season_competitors']
49
+ create_data(@fighters_hash, data['season_competitors'], klass: Fighter, api: api, season: self)
50
+ end
51
+ end
52
+
53
+ def api
54
+ @api ||= Sportradar::Api::Mma::Api.new
55
+ end
56
+
57
+ # url path helpers
58
+ def path_base
59
+ "seasons/#{ id }"
60
+ end
61
+
62
+ def path_summary
63
+ "#{ path_base }/summaries"
64
+ end
65
+ def get_summary
66
+ data = api.get_data(path_summary).to_h
67
+ ingest_summary(data)
68
+ end
69
+ def ingest_summary(data)
70
+ update(data)
71
+ # TODO parse the rest of the data. keys: ["tournament", "seasons"]
72
+ data
73
+ end
74
+
75
+ def path_competitors
76
+ "#{ path_base }/competitors"
77
+ end
78
+ def get_competitors
79
+ data = api.get_data(path_competitors).to_h
80
+ ingest_competitors(data)
81
+ end
82
+ def ingest_competitors(data)
83
+ update(data)
84
+ # TODO parse the rest of the data. keys: ["tournament", "seasons"]
85
+ data
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ __END__
94
+
95
+ {
96
+ "id"=>"sr:season:54879",
97
+ "name"=>"UFC Contender Series, Las Vegas, Week 26 2018",
98
+ "start_date"=>"2018-06-26",
99
+ "end_date"=>"2018-06-28",
100
+ "year"=>"2018",
101
+ "competition_id"=>"sr:competition:25357"
102
+ }
@@ -1,6 +1,6 @@
1
1
  module Sportradar
2
2
  module Api
3
- class Mma
3
+ module Mma
4
4
  class Venue < Data
5
5
  attr_accessor :response, :id, :name, :address, :city, :state, :country, :zip, :capacity, :timezone
6
6
  @all_hash = {}
@@ -1,182 +1,64 @@
1
+ require_relative "mma/api"
2
+ require_relative "mma/competition"
3
+ require_relative "mma/season"
4
+ require_relative "mma/schedule"
5
+ require_relative "mma/roster"
6
+ require_relative "mma/fighter"
7
+ require_relative "mma/event"
8
+ require_relative "mma/fight"
9
+ require_relative "mma/judge"
10
+ require_relative "mma/referee"
11
+ require_relative "mma/result"
12
+ require_relative "mma/score"
13
+ require_relative "mma/venue"
14
+ require_relative "mma/league"
15
+
1
16
  module Sportradar
2
17
  module Api
3
- class Mma < Request
4
- attr_accessor :league, :access_level, :simulation, :error
18
+ module Mma
5
19
 
6
- def initialize(access_level = 't')
7
- @league = 'mma'
8
- raise Sportradar::Api::Error::InvalidAccessLevel unless allowed_access_levels.include? access_level
9
- @access_level = access_level
20
+ def self.parse_results(arr)
21
+ arr.map { |hash| hash["sport_event"].merge(hash["sport_event_status"]) }
10
22
  end
11
23
 
12
- def schedule
13
- response = get request_url("schedule")
14
- if response.success? && response['schedule']
15
- Sportradar::Api::Mma::Schedule.new(response['schedule'], api: self)
16
- else
17
- @error = response
18
- end
24
+ def self.get_competitions
25
+ data = api.get_data(path_competitions).to_h
26
+ parse_competitions(data)
19
27
  end
20
28
 
21
- def participants
22
- response = get request_url("profiles")
23
- if response.success? && response['profile']
24
- Sportradar::Api::Mma::Roster.new(response['profile'], api: self)
25
- else
26
- @error = response
27
- end
28
- end
29
-
30
- def statistics(event_id = "8f85ecc5-0d4d-470b-b357-075cc7e7bedd")
31
- event_hash = {"id" => event_id } # => UFC 205 - McGregor/Alvarez
32
- event = Event.new({ 'id' => event_id })
33
- event.get_stats
34
- end
35
- def generate_simulation_event(event_id = "8f85ecc5-0d4d-470b-b357-075cc7e7bedd")
36
- event = Event.new({ 'id' => event_id })
37
- i = 0
38
- base_path = "simulations/mma/#{event_id}"
39
- FileUtils.mkdir_p(base_path)
40
- loop do
41
- t = Time.now
42
- print "#{t}: Data pull #{i+=1}\r"
43
- res = event.get_stats.body
44
- File.write("#{base_path}/#{t.to_i}.xml", res)
45
- wait = (t.to_i + 60 - Time.now.to_i)
46
- wait.times do |j|
47
- print "#{t}: Data pull #{i} complete, #{wait - j} seconds until next.\r"
48
- sleep 1
29
+ def self.parse_competitions(data)
30
+ if data['competitions']
31
+ data['competitions'].map do |hash|
32
+ Competition.new(hash, api: api)
49
33
  end
50
- puts
51
34
  end
52
35
  end
53
36
 
54
- # def roster(team_id, year = Date.today.year, season = "reg")
55
- # Team.new(team_id).tap { |team| team.roster }
56
- # end
57
-
58
-
59
- # def weekly_depth_charts(week = 1, year = Date.today.year, season = "reg" )
60
- # response = get request_url("seasontd/#{ week_path(year, season, week) }/depth_charts")
61
- # Sportradar::Api::Nfl::LeagueDepthChart.new response
62
- # end
63
-
64
- # def weekly_injuries(week = 1, year = Date.today.year, season = "reg")
65
- # response = get request_url("seasontd/#{ week_path(year, season, week) }/injuries")
66
- # Sportradar::Api::Nfl::Season.new response["season"] if response.success? && response["season"]
67
- # end
68
-
69
- # # gid = '8494fbf9-fe96-4d6d-81b2-5ed32347676f'
70
- # # past_game_id = "0141a0a5-13e5-4b28-b19f-0c3923aaef6e"
71
- # # future_game_id = "28290722-4ceb-4a4c-a4e5-1f9bec7283b3"
72
- # def game_boxscore(game_id)
73
- # check_simulation(game_id)
74
- # response = get request_url("games/#{ game_id }/boxscore")
75
- # Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"] # mostly done, just missing play statistics
76
- # end
77
-
78
- # def game_roster(game_id)
79
- # check_simulation(game_id)
80
- # response = get request_url("games/#{ game_id }/roster")
81
- # Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"]
82
- # end
83
-
84
- # def game_statistics(game_data)
85
- # # check_simulation(game_id)
86
- # base = "#{ year }/#{ mma_season }/#{ mma_season_week }/#{ away_team}/#{ home_team }/statistics"
87
- # response = get_data(base)
88
- # Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"]
89
- # ## Need to properly implement statistics
90
- # end
91
-
92
- # def play_by_play(game_id)
93
- # check_simulation(game_id)
94
- # response = get request_url("games/#{ game_id }/pbp")
95
- # Sportradar::Api::Nfl::Game.new response["game"] if response.success? && response["game"]
96
- # # need to get into quarters, drives, plays, stats more still
97
- # end
98
-
99
- # # player_id = "ede260be-5ae6-4a06-887b-e4a130932705"
100
- # def player_profile(player_id)
101
- # response = get request_url("players/#{ player_id }/profile")
102
- # Sportradar::Api::Nfl::Player.new response["player"] if response.success? && response["player"]
103
- # end
104
-
105
- # # team_id = "97354895-8c77-4fd4-a860-32e62ea7382a"
106
- # def seasonal_statistics(team_id, year = Date.today.year, season = "reg")
107
- # raise Sportradar::Api::Error::InvalidLeague unless allowed_seasons.include? season
108
- # response = get request_url("seasontd/#{ year }/#{ season }/teams/#{ team_id }/statistics")
109
- # Sportradar::Api::Nfl::Season.new response["season"] if response.success? && response["season"]
110
- # # TODO: Object map team & player records - statistics
111
- # end
112
-
113
- # def team_profile(team_id)
114
- # response = get request_url("teams/#{ team_id }/profile")
115
- # Sportradar::Api::Nfl::Team.new response["team"] if response.success? && response["team"]
116
- # end
117
-
118
- # def league_hierarchy
119
- # response = get request_url("league/hierarchy")
120
- # Sportradar::Api::Nfl::Hierarchy.new response["league"] if response.success? && response["league"]
121
- # end
122
-
123
- # def standings(year = Date.today.year)
124
- # response = get request_url("seasontd/#{ year }/standings")
125
- # Sportradar::Api::Nfl::Season.new response["season"] if response.success? && response["season"]
126
- # # TODO Needs implement rankings/records/stats on team
127
- # end
128
-
129
- # def daily_change_log(date = Date.today)
130
- # response = get request_url("league/#{date_path(date)}/changes")
131
- # Sportradar::Api::Nfl::Changelog.new response["league"]["changelog"] if response.success? && response["league"] && response["league"]["changelog"]
132
- # end
133
-
134
- # def simulation_games
135
- # [
136
- # # "f45b4a31-b009-4039-8394-42efbc6d5532",
137
- # # "5a7042cb-fe7a-4838-b93f-6b8c167ec384",
138
- # # "7f761bb5-7963-43ea-a01b-baf4f5d50fe3"
139
- # ]
140
- # end
141
-
142
- # def active_simulation
143
- # game = simulation_games.lazy.map {|game_id| game_boxscore game_id }.find{ |game| game.status == 'inprogress'}
144
- # if game
145
- # puts "Live Game: #{game.summary.home.full_name} vs #{game.summary.away.full_name}. Q#{game.quarter} #{game.clock}. game_id='#{game.id}'"
146
- # game
147
- # else
148
- # puts "No active simulation"
149
- # end
150
- # end
151
-
152
- def get_data(url)
153
- get request_url(url)
37
+ # url path helpers
38
+ def self.path_competitions
39
+ "competitions"
154
40
  end
155
41
 
156
- private
157
-
158
- # def check_simulation(game_id)
159
- # @simulation = true if simulation_games.include?(game_id)
160
- # end
161
-
162
- def request_url(path)
163
- "/mma-#{access_level}#{version}/#{path}"
42
+ def self.get_seasons
43
+ data = api.get_data(path_seasons).to_h
44
+ parse_seasons(data)
164
45
  end
165
46
 
166
- def api_key
167
- if access_level != 't'
168
- Sportradar::Api.api_key_params('mma', 'production')
169
- else
170
- Sportradar::Api.api_key_params('mma')
47
+ def self.parse_seasons(data)
48
+ if data['seasons']
49
+ data['seasons'].map do |hash|
50
+ Season.new(hash, api: api)
51
+ end
171
52
  end
172
53
  end
173
54
 
174
- def version
175
- Sportradar::Api.version('mma')
55
+ # url path helpers
56
+ def self.path_seasons
57
+ "seasons"
176
58
  end
177
59
 
178
- def allowed_access_levels
179
- %w[p t]
60
+ def self.api
61
+ @api ||= Sportradar::Api::Mma::Api.new
180
62
  end
181
63
 
182
64
  end
@@ -185,11 +67,14 @@ end
185
67
 
186
68
  __END__
187
69
 
188
- sr = Sportradar::Api::Mma.new
189
- ss = sr.schedule;
190
- sp = sr.participants;
191
-
192
- ss.games.count
193
- ss.weeks.count
194
- ss.weeks.first.response['game'].count
195
-
70
+ comps = Sportradar::Api::Mma.get_competitions;
71
+ comp = comps.first
72
+ comp.get_seasons
73
+ sea = comp.seasons.first
74
+
75
+ seasons = Sportradar::Api::Mma.get_seasons
76
+ sea = seasons.detect { |s| s.id == "sr:season:94429" }
77
+ sea.get_competitors
78
+ sea.get_summary
79
+ fight = sea.fights.detect { |f| f.id == "sr:sport_event:34102625" }
80
+ fight.title
@@ -56,6 +56,7 @@ module Sportradar
56
56
  puts response.inspect
57
57
  Sportradar::Api::Error.new(response.code, response.message, response)
58
58
  else
59
+ File.write("response.json", JSON.pretty_generate(response.to_h)) if ENV['SPORTRADAR_LOG']
59
60
  response
60
61
  end
61
62
  end
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.19.4"
3
+ VERSION = "0.20.0"
4
4
  end
5
5
  end
@@ -27,17 +27,6 @@ require "sportradar/api/images/ref"
27
27
  require "sportradar/api/images/tag"
28
28
 
29
29
  require "sportradar/api/mma"
30
- require "sportradar/api/mma/schedule"
31
- require "sportradar/api/mma/roster"
32
- require "sportradar/api/mma/fighter"
33
- require "sportradar/api/mma/event"
34
- require "sportradar/api/mma/fight"
35
- require "sportradar/api/mma/judge"
36
- require "sportradar/api/mma/referee"
37
- require "sportradar/api/mma/result"
38
- require "sportradar/api/mma/score"
39
- require "sportradar/api/mma/venue"
40
- require "sportradar/api/mma/league"
41
30
 
42
31
 
43
32
  require "sportradar/api/content"
@@ -65,7 +54,7 @@ module Sportradar
65
54
  {api: :olympics, version: 2},
66
55
  {api: :soccer, version: 4},
67
56
  {api: :ncaawb, version: 3},
68
- {api: :mma, version: 1},
57
+ {api: :mma, version: 2},
69
58
  {api: :cricket, version: 1},
70
59
  {api: :wnba, version: 3},
71
60
  {api: :ncaamh, version: 3},
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.4
4
+ version: 0.20.0
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-22 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -392,6 +392,8 @@ files:
392
392
  - lib/sportradar/api/images/tag.rb
393
393
  - lib/sportradar/api/live_images.rb
394
394
  - lib/sportradar/api/mma.rb
395
+ - lib/sportradar/api/mma/api.rb
396
+ - lib/sportradar/api/mma/competition.rb
395
397
  - lib/sportradar/api/mma/event.rb
396
398
  - lib/sportradar/api/mma/fight.rb
397
399
  - lib/sportradar/api/mma/fighter.rb
@@ -402,6 +404,7 @@ files:
402
404
  - lib/sportradar/api/mma/roster.rb
403
405
  - lib/sportradar/api/mma/schedule.rb
404
406
  - lib/sportradar/api/mma/score.rb
407
+ - lib/sportradar/api/mma/season.rb
405
408
  - lib/sportradar/api/mma/venue.rb
406
409
  - lib/sportradar/api/odds.rb
407
410
  - lib/sportradar/api/odds/README.md