sportradar-api 0.13.4 → 0.13.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/sportradar/api/basketball/game.rb +5 -4
  4. data/lib/sportradar/api/basketball/nba/quarter.rb +9 -2
  5. data/lib/sportradar/api/basketball/ncaamb/half.rb +9 -0
  6. data/lib/sportradar/api/soccer/README.md +4 -0
  7. data/lib/sportradar/api/soccer/event.rb +14 -13
  8. data/lib/sportradar/api/soccer/match.rb +120 -8
  9. data/lib/sportradar/api/soccer/player.rb +8 -2
  10. data/lib/sportradar/api/soccer/scoring.rb +24 -16
  11. data/lib/sportradar/api/soccer/team.rb +2 -0
  12. data/lib/sportradar/api/version.rb +1 -1
  13. metadata +3 -29
  14. data/lib/sportradar/api/soccer-old/boxscore.rb +0 -13
  15. data/lib/sportradar/api/soccer-old/category.rb +0 -17
  16. data/lib/sportradar/api/soccer-old/fact.rb +0 -61
  17. data/lib/sportradar/api/soccer-old/hierarchy.rb +0 -14
  18. data/lib/sportradar/api/soccer-old/match.rb +0 -55
  19. data/lib/sportradar/api/soccer-old/player.rb +0 -88
  20. data/lib/sportradar/api/soccer-old/ranking.rb +0 -13
  21. data/lib/sportradar/api/soccer-old/schedule.rb +0 -22
  22. data/lib/sportradar/api/soccer-old/season.rb +0 -14
  23. data/lib/sportradar/api/soccer-old/standing.rb +0 -13
  24. data/lib/sportradar/api/soccer-old/statistic.rb +0 -14
  25. data/lib/sportradar/api/soccer-old/summary.rb +0 -13
  26. data/lib/sportradar/api/soccer-old/team.rb +0 -63
  27. data/lib/sportradar/api/soccer-old/tournament.rb +0 -20
  28. data/lib/sportradar/api/soccer-old/tournament_group.rb +0 -35
  29. data/lib/sportradar/api/soccer-old/venue.rb +0 -21
  30. data/lib/sportradar/api/soccer-old.rb +0 -158
  31. data/soccer-old/boxscore_test.rb +0 -14
  32. data/soccer-old/hierarchy_test.rb +0 -14
  33. data/soccer-old/match_test.rb +0 -23
  34. data/soccer-old/player_test.rb +0 -40
  35. data/soccer-old/ranking_test.rb +0 -16
  36. data/soccer-old/schedule_test.rb +0 -24
  37. data/soccer-old/standing_test.rb +0 -14
  38. data/soccer-old/summary_test.rb +0 -14
  39. data/soccer-old/team_test.rb +0 -21
  40. data/soccer-old_test.rb +0 -184
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a16711fc16c1fe8cb6f89245196a545149929bc1
4
- data.tar.gz: 3ddf3e0c418cb2ac9f98fb943552dd6f7a76293d
3
+ metadata.gz: 3d49ce56fe5c2ca03df70263e5b216efe58d4fbb
4
+ data.tar.gz: 65d90cefb754021c67c6dda94fa53fb4f8ad33d9
5
5
  SHA512:
6
- metadata.gz: 52e1a6a9f6c7d99d908c5f862aa9bc2fc613957ec529d53758413eaee700515909bcd3ae6f4dc4f5aa01a1b1cd5fd13151dde9cdad115b2ebb39d3b4b5d3b9cc
7
- data.tar.gz: 3d0b8b56c18b5ba9595dd0bd453166b40af009b04fb48da5d215b7381dd389387b53585ee39e1c37297849b53df8e879507ce74866aac3badcc8de3dac77215e
6
+ metadata.gz: 43ac236b4a45c7178c929036d25a4ae99340bc8e8710a4307e9f7d5791079b5e547aca9757c11ee6ae44e525c786c35687db9140474e7c90dc23e48c164c25f6
7
+ data.tar.gz: 9ccedccca1160d5725a5553ea5b327884ffcae3cf11548910b5fcdd8e93dff9998fd250f371665d275bf35393cbdf3b79494c32cb17d4068c3b3716aff5b2f5e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sportradar-api (0.13.4)
4
+ sportradar-api (0.13.5)
5
5
  activesupport
