sportradar-api 0.19.5 → 0.20.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sportradar/api/football/stats_shim.rb +1 -1
- data/lib/sportradar/api/mma/api.rb +59 -0
- data/lib/sportradar/api/mma/competition.rb +62 -0
- data/lib/sportradar/api/mma/event.rb +1 -1
- data/lib/sportradar/api/mma/fight.rb +65 -44
- data/lib/sportradar/api/mma/fighter.rb +17 -17
- data/lib/sportradar/api/mma/judge.rb +2 -2
- data/lib/sportradar/api/mma/league.rb +1 -1
- data/lib/sportradar/api/mma/referee.rb +2 -2
- data/lib/sportradar/api/mma/result.rb +2 -2
- data/lib/sportradar/api/mma/roster.rb +1 -1
- data/lib/sportradar/api/mma/schedule.rb +1 -1
- data/lib/sportradar/api/mma/score.rb +2 -2
- data/lib/sportradar/api/mma/season.rb +102 -0
- data/lib/sportradar/api/mma/venue.rb +1 -1
- data/lib/sportradar/api/mma.rb +52 -167
- data/lib/sportradar/api/request.rb +1 -0
- data/lib/sportradar/api/version.rb +1 -1
- data/lib/sportradar/api.rb +1 -12
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59b7c64c57502e09e0710bab7364fa547678c09db700de7d9a9995a118c077e3
|
4
|
+
data.tar.gz: 7304057033316bda190fc8a9531686b745b6c63ca496d755c60080b61082579d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd54b0aa75e0f0c7679b41012357455ef6788192946b7725061782e728c1faa77f935ddbb2791eea741476898082b24996225a1bfe781c0f9c79b3319340aa40
|
7
|
+
data.tar.gz: cc3d800dc061431e86eafd74c6fcdc4111c23199cdc3f0a196d7c618d900f988ad1abd78752587d5ea761499fef94079925fc59292c1a07c141f06ac6021d958
|
data/Gemfile.lock
CHANGED
@@ -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,80 +1,101 @@
|
|
1
1
|
module Sportradar
|
2
2
|
module Api
|
3
|
-
|
3
|
+
module Mma
|
4
4
|
class Fight < Data
|
5
|
-
attr_accessor :response, :id, :
|
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
|
20
6
|
|
21
7
|
def initialize(data, **opts)
|
22
8
|
@response = data
|
23
9
|
@api = opts[:api]
|
24
|
-
@
|
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
|
-
|
43
|
-
|
44
|
-
|
24
|
+
if data["sport_event"]
|
25
|
+
update(data["sport_event"])
|
26
|
+
end
|
27
|
+
if data["sport_event_status"]
|
28
|
+
update(data["sport_event_status"])
|
29
|
+
end
|
30
|
+
|
31
|
+
@id = data['id'] if data['id'] && !@id
|
32
|
+
@start_time = Time.parse(data['start_time']) if data['start_time']
|
33
|
+
@start_time_confirmed = data['start_time_confirmed'] if data['start_time_confirmed']
|
34
|
+
@sport_event_context = data['sport_event_context'] if data['sport_event_context']
|
35
|
+
@coverage = data['coverage'] if data['coverage']
|
36
|
+
@venue = data['venue'] if data['venue']
|
45
37
|
|
46
|
-
@
|
47
|
-
@
|
38
|
+
@status = data['status'] if data['status']
|
39
|
+
@match_status = data['match_status'] if data['match_status']
|
40
|
+
@winner_id = data['winner_id'] if data['winner_id']
|
41
|
+
@final_round = data['final_round'] if data['final_round']
|
42
|
+
@final_round_length = data['final_round_length'] if data['final_round_length']
|
43
|
+
@end_method = data['method'] if data['method']
|
44
|
+
@winner = data['winner'] if data['winner']
|
45
|
+
@scheduled_length = data['scheduled_length'] if data['scheduled_length']
|
46
|
+
@weight_class = data['weight_class'] if data['weight_class']
|
47
|
+
@title_fight = data['title_fight'] if data['title_fight']
|
48
48
|
|
49
|
-
|
49
|
+
|
50
|
+
update_fighters(data) if data['competitors']
|
50
51
|
|
51
52
|
self
|
52
53
|
end
|
53
54
|
|
55
|
+
def season_id
|
56
|
+
@season&.id || @sport_event_context&.dig('season', 'id')
|
57
|
+
end
|
58
|
+
|
59
|
+
def starts_at
|
60
|
+
@start_time
|
61
|
+
end
|
62
|
+
|
63
|
+
def coverage_level
|
64
|
+
'live' if @coverage&.dig('live')
|
65
|
+
end
|
66
|
+
|
67
|
+
def title
|
68
|
+
fighters.map(&:display_name).join(' vs ')
|
69
|
+
end
|
70
|
+
|
71
|
+
def scheduled
|
72
|
+
@start_time
|
73
|
+
end
|
74
|
+
|
54
75
|
def update_fighters(data)
|
55
|
-
|
76
|
+
if data['competitors']
|
77
|
+
create_data(@fighters_hash, data['competitors'], klass: Fighter, api: api, fight: self)
|
78
|
+
end
|
56
79
|
end
|
57
80
|
def api
|
58
81
|
@api ||= Sportradar::Api::Mma.new
|
59
82
|
end
|
60
83
|
|
61
84
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# def path_box
|
66
|
-
# "#{ path_base }/boxscore"
|
67
|
-
# end
|
68
|
-
# def path_pbp
|
69
|
-
# "#{ path_base }/pbp"
|
70
|
-
# end
|
85
|
+
def path_base
|
86
|
+
"sport_events/#{ id }"
|
87
|
+
end
|
71
88
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
89
|
+
def path_summary
|
90
|
+
"#{ path_base }/summary"
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_summary
|
94
|
+
data = api.get_data(path_summary)
|
95
|
+
update(data)
|
96
|
+
|
97
|
+
data
|
98
|
+
end
|
78
99
|
|
79
100
|
# def get_pbp
|
80
101
|
# data = api.get_data(path_pbp)['game']
|
@@ -1,22 +1,8 @@
|
|
1
1
|
module Sportradar
|
2
2
|
module Api
|
3
|
-
|
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"=>""}}
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
+
}
|
data/lib/sportradar/api/mma.rb
CHANGED
@@ -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
|
-
|
4
|
-
attr_accessor :league, :access_level, :simulation, :error
|
18
|
+
module Mma
|
5
19
|
|
6
|
-
def
|
7
|
-
|
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
|
13
|
-
|
14
|
-
|
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
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
#
|
55
|
-
|
56
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
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
|
167
|
-
if
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
175
|
-
|
55
|
+
# url path helpers
|
56
|
+
def self.path_seasons
|
57
|
+
"seasons"
|
176
58
|
end
|
177
59
|
|
178
|
-
def
|
179
|
-
|
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
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|
data/lib/sportradar/api.rb
CHANGED
@@ -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:
|
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.
|
4
|
+
version: 0.20.0.pre
|
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-
|
11
|
+
date: 2022-09-22 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
|
@@ -456,9 +459,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
456
459
|
version: '0'
|
457
460
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
458
461
|
requirements:
|
459
|
-
- - "
|
462
|
+
- - ">"
|
460
463
|
- !ruby/object:Gem::Version
|
461
|
-
version:
|
464
|
+
version: 1.3.1
|
462
465
|
requirements: []
|
463
466
|
rubygems_version: 3.0.3.1
|
464
467
|
signing_key:
|