sportradar-api 0.1.38 → 0.9.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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +13 -10
- data/Guardfile +7 -0
- data/lib/sportradar/api/config.rb +4 -5
- data/lib/sportradar/api/content.rb +12 -4
- data/lib/sportradar/api/content/article.rb +1 -12
- data/lib/sportradar/api/content/article_list.rb +1 -12
- data/lib/sportradar/api/data.rb +16 -0
- data/lib/sportradar/api/error.rb +5 -2
- data/lib/sportradar/api/football/stat_pack.rb +4 -17
- data/lib/sportradar/api/football/stat_pack/defense.rb +1 -1
- data/lib/sportradar/api/football/stat_pack/extra_points.rb +4 -4
- data/lib/sportradar/api/football/stat_pack/passing.rb +1 -1
- data/lib/sportradar/api/football/stat_pack/penalties.rb +4 -3
- data/lib/sportradar/api/football/stat_pack/rushing.rb +1 -1
- data/lib/sportradar/api/images.rb +19 -6
- data/lib/sportradar/api/images/asset.rb +2 -26
- data/lib/sportradar/api/images/asset_list.rb +1 -12
- data/lib/sportradar/api/live_images.rb +5 -1
- data/lib/sportradar/api/nfl.rb +73 -17
- data/lib/sportradar/api/nfl/changelog.rb +2 -24
- data/lib/sportradar/api/nfl/conference.rb +1 -13
- data/lib/sportradar/api/nfl/depth_chart.rb +1 -0
- data/lib/sportradar/api/nfl/division.rb +1 -13
- data/lib/sportradar/api/nfl/drive.rb +2 -20
- data/lib/sportradar/api/nfl/franchise.rb +0 -1
- data/lib/sportradar/api/nfl/game.rb +14 -14
- data/lib/sportradar/api/nfl/game_statistic.rb +73 -15
- data/lib/sportradar/api/nfl/hierarchy.rb +3 -30
- data/lib/sportradar/api/nfl/league_depth_chart.rb +1 -4
- data/lib/sportradar/api/nfl/play.rb +11 -5
- data/lib/sportradar/api/nfl/player.rb +6 -10
- data/lib/sportradar/api/nfl/position.rb +1 -13
- data/lib/sportradar/api/nfl/quarter.rb +1 -6
- data/lib/sportradar/api/nfl/scoring.rb +4 -4
- data/lib/sportradar/api/nfl/season.rb +4 -44
- data/lib/sportradar/api/nfl/team.rb +6 -35
- data/lib/sportradar/api/nfl/team_depth_chart.rb +8 -7
- data/lib/sportradar/api/nfl/week.rb +1 -14
- data/lib/sportradar/api/request.rb +15 -18
- data/lib/sportradar/api/soccer.rb +55 -11
- data/lib/sportradar/api/soccer/boxscore.rb +1 -12
- data/lib/sportradar/api/soccer/category.rb +1 -12
- data/lib/sportradar/api/soccer/hierarchy.rb +2 -14
- data/lib/sportradar/api/soccer/match.rb +3 -3
- data/lib/sportradar/api/soccer/player.rb +4 -31
- data/lib/sportradar/api/soccer/ranking.rb +1 -14
- data/lib/sportradar/api/soccer/schedule.rb +1 -12
- data/lib/sportradar/api/soccer/season.rb +1 -14
- data/lib/sportradar/api/soccer/standing.rb +1 -12
- data/lib/sportradar/api/soccer/summary.rb +1 -13
- data/lib/sportradar/api/soccer/team.rb +4 -3
- data/lib/sportradar/api/soccer/tournament.rb +1 -14
- data/lib/sportradar/api/soccer/tournament_group.rb +1 -11
- data/lib/sportradar/api/version.rb +1 -1
- data/sportradar-api.gemspec +2 -0
- metadata +17 -3
- data/lib/sportradar/api/nfl/stat.rb +0 -7
|
@@ -8,36 +8,9 @@ module Sportradar
|
|
|
8
8
|
@id = data["id"]
|
|
9
9
|
@name = data["name"]
|
|
10
10
|
@alias = data["alias"]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def set_conferences
|
|
19
|
-
if response["conference"]
|
|
20
|
-
if response["conference"].is_a?(Array)
|
|
21
|
-
@conferences = response["conference"].map {|conference| Sportradar::Api::Nfl::Conference.new conference }
|
|
22
|
-
elsif response["conference"].is_a?(Hash)
|
|
23
|
-
@conferences = [ Sportradar::Api::Nfl::Conference.new(response["conference"]) ]
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def set_divisions
|
|
29
|
-
if conferences&.all? { |conference| conference.divisions }
|
|
30
|
-
@divisions = conferences.flat_map(&:divisions)
|
|
31
|
-
elsif response["division"]
|
|
32
|
-
if response["division"].is_a?(Array)
|
|
33
|
-
@divisions = response["division"].map {|division| Sportradar::Api::Nfl::Division.new division }
|
|
34
|
-
elsif response["division"].is_a?(Hash)
|
|
35
|
-
@divisions = [ Sportradar::Api::Nfl::Division.new(response["division"]) ]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def set_teams
|
|
11
|
+
@conferences = parse_into_array(selector: data["conference"], klass: Sportradar::Api::Nfl::Conference) if data["conference"]
|
|
12
|
+
@divisions = conferences.flat_map(&:divisions) if conferences&.all? { |conference| conference.divisions }
|
|
13
|
+
@divisions ||= parse_into_array(selector: data["division"], klass: Sportradar::Api::Nfl::Division) if data["division"]
|
|
41
14
|
@teams = @divisions.flat_map(&:teams) if divisions&.all? {|division| division.teams }
|
|
42
15
|
end
|
|
43
16
|
|
|
@@ -6,13 +6,10 @@ module Sportradar
|
|
|
6
6
|
|
|
7
7
|
def initialize(data)
|
|
8
8
|
@response = data
|
|
9
|
-
depth_chart_data = data["season"]
|
|
9
|
+
depth_chart_data = data["season"]['depth_charts']
|
|
10
10
|
@season = Sportradar::Api::Nfl::Season.new data["season"] if data["season"]
|
|
11
11
|
# @teams = depth_chart_data["team"].map {|team| Sportradar::Api::Nfl::Team.new team } if depth_chart_data["team"]
|
|
12
12
|
@charts = depth_chart_data["team"].map {|team| Sportradar::Api::Nfl::TeamDepthChart.new(team, season) } if depth_chart_data["team"]
|
|
13
|
-
rescue => e
|
|
14
|
-
puts e.message
|
|
15
|
-
# binding.pry
|
|
16
13
|
end
|
|
17
14
|
|
|
18
15
|
# id is preferred search, but we allow for team abbreviation too
|
|
@@ -19,15 +19,21 @@ module Sportradar
|
|
|
19
19
|
@scoring_play = data["scoring_play"]
|
|
20
20
|
@sequence = data["sequence"]
|
|
21
21
|
@start_situation = Sportradar::Api::Nfl::Situation.new data["start_situation"] if data["start_situation"]
|
|
22
|
-
@statistics = OpenStruct.new data["statistics"] if data["statistics"] # TODO Implement statistics
|
|
23
|
-
if @statistics
|
|
24
|
-
play_stats = @statistics.penalty || @statistics.rush || @statistics.return || @statistics.receive
|
|
25
|
-
@player_id = play_stats.dig('player', 'id') if play_stats
|
|
26
|
-
end
|
|
22
|
+
@statistics = OpenStruct.new data["statistics"] if data["statistics"] # TODO Implement statistics!
|
|
23
|
+
parse_player if @statistics
|
|
27
24
|
@type = data["type"]
|
|
28
25
|
@wall_clock = data["wall_clock"]
|
|
29
26
|
end
|
|
30
27
|
|
|
28
|
+
def parse_player
|
|
29
|
+
# TODO: Currently there is an issue where we are only mapping one player_id to a play, but there are plays with multiple players involved.
|
|
30
|
+
play_stats = @statistics.penalty || @statistics.rush || @statistics.return || @statistics.receive
|
|
31
|
+
if play_stats.is_a?(Array)
|
|
32
|
+
play_stats = play_stats.first
|
|
33
|
+
end
|
|
34
|
+
@player_id = play_stats.dig('player', 'id') if play_stats
|
|
35
|
+
end
|
|
36
|
+
|
|
31
37
|
end
|
|
32
38
|
end
|
|
33
39
|
end
|
|
@@ -33,18 +33,14 @@ module Sportradar
|
|
|
33
33
|
@team = Sportradar::Api::Nfl::Team.new data["team"] if data["team"]
|
|
34
34
|
@injury = Sportradar::Api::Nfl::Injury.new data["injury"] if data["injury"]
|
|
35
35
|
@draft = Sportradar::Api::Nfl::Draft.new data["draft"] if data["draft"]
|
|
36
|
-
|
|
36
|
+
@seasons = parse_into_array(selector: response["season"], klass: Sportradar::Api::Nfl::Season) if response["season"]
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@seasons = response["season"].map {|season| Sportradar::Api::Nfl::Season.new season }
|
|
45
|
-
elsif response["season"].is_a?(Hash)
|
|
46
|
-
@seasons = [ Sportradar::Api::Nfl::Season.new(response["season"]) ]
|
|
47
|
-
end
|
|
39
|
+
def age
|
|
40
|
+
if birth_date.present?
|
|
41
|
+
now = Time.now.utc.to_date
|
|
42
|
+
dob = birth_date.to_date
|
|
43
|
+
now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
|
|
48
44
|
end
|
|
49
45
|
end
|
|
50
46
|
|
|
@@ -6,19 +6,7 @@ module Sportradar
|
|
|
6
6
|
def initialize(data)
|
|
7
7
|
@response = data
|
|
8
8
|
@name = data["name"]
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
def set_players
|
|
15
|
-
if response["player"]
|
|
16
|
-
if response["player"].is_a?(Array)
|
|
17
|
-
@players = response["player"].map {|player| Sportradar::Api::Nfl::Player.new player }
|
|
18
|
-
elsif response["player"].is_a?(Hash)
|
|
19
|
-
@players = [ Sportradar::Api::Nfl::Player.new(response["player"]) ]
|
|
20
|
-
end
|
|
21
|
-
end
|
|
9
|
+
@players = parse_into_array(selector: response["player"], klass: Sportradar::Api::Nfl::Player) if response["player"]
|
|
22
10
|
end
|
|
23
11
|
|
|
24
12
|
end
|
|
@@ -12,12 +12,7 @@ module Sportradar
|
|
|
12
12
|
# @home_points = response['scoring']['home']['points'] # from play_by_play
|
|
13
13
|
@away_points = data["away_points"]
|
|
14
14
|
# @away_points = response['scoring']['away']['points'] # from play_by_play
|
|
15
|
-
@drives = if
|
|
16
|
-
raw_drives = raw_drives.is_a?(Hash) ? [ raw_drives ] : raw_drives
|
|
17
|
-
raw_drives.map{ |drive| Sportradar::Api::Nfl::Drive.new drive }
|
|
18
|
-
else
|
|
19
|
-
[]
|
|
20
|
-
end
|
|
15
|
+
@drives = parse_into_array(selector: response["play_by_play"]["drive"], klass: Sportradar::Api::Nfl::Drive) if response["play_by_play"] && response["play_by_play"]["drive"]
|
|
21
16
|
end
|
|
22
17
|
|
|
23
18
|
end
|
|
@@ -5,8 +5,8 @@ module Sportradar
|
|
|
5
5
|
|
|
6
6
|
def initialize(data)
|
|
7
7
|
@response = data
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
response['quarter'] = response['quarter'].select {|x| x.is_a? Hash } if response['quarter'].is_a?(Array) && response['quarter'].map(&:class).uniq.count > 1
|
|
9
|
+
@quarters = parse_into_array(selector: response["quarter"], klass: Sportradar::Api::Nfl::Quarter) if response["quarter"]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def final
|
|
@@ -14,11 +14,11 @@ module Sportradar
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def home
|
|
17
|
-
quarters.map {|quarter| quarter
|
|
17
|
+
quarters.map {|quarter| quarter.home_points.to_i }.reduce(:+)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def away
|
|
21
|
-
quarters.map {|quarter| quarter
|
|
21
|
+
quarters.map {|quarter| quarter.away_points.to_i }.reduce(:+)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -11,50 +11,10 @@ module Sportradar
|
|
|
11
11
|
@name = data["name"]
|
|
12
12
|
@team = Sportradar::Api::Nfl::Team.new(data["team"]) if data["team"].is_a?(Hash)
|
|
13
13
|
@injuries = data["injuries"]["team"].map {|team| Sportradar::Api::Nfl::Team.new team } if data["injuries"] && data["injuries"]["team"]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def set_weeks
|
|
23
|
-
if response["week"]
|
|
24
|
-
if response["week"].is_a?(Array)
|
|
25
|
-
@weeks = response["week"].map {|week| Sportradar::Api::Nfl::Week.new week }
|
|
26
|
-
elsif response["week"].is_a?(Hash)
|
|
27
|
-
@weeks = [ Sportradar::Api::Nfl::Week.new(response["week"]) ]
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# set_(conferences|divisions|teams) are all identical to the same methods in Hierarchy
|
|
33
|
-
# There is likely more overlap between Sportradar's NFL standings and NFL hierarchy APIs
|
|
34
|
-
# Eventually, these should be shared between classes
|
|
35
|
-
def set_conferences
|
|
36
|
-
if response["conference"]
|
|
37
|
-
if response["conference"].is_a?(Array)
|
|
38
|
-
@conferences = response["conference"].map {|conference| Sportradar::Api::Nfl::Conference.new conference }
|
|
39
|
-
elsif response["conference"].is_a?(Hash)
|
|
40
|
-
@conferences = [ Sportradar::Api::Nfl::Conference.new(response["conference"]) ]
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def set_divisions
|
|
46
|
-
if conferences&.all? { |conference| conference.divisions }
|
|
47
|
-
@divisions = conferences.flat_map(&:divisions)
|
|
48
|
-
elsif response["division"]
|
|
49
|
-
if response["division"].is_a?(Array)
|
|
50
|
-
@divisions = response["division"].map {|division| Sportradar::Api::Nfl::Division.new division }
|
|
51
|
-
elsif response["division"].is_a?(Hash)
|
|
52
|
-
@divisions = [ Sportradar::Api::Nfl::Division.new(response["division"]) ]
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def set_teams
|
|
14
|
+
@weeks = parse_into_array(selector: response["week"], klass: Sportradar::Api::Nfl::Week) if response["week"]
|
|
15
|
+
@conferences = parse_into_array(selector: response["conference"], klass: Sportradar::Api::Nfl::Conference) if response["conference"]
|
|
16
|
+
@divisions = conferences.flat_map(&:divisions) if conferences&.all? { |conference| conference.divisions }
|
|
17
|
+
@divisions ||= parse_into_array(selector: response["division"], klass: Sportradar::Api::Nfl::Division) if response["division"]
|
|
58
18
|
@teams = @divisions.flat_map(&:teams) if divisions&.all? {|division| division.teams }
|
|
59
19
|
end
|
|
60
20
|
|
|
@@ -29,15 +29,16 @@ module Sportradar
|
|
|
29
29
|
@win_pct = data["win_pct"].to_f if data["win_pct"]
|
|
30
30
|
@rank = data["rank"]
|
|
31
31
|
|
|
32
|
-
@defense = data["defense"]["position"].map {|position| Sportradar::Api::Nfl::Position.new position } if data["defense"] && data["defense"]["position"]
|
|
33
|
-
@offense = data["offense"]["position"].map {|position| Sportradar::Api::Nfl::Position.new position } if data["offense"] && data["offense"]["position"]
|
|
34
|
-
@special_teams = data["special_teams"]["position"].map {|position| Sportradar::Api::Nfl::Position.new position } if data["special_teams"] && data["special_teams"]["position"]
|
|
35
32
|
@statistics = OpenStruct.new data["statistics"] if data["statistics"] # TODO Implement better?
|
|
36
33
|
@team_records = OpenStruct.new data["team_records"] if data["team_records"] # TODO Implement better?
|
|
37
34
|
@player_records = OpenStruct.new data["player_records"] if data["player_records"] # TODO Implement better?
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
@defense = parse_into_array(selector: data["defense"]["position"], klass: Sportradar::Api::Nfl::Position) if data["defense"] && data["defense"]["position"]
|
|
37
|
+
@offense = parse_into_array(selector: data["offense"]["position"], klass: Sportradar::Api::Nfl::Position) if data["offense"] && data["offense"]["position"]
|
|
38
|
+
@special_teams = parse_into_array(selector: data["special_teams"]["position"], klass: Sportradar::Api::Nfl::Position) if data["special_teams"] && data["special_teams"]["position"]
|
|
39
|
+
@coaches = parse_into_array(selector: response["coaches"]["coach"], klass: Sportradar::Api::Nfl::Coach) if response["coaches"] && response["coaches"]["coach"]
|
|
40
|
+
@players = parse_into_array(selector: response["player"], klass: Sportradar::Api::Nfl::Player) if response["player"]
|
|
41
|
+
@players ||= parse_into_array(selector: response["players"]["player"], klass: Sportradar::Api::Nfl::Player) if response["players"] && response["players"]["player"]
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def full_name
|
|
@@ -50,36 +51,6 @@ module Sportradar
|
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
53
|
-
private
|
|
54
|
-
|
|
55
|
-
def set_players
|
|
56
|
-
if response["player"]
|
|
57
|
-
if response["player"].is_a?(Array)
|
|
58
|
-
@players = response["player"].map {|player| Sportradar::Api::Nfl::Player.new player }
|
|
59
|
-
elsif response["player"].is_a?(Hash)
|
|
60
|
-
@players = [ Sportradar::Api::Nfl::Player.new(response["player"]) ]
|
|
61
|
-
end
|
|
62
|
-
elsif response["players"] && response["players"]["player"]
|
|
63
|
-
if response["players"]["player"].is_a?(Array)
|
|
64
|
-
@players = response["players"]["player"].map {|player| Sportradar::Api::Nfl::Player.new player }
|
|
65
|
-
elsif response["players"]["player"].is_a?(Hash)
|
|
66
|
-
@players = [ Sportradar::Api::Nfl::Player.new(response["players"]["player"]) ]
|
|
67
|
-
end
|
|
68
|
-
else
|
|
69
|
-
@players = []
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def set_coaches
|
|
74
|
-
if response["coaches"] && response["coaches"]["coach"]
|
|
75
|
-
if response["coaches"]["coach"].is_a?(Array)
|
|
76
|
-
@coaches = response["coaches"]["coach"].map {|coach| Sportradar::Api::Nfl::Coach.new coach }
|
|
77
|
-
elsif response["coaches"]["coach"].is_a?(Hash)
|
|
78
|
-
@coaches = [ Sportradar::Api::Nfl::Coach.new(response["coaches"]["coach"]) ]
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
54
|
end
|
|
84
55
|
end
|
|
85
56
|
end
|
|
@@ -13,15 +13,15 @@ module Sportradar
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def offense
|
|
16
|
-
@offense ||= Sportradar::Api::Nfl::DepthChart.new(response['offense'])
|
|
16
|
+
@offense ||= Sportradar::Api::Nfl::DepthChart.new(response['offense']) if response['offense']
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def defense
|
|
20
|
-
@defense ||= Sportradar::Api::Nfl::DepthChart.new(response['defense'])
|
|
20
|
+
@defense ||= Sportradar::Api::Nfl::DepthChart.new(response['defense']) if response['defense']
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def special_teams
|
|
24
|
-
@special_teams ||= Sportradar::Api::Nfl::DepthChart.new(response['special_teams'])
|
|
24
|
+
@special_teams ||= Sportradar::Api::Nfl::DepthChart.new(response['special_teams']) if response['special_teams']
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def team
|
|
@@ -32,11 +32,12 @@ module Sportradar
|
|
|
32
32
|
[:offense, :defense, :special_teams].each { |type| yield type, send(type) }
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
# These aren't ever used, but handy if you need to invoke for testing
|
|
36
|
+
# private
|
|
36
37
|
|
|
37
|
-
def set_charts
|
|
38
|
-
|
|
39
|
-
end
|
|
38
|
+
# def set_charts
|
|
39
|
+
# [offense, defense, special_teams]
|
|
40
|
+
# end
|
|
40
41
|
|
|
41
42
|
end
|
|
42
43
|
end
|
|
@@ -3,25 +3,12 @@ module Sportradar
|
|
|
3
3
|
class Nfl::Week < Data
|
|
4
4
|
attr_accessor :response, :id, :sequence, :title, :games
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
def initialize(data)
|
|
8
7
|
@response = data
|
|
9
8
|
@id = data["id"]
|
|
10
9
|
@sequence = data["sequence"]
|
|
11
10
|
@title = data["title"]
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def set_games
|
|
18
|
-
if response["game"]
|
|
19
|
-
if response["game"].is_a?(Array)
|
|
20
|
-
@games = response["game"].map {|game| Sportradar::Api::Nfl::Game.new game }
|
|
21
|
-
elsif response["game"].is_a?(Hash)
|
|
22
|
-
@games = [ Sportradar::Api::Nfl::Game.new(response["game"]) ]
|
|
23
|
-
end
|
|
24
|
-
end
|
|
11
|
+
@games = parse_into_array(selector: response["game"], klass: Sportradar::Api::Nfl::Game) if response["game"]
|
|
25
12
|
end
|
|
26
13
|
|
|
27
14
|
end
|
|
@@ -6,31 +6,28 @@ module Sportradar
|
|
|
6
6
|
|
|
7
7
|
attr_reader :url, :headers, :timeout, :api_key
|
|
8
8
|
|
|
9
|
-
def base_setup(path, options={})
|
|
10
|
-
@url = set_base(path)
|
|
11
|
-
@url += format unless options[:format] == 'none'
|
|
12
|
-
@headers = set_headers unless options[:format] == 'none'
|
|
13
|
-
@api_key = options[:api_key]
|
|
14
|
-
@timeout = options.delete(:api_timeout) || Sportradar::Api.config.api_timeout
|
|
15
|
-
end
|
|
16
|
-
|
|
17
9
|
def get(path, options={})
|
|
18
10
|
base_setup(path, options)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if response.success?
|
|
26
|
-
response
|
|
27
|
-
else
|
|
28
|
-
Sportradar::Api::Error.new(response.code, response.message, response)
|
|
11
|
+
begin
|
|
12
|
+
response = self.class.get(url, headers: headers, query: options.merge(api_key), timeout: timeout)
|
|
13
|
+
rescue Net::ReadTimeout, Net::OpenTimeout
|
|
14
|
+
raise Sportradar::Api::Error::Timeout
|
|
15
|
+
rescue EOFError
|
|
16
|
+
raise Sportradar::Api::Error::NoData
|
|
29
17
|
end
|
|
18
|
+
return Sportradar::Api::Error.new(response.code, response.message, response) unless response.success?
|
|
19
|
+
response
|
|
30
20
|
end
|
|
31
21
|
|
|
32
22
|
private
|
|
33
23
|
|
|
24
|
+
def base_setup(path, options={})
|
|
25
|
+
@url = set_base(path)
|
|
26
|
+
@url += format unless options[:format] == 'none'
|
|
27
|
+
@headers = set_headers unless options[:format] == 'none'
|
|
28
|
+
@timeout = options.delete(:api_timeout) || Sportradar::Api.config.api_timeout
|
|
29
|
+
end
|
|
30
|
+
|
|
34
31
|
def set_base(path)
|
|
35
32
|
protocol = !!Sportradar::Api.config.use_ssl ? "https://" : "http://"
|
|
36
33
|
url = "#{protocol}api.sportradar.us"
|
|
@@ -11,65 +11,109 @@ module Sportradar
|
|
|
11
11
|
|
|
12
12
|
def schedule
|
|
13
13
|
response = get request_url("matches/schedule")
|
|
14
|
-
|
|
14
|
+
if response.success?
|
|
15
|
+
Sportradar::Api::Soccer::Schedule.new response
|
|
16
|
+
else
|
|
17
|
+
response
|
|
18
|
+
end
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
# date = Date.parse('2016-07-17')
|
|
18
22
|
def daily_schedule(date = Date.today)
|
|
19
23
|
response = get request_url("matches/#{date_path(date)}/schedule")
|
|
20
|
-
|
|
24
|
+
if response.success?
|
|
25
|
+
Sportradar::Api::Soccer::Schedule.new response
|
|
26
|
+
else
|
|
27
|
+
response
|
|
28
|
+
end
|
|
21
29
|
end
|
|
22
30
|
|
|
23
31
|
|
|
24
32
|
def daily_summary(date = Date.today)
|
|
25
33
|
response = get request_url("matches/#{date_path(date)}/summary")
|
|
26
|
-
|
|
34
|
+
if response.success?
|
|
35
|
+
Sportradar::Api::Soccer::Summary.new response
|
|
36
|
+
else
|
|
37
|
+
response
|
|
38
|
+
end
|
|
27
39
|
end
|
|
28
40
|
|
|
29
41
|
def daily_boxscore(date = Date.today)
|
|
30
42
|
response = get request_url("matches/#{date_path(date)}/boxscore")
|
|
31
|
-
|
|
43
|
+
if response.success?
|
|
44
|
+
Sportradar::Api::Soccer::Boxscore.new response
|
|
45
|
+
else
|
|
46
|
+
response
|
|
47
|
+
end
|
|
32
48
|
end
|
|
33
49
|
|
|
34
50
|
# match_id = "357607e9-87cd-4848-b53e-0485d9c1a3bc"
|
|
35
51
|
def match_summary(match_id)
|
|
36
52
|
check_simulation(match_id)
|
|
37
53
|
response = get request_url("matches/#{match_id}/summary")
|
|
38
|
-
|
|
54
|
+
if response.success?
|
|
55
|
+
Sportradar::Api::Soccer::Summary.new response
|
|
56
|
+
else
|
|
57
|
+
response
|
|
58
|
+
end
|
|
39
59
|
end
|
|
40
60
|
|
|
41
61
|
# match_id = "357607e9-87cd-4848-b53e-0485d9c1a3bc"
|
|
42
62
|
def match_boxscore(match_id)
|
|
43
63
|
check_simulation(match_id)
|
|
44
64
|
response = get request_url("matches/#{match_id}/boxscore")
|
|
45
|
-
|
|
65
|
+
if response.success?
|
|
66
|
+
Sportradar::Api::Soccer::Boxscore.new response
|
|
67
|
+
else
|
|
68
|
+
response
|
|
69
|
+
end
|
|
46
70
|
end
|
|
47
71
|
|
|
48
72
|
# team_id = "b78b9f61-0697-4347-a1b6-b7685a130eb1"
|
|
49
73
|
def team_profile(team_id)
|
|
50
74
|
response = get request_url("teams/#{team_id}/profile")
|
|
51
|
-
|
|
75
|
+
if response.success? && response["profile"] && response["profile"]["team"]
|
|
76
|
+
Sportradar::Api::Soccer::Team.new response["profile"]["team"]
|
|
77
|
+
else
|
|
78
|
+
response
|
|
79
|
+
end
|
|
52
80
|
end
|
|
53
81
|
|
|
54
82
|
# player_id = "2aeacd39-3f9c-42af-957e-9df8573973c4"
|
|
55
83
|
def player_profile(player_id)
|
|
56
84
|
response = get request_url("players/#{player_id}/profile")
|
|
57
|
-
|
|
85
|
+
if response.success? && response["profile"] && response["profile"]["player"]
|
|
86
|
+
Sportradar::Api::Soccer::Player.new response["profile"]["player"]
|
|
87
|
+
else
|
|
88
|
+
response
|
|
89
|
+
end
|
|
58
90
|
end
|
|
59
91
|
|
|
60
92
|
def player_rankings
|
|
61
93
|
response = get request_url("players/leader")
|
|
62
|
-
|
|
94
|
+
if response.success? && response["leaders"]
|
|
95
|
+
Sportradar::Api::Soccer::Ranking.new response["leaders"]
|
|
96
|
+
else
|
|
97
|
+
response
|
|
98
|
+
end
|
|
63
99
|
end
|
|
64
100
|
|
|
65
101
|
def team_hierarchy
|
|
66
102
|
response = get request_url("teams/hierarchy")
|
|
67
|
-
|
|
103
|
+
if response.success? && response["hierarchy"]
|
|
104
|
+
Sportradar::Api::Soccer::Hierarchy.new response["hierarchy"]
|
|
105
|
+
else
|
|
106
|
+
response
|
|
107
|
+
end
|
|
68
108
|
end
|
|
69
109
|
|
|
70
110
|
def team_standings
|
|
71
111
|
response = get request_url("teams/standing")
|
|
72
|
-
|
|
112
|
+
if response.success?
|
|
113
|
+
Sportradar::Api::Soccer::Standing.new response["standings"]
|
|
114
|
+
else
|
|
115
|
+
response
|
|
116
|
+
end
|
|
73
117
|
end
|
|
74
118
|
|
|
75
119
|
def simulation_match
|