6
6
  httparty (>= 0.14.0)
7
7
 
@@ -212,7 +212,7 @@ module Sportradar
212
212
  end
213
213
 
214
214
  def halftime?
215
- clock == '0:00' && quarter == 2
215
+ status == 'halftime' || clock == '00:00' && quarter == 2
216
216
  end
217
217
  def clock_display
218
218
  if clock && period
@@ -266,7 +266,7 @@ module Sportradar
266
266
  # data retrieval
267
267
 
268
268
  def get_box
269
- data = api.get_data(path_box)
269
+ data = api.get_data(path_box).to_h
270
270
  ingest_box(data)
271
271
  end
272
272
 
@@ -283,7 +283,7 @@ module Sportradar
283
283
  end
284
284
 
285
285
  def get_pbp
286
- data = api.get_data(path_pbp)
286
+ data = api.get_data(path_pbp).to_h
287
287
  ingest_pbp(data)
288
288
  end
289
289
 
@@ -305,12 +305,13 @@ module Sportradar
305
305
  set_pbp(period_data)
306
306
  @pbp = @periods_hash.values
307
307
  check_newness(:pbp, plays.last&.updated)
308
+ check_newness(:clock, @clock)
308
309
  check_newness(:score, @score)
309
310
  data
310
311
  end
311
312
 
312
313
  def get_summary
313
- data = api.get_data(path_summary)
314
+ data = api.get_data(path_summary).to_h
314
315
  ingest_summary(data)
315
316
  end
316
317
 
@@ -33,8 +33,15 @@ module Sportradar
33
33
  end
34
34
  def update(data, **opts)
35
35
  create_data(@plays_hash, data.dig('events'), klass: Play, api: @api, quarter: self)
36
- # rescue => e
37
- # binding.pry
36
+ end
37
+
38
+ def plays_by_type(play_type, *types)
39
+ if types.empty?
40
+ plays.grep(Play.subclass(play_type.delete('_')))
41
+ else
42
+ play_classes = [play_type, *types].map { |type| Play.subclass(type.delete('_')) }
43
+ plays.select { |play| play_classes.any? { |klass| play.kind_of?(klass) } }
44
+ end
38
45
  end
39
46
 
40
47
  def plays
@@ -35,6 +35,15 @@ module Sportradar
35
35
  create_data(@plays_hash, data.dig('events'), klass: Play, api: @api, half: self)
36
36
  end
37
37
 
38
+ def plays_by_type(play_type, *types)
39
+ if types.empty?
40
+ plays.grep(Play.subclass(play_type.delete('_')))
41
+ else
42
+ play_classes = [play_type, *types].map { |type| Play.subclass(type.delete('_')) }
43
+ plays.select { |play| play_classes.any? { |klass| play.kind_of?(klass) } }
44
+ end
45
+ end
46
+
38
47
  def plays
39
48
  @plays_hash.values
40
49
  end
