sports_data_api 0.11.6 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +1 -0
- data/lib/sports_data_api/nba/broadcast.rb +1 -9
- data/lib/sports_data_api/nba/game.rb +56 -37
- data/lib/sports_data_api/nba/games.rb +16 -13
- data/lib/sports_data_api/nba/player.rb +4 -16
- data/lib/sports_data_api/nba/season.rb +15 -10
- data/lib/sports_data_api/nba/stats.rb +6 -0
- data/lib/sports_data_api/nba/team.rb +29 -17
- data/lib/sports_data_api/nba/teams.rb +14 -65
- data/lib/sports_data_api/nba/venue.rb +10 -12
- data/lib/sports_data_api/nba.rb +10 -9
- data/lib/sports_data_api/version.rb +1 -1
- data/spec/cassettes/sports_data_api_nba.yml +66434 -112102
- data/spec/cassettes/sports_data_api_nba_broadcast.yml +67 -56
- data/spec/cassettes/sports_data_api_nba_game.yml +31079 -21019
- data/spec/cassettes/sports_data_api_nba_games.yml +112 -68
- data/spec/cassettes/sports_data_api_nba_league_hierarchy.yml +553 -469
- data/spec/cassettes/sports_data_api_nba_player.yml +1173 -212
- data/spec/cassettes/sports_data_api_nba_season.yml +18253 -18195
- data/spec/cassettes/sports_data_api_nba_team.yml +1429 -1284
- data/spec/cassettes/sports_data_api_nba_venue.yml +438 -56
- data/spec/lib/sports_data_api/nba/broadcast_spec.rb +8 -4
- data/spec/lib/sports_data_api/nba/game_spec.rb +32 -41
- data/spec/lib/sports_data_api/nba/games_spec.rb +10 -6
- data/spec/lib/sports_data_api/nba/player_spec.rb +86 -56
- data/spec/lib/sports_data_api/nba/season_spec.rb +4 -3
- data/spec/lib/sports_data_api/nba/team_spec.rb +44 -48
- data/spec/lib/sports_data_api/nba/teams_spec.rb +12 -63
- data/spec/lib/sports_data_api/nba/venue_spec.rb +23 -6
- data/spec/lib/sports_data_api/nba_spec.rb +97 -15
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8a2556b1cd7f55fd366400025462306b46fb1dc9a45449e4d038b15e3c2dc344
|
4
|
+
data.tar.gz: b3a2452b53e1aa99f4ea928bc64ec12f60fc18ae2f3140a8c8379a4d0f2742c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63d5635e7b7097506310fd81257ad21cd0f209bf42cbc8fa30667ade1ab11feadef2811f4d675da5dc6ffcc8cf2b2e2d03d6b19c0ee7327e3244ae5db58d588
|
7
|
+
data.tar.gz: 47adca1c31f93dd5cfadffd80dd475c036cae42ef1cf371d409a92f1c2eca7f8ae21d0bca8d4cfddbb44e97518a25eeec4e82e592fe48aa7e4988e449abdaa1b
|
data/.travis.yml
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nba
|
3
|
-
class Broadcast
|
4
|
-
attr_reader :network, :satellite
|
5
|
-
def initialize(xml)
|
6
|
-
xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet
|
7
|
-
if xml.is_a? Nokogiri::XML::Element
|
8
|
-
@network = xml['network']
|
9
|
-
@satellite = xml['satellite']
|
10
|
-
end
|
11
|
-
end
|
3
|
+
class Broadcast < SportsDataApi::JsonData
|
12
4
|
end
|
13
5
|
end
|
14
6
|
end
|
@@ -1,49 +1,56 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nba
|
3
3
|
class Game
|
4
|
-
attr_reader :id, :
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
4
|
+
attr_reader :id, :status, :year, :season, :clock
|
5
|
+
|
6
|
+
def initialize(json:, year: nil, season: nil)
|
7
|
+
@json = json
|
8
|
+
@year = year
|
9
|
+
@season = season
|
10
|
+
@id = json['id']
|
11
|
+
@status = json['status']
|
12
|
+
@clock = json['clock']
|
13
|
+
end
|
14
|
+
|
15
|
+
def scheduled
|
16
|
+
@scheduled ||= Time.iso8601 json['scheduled']
|
17
|
+
end
|
18
|
+
|
19
|
+
def home_team_id
|
20
|
+
json['home']['id']
|
21
|
+
end
|
22
|
+
|
23
|
+
def away_team_id
|
24
|
+
json['away']['id']
|
25
|
+
end
|
26
|
+
|
27
|
+
def home_team
|
28
|
+
@home_team ||= Team.new(json['home'])
|
29
|
+
end
|
30
|
+
|
31
|
+
def away_team
|
32
|
+
@away_team ||= Team.new(json['away'])
|
33
|
+
end
|
34
|
+
|
35
|
+
def quarter
|
36
|
+
return unless json['quarter']
|
37
|
+
json['quarter'].to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
def venue
|
41
|
+
@venue ||= Venue.new(json['venue'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def broadcast
|
45
|
+
return nil if json['broadcast'].nil? || json['broadcast'].empty?
|
46
|
+
@broadcast ||= Broadcast.new(json['broadcast'])
|
40
47
|
end
|
41
48
|
|
42
49
|
##
|
43
50
|
# Wrapper for Nba.game_summary
|
44
51
|
# TODO
|
45
52
|
def summary
|
46
|
-
Nba.game_summary(
|
53
|
+
Nba.game_summary(id)
|
47
54
|
end
|
48
55
|
|
49
56
|
##
|
@@ -59,6 +66,18 @@ module SportsDataApi
|
|
59
66
|
def boxscore
|
60
67
|
raise NotImplementedError
|
61
68
|
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
attr_reader :json
|
73
|
+
|
74
|
+
def game_summary?
|
75
|
+
!team_json.nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
def team_json
|
79
|
+
@team_json ||= json['team']
|
80
|
+
end
|
62
81
|
end
|
63
82
|
end
|
64
83
|
end
|
@@ -2,25 +2,28 @@ module SportsDataApi
|
|
2
2
|
module Nba
|
3
3
|
class Games
|
4
4
|
include Enumerable
|
5
|
-
attr_reader :games, :date
|
6
5
|
|
7
|
-
|
8
|
-
@date = xml.first['date']
|
6
|
+
attr_reader :date
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def initialize(json)
|
9
|
+
@json = json
|
10
|
+
@date = json['date']
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
@games.
|
17
|
-
|
18
|
-
block.call game
|
19
|
-
else
|
20
|
-
yield game
|
21
|
-
end
|
13
|
+
def games
|
14
|
+
@games ||= json['games'].map do |game_json|
|
15
|
+
Game.new(json: game_json)
|
22
16
|
end
|
23
17
|
end
|
18
|
+
|
19
|
+
def each
|
20
|
+
return games.each unless block_given?
|
21
|
+
games.each { |game| yield game }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :json
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -1,21 +1,9 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nba
|
3
|
-
class Player
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
if xml.is_a? Nokogiri::XML::Element
|
8
|
-
player_ivar = self.instance_variable_set("@#{xml.name}", {})
|
9
|
-
self.class.class_eval { attr_reader :"#{xml.name}" }
|
10
|
-
xml.attributes.each do | attr_name, attr_value|
|
11
|
-
player_ivar[attr_name.to_sym] = attr_value.value
|
12
|
-
end
|
13
|
-
|
14
|
-
stats_xml = xml.xpath('statistics')
|
15
|
-
if stats_xml.is_a? Nokogiri::XML::NodeSet and stats_xml.count > 0
|
16
|
-
@stats = SportsDataApi::Stats.new(stats_xml.first)
|
17
|
-
end
|
18
|
-
end
|
3
|
+
class Player < SportsDataApi::JsonData
|
4
|
+
def stats
|
5
|
+
return if player[:statistics].nil? || player[:statistics].empty?
|
6
|
+
@stats ||= SportsDataApi::Nba::Stats.new(player[:statistics])
|
19
7
|
end
|
20
8
|
end
|
21
9
|
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nba
|
3
3
|
class Season
|
4
|
-
attr_reader :id, :year, :type
|
4
|
+
attr_reader :id, :year, :type
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def initialize(json)
|
7
|
+
@json = json
|
8
|
+
@id = json['season']['id']
|
9
|
+
@year = json['season']['year']
|
10
|
+
@type = json['season']['type'].to_sym
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def games
|
14
|
+
@games ||= json['games'].map do |game_json|
|
15
|
+
Game.new(year: year, season: type, json: game_json)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -21,8 +22,12 @@ module SportsDataApi
|
|
21
22
|
#
|
22
23
|
# The only valid types are: :pre, :reg, :pst
|
23
24
|
def self.valid?(season)
|
24
|
-
[
|
25
|
+
%i[PRE REG PST].include?(season)
|
25
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :json
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
@@ -1,23 +1,31 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nba
|
3
3
|
class Team
|
4
|
-
attr_reader :id, :name, :market, :alias, :conference, :division,
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
attr_reader :id, :name, :market, :alias, :conference, :division, :stats
|
5
|
+
|
6
|
+
def initialize(json, conference = nil, division = nil)
|
7
|
+
@conference = conference
|
8
|
+
@division = division
|
9
|
+
@id = json['id']
|
10
|
+
@name = json['name']
|
11
|
+
@market = json['market']
|
12
|
+
@alias = json['alias']
|
13
|
+
@points = json['points']
|
14
|
+
@alias = json['alias']
|
15
|
+
@json = json
|
16
|
+
end
|
17
|
+
|
18
|
+
def points
|
19
|
+
@points ||= json['points'] ? json['points'].to_i : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def players
|
23
|
+
return [] if json['players'].nil? || json['players'].empty?
|
24
|
+
@players ||= json['players'].map { |x| Player.new(x) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def venue
|
28
|
+
@venue ||= Venue.new(json['venue']) if json['venue']
|
21
29
|
end
|
22
30
|
|
23
31
|
##
|
@@ -34,6 +42,10 @@ module SportsDataApi
|
|
34
42
|
super(other)
|
35
43
|
end
|
36
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
attr_reader :json
|
37
49
|
end
|
38
50
|
end
|
39
51
|
end
|
@@ -3,81 +3,30 @@ module SportsDataApi
|
|
3
3
|
class Teams
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# Initialize by passing the raw XML returned from the API
|
10
|
-
def initialize(xml)
|
11
|
-
@teams = []
|
12
|
-
xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet
|
13
|
-
if xml.is_a? Nokogiri::XML::Element
|
14
|
-
xml.xpath('conference').each do |conference|
|
15
|
-
# Conference ID, e.g., EASTERN or WESTERN
|
16
|
-
cname = conference['alias']
|
17
|
-
|
18
|
-
conference.xpath('division').each do |division|
|
19
|
-
# Division ID, e.g., ATLANTIC, PACIFIC
|
20
|
-
dname = division['alias']
|
6
|
+
def initialize(json)
|
7
|
+
@json = json
|
8
|
+
end
|
21
9
|
|
22
|
-
|
23
|
-
|
10
|
+
def teams
|
11
|
+
@teams ||= json['conferences'].flat_map do |conference|
|
12
|
+
conference['divisions'].flat_map do |division|
|
13
|
+
division['teams'].map do |json|
|
14
|
+
Team.new(json, conference['alias'], division['alias'])
|
24
15
|
end
|
25
16
|
end
|
26
17
|
end
|
27
|
-
|
28
|
-
@teams.flatten!
|
29
|
-
|
30
|
-
uniq_conferences = @teams.map { |team| team.conference.upcase }.uniq
|
31
|
-
@allowed_conferences = uniq_conferences.map { |str| str.to_sym }.concat(uniq_conferences.map { |str| str.downcase.to_sym })
|
32
|
-
@conferences = uniq_conferences.map { |conf| conf.to_sym }
|
33
|
-
|
34
|
-
uniq_divisions = @teams.map { |team| team.division.upcase }.uniq
|
35
|
-
@divisions = @teams.map { |team| team.division.to_sym }.uniq
|
36
|
-
@allowed_divisions = uniq_divisions.map { |str| str.to_sym }.concat(uniq_divisions.map { |str| str.downcase.to_sym })
|
37
|
-
end
|
38
|
-
|
39
|
-
def [](search_index)
|
40
|
-
found_index = @teams.index(search_index)
|
41
|
-
unless found_index.nil?
|
42
|
-
@teams[found_index]
|
43
|
-
end
|
44
18
|
end
|
45
19
|
|
46
20
|
##
|
47
|
-
#
|
48
|
-
def
|
49
|
-
|
21
|
+
# Make the class Enumerable
|
22
|
+
def each
|
23
|
+
return teams.each unless block_given?
|
24
|
+
teams.each { |team| yield team }
|
50
25
|
end
|
51
26
|
|
52
|
-
|
53
|
-
#
|
54
|
-
def method_missing(method)
|
55
|
-
if @allowed_conferences.include?(method)
|
56
|
-
@teams.select do |team|
|
57
|
-
up = team.conference.upcase.to_sym
|
58
|
-
dw = team.conference.downcase.to_sym
|
59
|
-
up === method || dw === method
|
60
|
-
end
|
61
|
-
elsif @allowed_divisions.include?(method)
|
62
|
-
@teams.select do |team|
|
63
|
-
up = team.division.upcase.to_sym
|
64
|
-
dw = team.division.downcase.to_sym
|
65
|
-
up === method || dw === method
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
27
|
+
private
|
69
28
|
|
70
|
-
|
71
|
-
# Make the class Enumerable
|
72
|
-
def each(&block)
|
73
|
-
@teams.each do |team|
|
74
|
-
if block_given?
|
75
|
-
block.call team
|
76
|
-
else
|
77
|
-
yield team
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
29
|
+
attr_reader :json
|
81
30
|
end
|
82
31
|
end
|
83
32
|
end
|
@@ -2,18 +2,16 @@ module SportsDataApi
|
|
2
2
|
module Nba
|
3
3
|
class Venue
|
4
4
|
attr_reader :id, :name, :address, :city, :state, :zip, :country, :capacity
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@capacity = xml['capacity']
|
16
|
-
end
|
5
|
+
|
6
|
+
def initialize(json)
|
7
|
+
@id = json['id']
|
8
|
+
@name = json['name']
|
9
|
+
@address = json['address']
|
10
|
+
@city = json['city']
|
11
|
+
@state = json['state']
|
12
|
+
@zip = json['zip']
|
13
|
+
@country = json['country']
|
14
|
+
@capacity = json['capacity']
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
data/lib/sports_data_api/nba.rb
CHANGED
@@ -5,8 +5,8 @@ module SportsDataApi
|
|
5
5
|
class Exception < ::Exception
|
6
6
|
end
|
7
7
|
|
8
|
-
API_VERSION =
|
9
|
-
BASE_URL = 'https://api.
|
8
|
+
API_VERSION = 4
|
9
|
+
BASE_URL = 'https://api.sportradar.us/nba/%{access_level}/v%{version}/en'
|
10
10
|
DIR = File.join(File.dirname(__FILE__), 'nba')
|
11
11
|
SPORT = :nba
|
12
12
|
|
@@ -16,6 +16,7 @@ module SportsDataApi
|
|
16
16
|
autoload :Game, File.join(DIR, 'game')
|
17
17
|
autoload :Games, File.join(DIR, 'games')
|
18
18
|
autoload :Season, File.join(DIR, 'season')
|
19
|
+
autoload :Stats, File.join(DIR, 'stats')
|
19
20
|
autoload :Venue, File.join(DIR, 'venue')
|
20
21
|
autoload :Broadcast, File.join(DIR, 'broadcast')
|
21
22
|
|
@@ -26,31 +27,31 @@ module SportsDataApi
|
|
26
27
|
season = season.to_s.upcase.to_sym
|
27
28
|
raise Exception.new("#{season} is not a valid season") unless Season.valid?(season)
|
28
29
|
|
29
|
-
Season.new(
|
30
|
+
Season.new(response_json("/games/#{year}/#{season}/schedule.json"))
|
30
31
|
end
|
31
32
|
|
32
33
|
##
|
33
34
|
# Fetches NBA team roster
|
34
|
-
def team_roster(
|
35
|
-
Team.new(
|
35
|
+
def team_roster(team_id)
|
36
|
+
Team.new(response_json("/teams/#{team_id}/profile.json"))
|
36
37
|
end
|
37
38
|
|
38
39
|
##
|
39
40
|
# Fetches NBA game summary for a given game
|
40
|
-
def game_summary(
|
41
|
-
Game.new(
|
41
|
+
def game_summary(game_id)
|
42
|
+
Game.new(json: response_json("/games/#{game_id}/summary.json"))
|
42
43
|
end
|
43
44
|
|
44
45
|
##
|
45
46
|
# Fetches all NBA teams
|
46
47
|
def teams
|
47
|
-
Teams.new(
|
48
|
+
Teams.new(response_json('/league/hierarchy.json'))
|
48
49
|
end
|
49
50
|
|
50
51
|
##
|
51
52
|
# Fetches NBA daily schedule for a given date
|
52
53
|
def daily(year, month, day)
|
53
|
-
Games.new(
|
54
|
+
Games.new(response_json("/games/#{year}/#{month}/#{day}/schedule.json"))
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|