@@ -0,0 +1,4 @@
1
+ # Sportradar Soccer
2
+
3
+ ![League Reference](https://www.evernote.com/l/ASYGl8UICK1A6q_yrarGw1iFpRLzyQP6HJ4B/image.png)
4
+
@@ -12,18 +12,19 @@ module Sportradar
12
12
  end
13
13
 
14
14
  def update(data, **opts)
15
- @type = data['type']
16
- @time = Time.parse(data['time']) if data['time']
17
- @period = data['period']
18
- @period_type = data['period_type']
19
- @period_name = data['period_name']
20
- @match_time = data['match_time']
21
- @team = data['team'] # home/away
22
- @x = data['x']
23
- @y = data['y']
24
- @outcome = data['outcome']
25
- @home_score = data['home_score']
26
- @away_score = data['away_score']
15
+ @type = data['type'] if data['type']
16
+ @time = Time.parse(data['time']) if data['time']
17
+ @period = data['period'] if data['period']
18
+ @period_type = data['period_type'] if data['period_type']
19
+ @period_name = data['period_name'] if data['period_name']
20
+ @match_time = data['match_time'] if data['match_time']
21
+ @team = data['team'] if data['team']
22
+ @x = data['x'] if data['x']
23
+ @y = data['y'] if data['y']
24
+ @outcome = data['outcome'] if data['outcome']
25
+ @home_score = data['home_score'] if data['home_score']
26
+ @away_score = data['away_score'] if data['away_score']
27
+ @commentaries = data['commentaries'] if data['commentaries']
27
28
  @goal_scorer = OpenStruct.new(data['goal_scorer']) if data['goal_scorer']
28
29
  @stoppage_time = data['stoppage_time'].to_i if data['stoppage_time']
29
30
  @player_out = OpenStruct.new(data['player_out']) if data['player_out']
@@ -31,7 +32,7 @@ module Sportradar
31
32
  @player = OpenStruct.new(data['player']) if data['player'] # red/yellow cards
32
33
  end
33
34
 
34
- def updated_at
35
+ def updated
35
36
  @time
36
37
  end
37
38
 
@@ -6,12 +6,15 @@ module Sportradar
6
6
  attr_reader :home_score, :away_score, :winner_id, :aggregate_home_score, :aggregate_away_score, :aggregate_winner_id
7
7
  attr_reader :referee, :weather_info, :coverage_info, :probabilities
8
8
  attr_reader :home, :away, :tournament_id
9
- attr_reader :clock, :period, :score, :scoring, :broadcast, :coverage # these are for consistency with other sports
9
+ attr_reader :period, :score, :broadcast, :coverage # these are for consistency with other sports
10
+ attr_reader :match_time, :stoppage_time
10
11
 
11
12
  def initialize(data = {}, league_group: nil, **opts)
12
13
  @response = data
13
14
  @id = data['id']
14
15
  @api = opts[:api]
16
+ @updates = {}
17
+ @changes = {}
15
18
 
16
19
  @league_group = league_group || data['league_group'] || @api&.league_group
17
20
 
@@ -49,7 +52,6 @@ module Sportradar
49
52
  update_teams(stats)
50
53
  end
51
54
 
52
-
53
55
  @scheduled = Time.parse(data['scheduled']) if data['scheduled']
54
56
  @start_time_tbd = data['start_time_tbd'] if data.key?('start_time_tbd')
55
57
  @status = data['status'] if data['status']
@@ -62,14 +64,18 @@ module Sportradar
62
64
 
63
65
  @home_score = data['home_score'] if data['home_score']
64
66
  @away_score = data['away_score'] if data['away_score']
67
+ @period = data['period'] if data['period']
68
+ @match_time = data.dig('clock', 'match_time') if data.dig('clock', 'match_time')
69
+ @stoppage_time = data.dig('clock', 'stoppage_time') if data.dig('clock', 'stoppage_time')
70
+ @ball_locations = data['ball_locations'] if data['ball_locations']
65
71
  @winner_id = data['winner_id'] if data['winner_id']
66
72
 
67
73
  @aggregate_home_score = data['aggregate_home_score'] if data['aggregate_home_score']
68
74
  @aggregate_away_score = data['aggregate_away_score'] if data['aggregate_away_score']
69
75
  @aggregate_winner_id = data['aggregate_winner_id'] if data['aggregate_winner_id']
76
+ @scoring_raw.update(data, source: opts[:source])
70
77
  create_data(@timeline_hash, data['timeline'], klass: Event, api: api)
71
- # @season
72
- # @tournament
78
+
73
79
  if data['competitors']
74
80
  update_teams(data['competitors'])
75
81
  end
@@ -80,14 +86,92 @@ module Sportradar
80
86
  def title
81
87
  [@home, @away].compact.map(&:name).join(' vs ')
82
88
  end
89
+ def scoring
90
+ @scoring_raw.scores.each { |period, hash| hash[@home.id] = hash['home']; hash[@away.id] = hash['away'] }
91
+ end
92
+ def score
93
+ {@home.id => @home_score, @away.id => @away_score}
94
+ end
95
+
96
+ # status helpers
97
+ def realtime_state_short
98
+ if future?
99
+ 'Scheduled' # ??
100
+ elsif finished?
101
+ 'FT'
102
+ elsif postponed?
103
+ 'PPD'
104
+ elsif halftime?
105
+ 'HT'
106
+ else
107
+ clock_display
108
+ end
109
+ end
83
110
 
84
111
  def realtime_state
85
-
112
+ if future?
113
+ 'Scheduled'
114
+ elsif finished?
115
+ 'Final'
116
+ elsif postponed?
117
+ 'Postponed'
118
+ elsif halftime?
119
+ 'Halftime'
120
+ else
121
+ clock_display
122
+ end
86
123
  end
87
124
 
88
- def scoring
89
- @scoring_raw.scores
125
+ def halftime?
126
+ @match_status == "halftime"
127
+ end
128
+
129
+ def postponed?
130
+ 'postponed' == status
131
+ end
132
+ def unnecessary?
133
+ 'unnecessary' == status
134
+ end
135
+ def cancelled?
136
+ ['unnecessary', 'postponed'].include? status
137
+ end
138
+ def future?
139
+ ['not_started', 'scheduled', 'delayed', 'created', 'time-tbd', 'if-necessary'].include? status
140
+ end
141
+ def started?
142
+ ['live'].include?(@status) || ['halftime', '1st_half', '2nd_half'].include?(@match_status)
90
143
  end
144
+ def finished?
145
+ ['complete', 'closed'].include?(@status) || ['ended'].include?(@match_status)
146
+ end
147
+ def completed?
148
+ 'complete' == status
149
+ end
150
+ def closed?
151
+ 'closed' == status
152
+ end
153
+
154
+ def clock_display
155
+ if @match_time == '45:00' || @match_time == '90:00' # stoppage time
156
+ @match_time.split(':').first + ?'
157
+ else
158
+ @match_time.split(':').first + ?'
159
+ end
160
+ end
161
+ alias :clock :clock_display
162
+
163
+ def match_seconds
164
+ return nil unless @match_time
165
+ mm, ss = @match_time.split(':').map(&:to_i)
166
+ time = mm * 60 + ss
167
+ if @match_time == '45:00' || @match_time == '90:00' # stoppage time
168
+ mm, ss = @stoppage_time.split(':').map(&:to_i)
169
+ stop_time = mm * 60 + ss
170
+ time += stop_time
171
+ end
172
+ time
173
+ end
174
+ alias :game_seconds :match_seconds
91
175
 
92
176
  def update_teams(data)
93
177
  home_hash = data.detect { |team_hash| team_hash["qualifier"] == "home" || team_hash["team"] == "home" }
@@ -214,7 +298,9 @@ module Sportradar
214
298
  ingest_timeline(data)
215
299
  end
216
300
  def ingest_timeline(data)
217
- update(data)
301
+ update(data, source: :pbp)
302
+ check_newness(:pbp, timeline.last&.updated)
303
+ check_newness(:clock, self.match_seconds.to_s)
218
304
  data
219
305
  end
220
306
  def queue_timeline
@@ -222,6 +308,21 @@ module Sportradar
222
308
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_timeline)}
223
309
  end
224
310
 
311
+ # tracking updates
312
+ def remember(key, object)
313
+ @updates[key] = object&.dup
314
+ end
315
+ def not_updated?(key, object)
316
+ @updates[key] == object
317
+ end
318
+ def changed?(key)
319
+ @changes[key]
320
+ end
321
+ def check_newness(key, new_object)
322
+ @changes[key] = !not_updated?(key, new_object)
323
+ remember(key, new_object)
324
+ end
325
+
225
326
  end
226
327
  end
227
328
  end
@@ -240,6 +341,17 @@ __END__
240
341
  [{"id"=>"sr:competitor:2793", "name"=>"US Sassuolo", "country"=>"Italy", "country_code"=>"ITA", "abbreviation"=>"SAS", "qualifier"=>"home"},
241
342
  {"id"=>"sr:competitor:2702", "name"=>"AS Roma", "country"=>"Italy", "country_code"=>"ITA", "abbreviation"=>"ROM", "qualifier"=>"away"}]
242
343
 
344
+ "sport_event_status"=>
345
+ {"status"=>"live",
346
+ "match_status"=>"1st_half",
347
+ "home_score"=>1,
348
+ "away_score"=>0,
349
+ "period"=>1,
350
+ "clock"=>{"match_time"=>"19:25"},
351
+ "clock"=>{"match_time"=>"45:00", "stoppage_time"=>"00:05"}
352
+ "ball_locations"=>[{"x"=>"95", "y"=>"50", "team"=>"away"}, {"x"=>"80", "y"=>"62", "team"=>"home"}, {"x"=>"82", "y"=>"60", "team"=>"home"}, {"x"=>"79", "y"=>"58", "team"=>"home"}]},
353
+
354
+
243
355
 
244
356
  m = Sportradar::Api::Soccer::Match.new({"id"=>"sr:match:12090446"}, league_group: 'eu')
245
357
  res = m.get_summary
@@ -44,6 +44,14 @@ module Sportradar
44
44
  @name || [@first_name, @last_name].join(' ')
45
45
  end
46
46
 
47
+ def first_name
48
+ @first_name || (@name && @name.split(', ')[1])
49
+ end
50
+
51
+ def last_name
52
+ @last_name || (@name && @name.split(', ')[0])
53
+ end
54
+
47
55
  def api
48
56
  @api || Sportradar::Api::Soccer::Api.new(league_group: @league_group)
49
57
  end
@@ -67,9 +75,7 @@ module Sportradar
67
75
  url, headers, options, timeout = api.get_request_info(path_profile)
68
76
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_profile)}
69
77
  end
70
-
71
78
  end
72
-
73
79
  end
74
80
  end
75
81
  end
@@ -15,22 +15,23 @@ module Sportradar
15
15
  end
16
16
 
17
17
  def update(data, source: nil, **opts)
18
- new_scores = case source
19
- when :box
20
- parse_from_box(data)
21
- when :timeline
22
- parse_from_timeline(data)
23
- when :summary
24
- parse_from_box(data)
25
- else
26
- if data['period'] || data['half']
27
- parse_from_timeline(data)
28
- elsif data['team']
29
- parse_from_box(data)
30
- else # schedule requests
31
- {}
32
- end
33
- end
18
+ # new_scores = case source
19
+ # when :box
20
+ # parse_from_box(data)
21
+ # when :timeline
22
+ # parse_from_timeline(data)
23
+ # when :summary
24
+ # parse_from_box(data)
25
+ # else
26
+ # if data['period'] || data['half']
27
+ # parse_from_timeline(data)
28
+ # elsif data['team']
29
+ # parse_from_box(data)
30
+ # else # schedule requests
31
+ # {}
32
+ # end
33
+ # end
34
+ new_scores = parse_from_timeline(data)
34
35
  # parse data structure
35
36
  # handle data from team (all periods)
36
37
  # handle data from period (both teams)
@@ -47,6 +48,13 @@ module Sportradar
47
48
  private
48
49
 
49
50
  def parse_from_timeline(data)
51
+ if data['period_scores']
52
+ data['period_scores'].map do |hash|
53
+ [hash["number"], {"home"=>hash['home_score'], "away"=>hash['away_score']}]
54
+ end.to_h
55
+ else
56
+ {}
57
+ end
50
58
  end
51
59
 
52
60
  # def period_name
@@ -61,6 +61,8 @@ module Sportradar
61
61
  opts[:season].tournament_id
62
62
  elsif opts[:match]
63
63
  opts[:match].tournament_id
64
+ elsif data['tournament_id']
65
+ data['tournament_id']
64
66
  elsif data['tournament']
65
67
  data.dig('tournament', 'id')
66
68
  elsif data['season']
@@ -1,5 +1,5 @@
1
1
  module Sportradar
2
2
  module Api
3
- VERSION = "0.13.4"
3
+ VERSION = "0.13.5"
4
4
  end
5
5
  end
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.13.4
4
+ version: 0.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Eggett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-02 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -433,24 +433,8 @@ files:
433
433
  - lib/sportradar/api/odds.rb
434
434
  - lib/sportradar/api/poll.rb
435
435
  - lib/sportradar/api/request.rb
436
- - lib/sportradar/api/soccer-old.rb
437
- - lib/sportradar/api/soccer-old/boxscore.rb
438
- - lib/sportradar/api/soccer-old/category.rb
439
- - lib/sportradar/api/soccer-old/fact.rb
440
- - lib/sportradar/api/soccer-old/hierarchy.rb
441
- - lib/sportradar/api/soccer-old/match.rb
442
- - lib/sportradar/api/soccer-old/player.rb
443
- - lib/sportradar/api/soccer-old/ranking.rb
444
- - lib/sportradar/api/soccer-old/schedule.rb
445
- - lib/sportradar/api/soccer-old/season.rb
446
- - lib/sportradar/api/soccer-old/standing.rb
447
- - lib/sportradar/api/soccer-old/statistic.rb
448
- - lib/sportradar/api/soccer-old/summary.rb
449
- - lib/sportradar/api/soccer-old/team.rb
450
- - lib/sportradar/api/soccer-old/tournament.rb
451
- - lib/sportradar/api/soccer-old/tournament_group.rb
452
- - lib/sportradar/api/soccer-old/venue.rb
453
436
  - lib/sportradar/api/soccer.rb
437
+ - lib/sportradar/api/soccer/README.md
454
438
  - lib/sportradar/api/soccer/api.rb
455
439
  - lib/sportradar/api/soccer/event.rb
456
440
  - lib/sportradar/api/soccer/fact.rb
@@ -466,16 +450,6 @@ files:
466
450
  - lib/sportradar/api/soccer/tournament.rb
467
451
  - lib/sportradar/api/soccer/venue.rb
468
452
  - lib/sportradar/api/version.rb
469
- - soccer-old/boxscore_test.rb
470
- - soccer-old/hierarchy_test.rb
471
- - soccer-old/match_test.rb
472
- - soccer-old/player_test.rb
473
- - soccer-old/ranking_test.rb
474
- - soccer-old/schedule_test.rb
475
- - soccer-old/standing_test.rb
476
- - soccer-old/summary_test.rb
477
- - soccer-old/team_test.rb
478
- - soccer-old_test.rb
479
453
  - sportradar-api.gemspec
480
454
  homepage: https://github.com/beneggett/sportradar-api
481
455
  licenses: []
@@ -1,13 +0,0 @@
1
- module Sportradar
2
- module Api
3
- class Soccer::Boxscore < Data
4
- attr_accessor :response, :matches
5
-
6
- def initialize(data)
7
- @response = data
8
- @matches = parse_into_array(selector: response["boxscore"]["matches"]["match"], klass: Sportradar::Api::Soccer::Match) if response['boxscore'] && response['boxscore']['matches'] && response["boxscore"]["matches"]["match"]
9
- end
10
-
11
- end
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- module Sportradar
2
- module Api
3
- class Soccer::Category < Data
4
- attr_accessor :response, :id, :name, :country_code, :country, :tournament_groups
5
-
6
- def initialize(data)
7
- @response = data
8
- @id = data["id"]
9
- @name = data["name"]
10
- @country_code = data["country_code"]
11
- @country = data["country"]
12
- @tournament_groups = parse_into_array(selector: response["tournament_group"], klass: Sportradar::Api::Soccer::TournamentGroup) if response["tournament_group"]
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,61 +0,0 @@
1
- module Sportradar
2
- module Api
3
- class Soccer::Fact < Data
4
-
5
- attr_accessor :id, :type, :time, :updated_time, :scratch, :reference_id, :clock, :team_id, :description, :period, :x, :y, :player_id, :card, :injury_time, :home_score, :away_score, :player_out_id, :player_in_id, :penalty, :owngoal, :header, :assist1_id, :winner_id, :draw, :response
6
-
7
- def initialize(data)
8
- @response = data
9
- @id = data["id"]
10
- @type = data["type"]
11
- @time = data["time"]
12
- @updated_time = data["updated_time"]
13
- @scratch = data["scratch"]
14
- @reference_id = data["reference_id"]
15
- @clock = data["clock"]
16
- @team_id = data["team_id"]
17
- @description = data["description"]
18
- @period = data["period"]
19
- @x = data["x"]
20
- @y = data["y"]
21
- @player_id = data["player_id"]
22
- @card = data["card"]
23
- @injury_time = data["injury_time"]
24
- @home_score = data["home_score"]
25
- @away_score = data["away_score"]
26
- @player_out_id = data["player_out_id"]
27
- @player_in_id = data["player_in_id"]
28
- @penalty = data["penalty"]
29
- @owngoal = data["owngoal"]
30
- @header = data["header"]
31
- @assist1_id = data["assist1_id"]
32
- @winner_id = data["winner_id"]
33
- @draw = data["draw"]
34
- end
35
-
36
- ## Fact Types
37
- # card
38
- # corner_kick
39
- # free_kick
40
- # game_resumed
41
- # goal
42
- # goal_kick
43
- # injury
44
- # injury_return
45
- # injury_time
46
- # keeper_save
47
- # match_ended
48
- # match_started
49
- # offside
50
- # penalty_awarded
51
- # penalty_missed
52
- # period_over
53
- # period_started
54
- # shot_blocked
55
- # shot_off_target
56
- # shot_on_target
57
- # substitution
58
- # throwin
59
- end
60
- end
61
- end
@@ -1,14 +0,0 @@
1
- module Sportradar
2
- module Api
3
- class Soccer::Hierarchy < Data
4
- attr_accessor :response, :categories
5
-
6
- def initialize(data)
7
- @response = data
8
- @categories = parse_into_array(selector: response["category"], klass: Sportradar::Api::Soccer::Category) if response["category"]
9
- end
10
-
11
- end
12
- end
13
- end
14
-
@@ -1,55 +0,0 @@
1
- module Sportradar
2
- module Api
3
- class Soccer::Match < Data
4
-
5
- attr_accessor :id, :status, :scheduled, :scratched, :season_id, :reference_id, :category, :tournament_group, :tournament, :home, :away, :venue, :round, :coverage, :period, :clock, :referee, :facts, :response, :future_game, :winner
6
-
7
- def initialize(data)
8
- @response = data
9
- @id = data["id"]
10
- @reference_id = data["reference_id"]
11
- @scheduled = Time.parse(data["scheduled"]) if data["scheduled"]
12
- @scratched = data["scratched"] == "true"
13
- @season_id = data["season_id"]
14
- @status = data["status"]
15
- @category = Sportradar::Api::Soccer::Category.new data["category"] if data["category"]
16
- @coverage = OpenStruct.new data["coverage"]
17
- @round = OpenStruct.new data["round"]
18
- @tournament = Sportradar::Api::Soccer::Tournament.new data["tournament"] if data["tournament"]
19
- @tournament_group = Sportradar::Api::Soccer::TournamentGroup.new data["tournament_group"] if data["tournament_group"]
20
-
21
- @away = Sportradar::Api::Soccer::Team.new data["away"] if data["away"]
22
- @home = Sportradar::Api::Soccer::Team.new data["home"] if data["home"]
23
- @venue = Sportradar::Api::Soccer::Venue.new data["venue"] if data["venue"]
24
-
25
- @future_game = @scheduled > Time.now.utc
26
- @winner = find_winner if @home && @away && !future_game
27
-
28
- # Actual stats from match summary
29
- @period = data["period"]
30
- @clock = data["clock"]
31
- @referee = OpenStruct.new data["referee"] if data["referee"]
32
- @facts = data["facts"]["fact"].map {|fact| Sportradar::Api::Soccer::Fact.new fact } if data["facts"]
33
- end
34
-
35
- def find_winner
36
- if @home.winner == 'draw'
37
- 'draw'
38
- else
39
- [@home, @away].find {|team| team.winner == "true" }
40
- end
41
-
42
- end
43
-
44
- def period_name
45
- period_names = {"P1" => "Period one", "H" => "Halftime", "P2" => "Period two", "PX1" => "Pre-extra time one", "X1" => "Extra time one", "PX2" => "Pre-extra time two", "X2" => "Extra time two", "PP" => "Pre-penalty", "P" => "Penalty"}
46
- period_names[period] if period
47
- end
48
-
49
- def status_description
50
- status_descriptions = {"scheduled" => "The match is scheduled to be played", "inprogress" => "The match is currently in progress", "postponed" => "The match has been postponed to a future date", "delayed" => "The match has been temporarily delayed and will be continued", "canceled" => "The match has been canceled and will not be played", "closed" => "The match is over"}
51
- status_descriptions[status] if status
52
- end
53
- end
54
- end
55
- end