sports_data_api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/README.md +6 -6
- data/lib/sports_data_api.rb +2 -0
- data/lib/sports_data_api/nfl.rb +28 -16
- data/lib/sports_data_api/nfl/broadcast.rb +6 -7
- data/lib/sports_data_api/nfl/game.rb +17 -22
- data/lib/sports_data_api/nfl/games.rb +7 -8
- data/lib/sports_data_api/nfl/player.rb +5 -7
- data/lib/sports_data_api/nfl/player_season_stats.rb +3 -13
- data/lib/sports_data_api/nfl/season.rb +5 -7
- data/lib/sports_data_api/nfl/team.rb +50 -11
- data/lib/sports_data_api/nfl/team_roster.rb +2 -5
- data/lib/sports_data_api/nfl/team_season_stats.rb +4 -9
- data/lib/sports_data_api/nfl/teams.rb +9 -15
- data/lib/sports_data_api/nfl/venue.rb +12 -13
- data/lib/sports_data_api/nfl/weather.rb +7 -8
- data/lib/sports_data_api/nfl/week.rb +4 -6
- data/lib/sports_data_api/nhl.rb +71 -0
- data/lib/sports_data_api/nhl/broadcast.rb +14 -0
- data/lib/sports_data_api/nhl/game.rb +54 -0
- data/lib/sports_data_api/nhl/games.rb +26 -0
- data/lib/sports_data_api/nhl/player.rb +31 -0
- data/lib/sports_data_api/nhl/season.rb +28 -0
- data/lib/sports_data_api/nhl/team.rb +40 -0
- data/lib/sports_data_api/nhl/teams.rb +83 -0
- data/lib/sports_data_api/nhl/venue.rb +20 -0
- data/lib/sports_data_api/stats.rb +6 -2
- data/lib/sports_data_api/version.rb +1 -1
- data/spec/cassettes/sports_data_api_mlb_game.yml +19926 -19688
- data/spec/cassettes/sports_data_api_mlb_game_boxscore.yml +24 -18
- data/spec/cassettes/sports_data_api_mlb_game_stats.yml +576 -574
- data/spec/cassettes/sports_data_api_mlb_games.yml +152 -147
- data/spec/cassettes/sports_data_api_mlb_player.yml +8459 -10660
- data/spec/cassettes/sports_data_api_mlb_season.yml +19926 -19688
- data/spec/cassettes/sports_data_api_mlb_team.yml +47 -44
- data/spec/cassettes/sports_data_api_mlb_team_roster.yml +8459 -10660
- data/spec/cassettes/sports_data_api_mlb_teams.yml +94 -130
- data/spec/cassettes/sports_data_api_mlb_venues.yml +16 -16
- data/spec/cassettes/sports_data_api_nfl.yml +5331 -18893
- data/spec/cassettes/sports_data_api_nfl_broadcast.yml +35 -84
- data/spec/cassettes/sports_data_api_nfl_game.yml +7702 -15956
- data/spec/cassettes/sports_data_api_nfl_games.yml +211 -884
- data/spec/cassettes/sports_data_api_nfl_player_season_stats.yml +1002 -959
- data/spec/cassettes/sports_data_api_nfl_season.yml +3168 -14065
- data/spec/cassettes/sports_data_api_nfl_team.yml +1264 -715
- data/spec/cassettes/sports_data_api_nfl_team_hierarchy.yml +462 -846
- data/spec/cassettes/sports_data_api_nfl_team_roster.yml +796 -580
- data/spec/cassettes/sports_data_api_nfl_team_season_stats.yml +1004 -945
- data/spec/cassettes/sports_data_api_nfl_venue.yml +35 -84
- data/spec/cassettes/sports_data_api_nfl_weather.yml +35 -84
- data/spec/cassettes/sports_data_api_nfl_week.yml +3168 -14065
- data/spec/cassettes/sports_data_api_nhl.yml +18999 -0
- data/spec/cassettes/sports_data_api_nhl_broadcast.yml +226 -0
- data/spec/cassettes/sports_data_api_nhl_game.yml +23261 -0
- data/spec/cassettes/sports_data_api_nhl_games.yml +226 -0
- data/spec/cassettes/sports_data_api_nhl_league_hierarchy.yml +535 -0
- data/spec/cassettes/sports_data_api_nhl_player.yml +396 -0
- data/spec/cassettes/sports_data_api_nhl_season.yml +18961 -0
- data/spec/cassettes/sports_data_api_nhl_team.yml +1962 -0
- data/spec/cassettes/sports_data_api_nhl_venue.yml +226 -0
- data/spec/lib/sports_data_api/mlb/players_spec.rb +1 -1
- data/spec/lib/sports_data_api/nfl/game_spec.rb +33 -9
- data/spec/lib/sports_data_api/nfl/team_spec.rb +62 -32
- data/spec/lib/sports_data_api/nfl/teams_spec.rb +5 -6
- data/spec/lib/sports_data_api/nfl/venue_spec.rb +3 -3
- data/spec/lib/sports_data_api/nfl_spec.rb +3 -3
- data/spec/lib/sports_data_api/nhl/broadcast_spec.rb +18 -0
- data/spec/lib/sports_data_api/nhl/game_spec.rb +87 -0
- data/spec/lib/sports_data_api/nhl/games_spec.rb +19 -0
- data/spec/lib/sports_data_api/nhl/player_spec.rb +56 -0
- data/spec/lib/sports_data_api/nhl/season_spec.rb +41 -0
- data/spec/lib/sports_data_api/nhl/team_spec.rb +240 -0
- data/spec/lib/sports_data_api/nhl/teams_spec.rb +76 -0
- data/spec/lib/sports_data_api/nhl/venue_spec.rb +24 -0
- data/spec/lib/sports_data_api/nhl_spec.rb +41 -0
- data/spec/spec_helper.rb +2 -0
- data/sports_data_api.gemspec +1 -0
- metadata +62 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62aab7aee23b0a730d1134d17519b149c0094327
|
4
|
+
data.tar.gz: f95759783b3b4d34a87f79db7e6e5be0d0ed414c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9152043f7a7d85ef9245dd0466f83d7f970d23c60a3a0ecb2007edda75623f01b3b7ec4781d2e16fd38aa010dbd90f1b7d6ba898d3148d8bd393ad8d018512b5
|
7
|
+
data.tar.gz: a2f99223b3092b2639a04ad843fd12e60f55af1388a3d937e550922e49bc6ae24f7457c9396c5d72ab35359815bc6452b4d73da1e57e59f742623a84793c3939
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.1
|
1
|
+
ruby-2.1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SportsDataApi [![Build Status](https://travis-ci.org/RLovelett/sports_data_api.png?branch=master)](https://travis-ci.org/RLovelett/sports_data_api) [![Coverage Status](https://coveralls.io/repos/RLovelett/sports_data_api/badge.png?branch=master)](https://coveralls.io/r/RLovelett/sports_data_api?branch=master)
|
1
|
+
# SportsDataApi [![Build Status](https://travis-ci.org/RLovelett/sports_data_api.png?branch=master)](https://travis-ci.org/RLovelett/sports_data_api) [![Coverage Status](https://coveralls.io/repos/RLovelett/sports_data_api/badge.png?branch=master)](https://coveralls.io/r/RLovelett/sports_data_api?branch=master) [![Gem Version](https://badge.fury.io/rb/sports_data_api.svg)](http://badge.fury.io/rb/sports_data_api) [![Code Climate](https://codeclimate.com/github/RLovelett/sports_data_api/badges/gpa.svg)](https://codeclimate.com/github/RLovelett/sports_data_api)
|
2
2
|
|
3
3
|
SportsDataApi is an attempt to make a Ruby interface to the
|
4
4
|
[SportsData](http://www.sportsdatallc.com/) API. The goal is to
|
@@ -22,11 +22,11 @@ log](https://github.com/rlovelett/sports_data_api/issues).
|
|
22
22
|
|
23
23
|
* [NFL](http://developer.sportsdatallc.com/docs/NFL_API)
|
24
24
|
* [NBA](http://developer.sportsdatallc.com/docs/NBA_API)
|
25
|
+
* [MLB](http://developer.sportsdatallc.com/docs/MLB_API)
|
26
|
+
* [NHL](http://developer.sportsdatallc.com/docs/NHL_API)
|
25
27
|
* TODO
|
26
|
-
|
27
|
-
|
28
|
-
3. [NCAA Basketball](http://developer.sportsdatallc.com/docs/NCAA_Mens_Basketball)
|
29
|
-
4. [NCAA Football](http://developer.sportsdatallc.com/docs/NCAA_Football_API)
|
28
|
+
2. [NCAA Basketball](http://developer.sportsdatallc.com/docs/NCAA_Mens_Basketball)
|
29
|
+
3. [NCAA Football](http://developer.sportsdatallc.com/docs/NCAA_Football_API)
|
30
30
|
|
31
31
|
## Installation
|
32
32
|
|
@@ -61,7 +61,7 @@ However, if you want to refresh the actual server API responses you will need to
|
|
61
61
|
This can be achieved simply by performing the following two steps:
|
62
62
|
|
63
63
|
1. Delete all the cassettes (`rm spec/cassettes/*.yml`)
|
64
|
-
2. Run specs passing the API key as environment variable (`SPORTS_DATA_<NBA|
|
64
|
+
2. Run specs passing the API key as environment variable (`SPORTS_DATA_<NFL|NBA|MLB|NHL>_API_KEY=realapikey bundle exec rake spec`)
|
65
65
|
|
66
66
|
## Contributing
|
67
67
|
|
data/lib/sports_data_api.rb
CHANGED
@@ -2,6 +2,7 @@ require "sports_data_api/version"
|
|
2
2
|
require "nokogiri"
|
3
3
|
require "rest_client"
|
4
4
|
require "time"
|
5
|
+
require "multi_json"
|
5
6
|
|
6
7
|
module SportsDataApi
|
7
8
|
def self.key(sport)
|
@@ -49,5 +50,6 @@ module SportsDataApi
|
|
49
50
|
autoload :Nfl, File.join(LIBRARY_PATH, 'nfl')
|
50
51
|
autoload :Nba, File.join(LIBRARY_PATH, 'nba')
|
51
52
|
autoload :Mlb, File.join(LIBRARY_PATH, 'mlb')
|
53
|
+
autoload :Nhl, File.join(LIBRARY_PATH, 'nhl')
|
52
54
|
autoload :Exception, File.join(LIBRARY_PATH, 'exception')
|
53
55
|
end
|
data/lib/sports_data_api/nfl.rb
CHANGED
@@ -29,33 +29,33 @@ module SportsDataApi
|
|
29
29
|
season = season.to_s.upcase.to_sym
|
30
30
|
raise SportsDataApi::Nfl::Exception.new("#{season} is not a valid season") unless Season.valid?(season)
|
31
31
|
|
32
|
-
response = self.
|
32
|
+
response = self.response_json(version, "/#{year}/#{season}/schedule.json")
|
33
33
|
|
34
|
-
return Season.new(response
|
34
|
+
return Season.new(response)
|
35
35
|
end
|
36
36
|
|
37
37
|
##
|
38
38
|
# Fetch NFL team roster
|
39
39
|
def self.team_roster(team, version = DEFAULT_VERSION)
|
40
|
-
response = self.
|
40
|
+
response = self.response_json(version, "/teams/#{team}/roster.json")
|
41
41
|
|
42
|
-
return TeamRoster.new(response
|
42
|
+
return TeamRoster.new(response)
|
43
43
|
end
|
44
44
|
|
45
45
|
##
|
46
46
|
# Fetch NFL team seaon stats for a given team, season and season type
|
47
47
|
def self.team_season_stats(team, season, season_type, version = DEFAULT_VERSION)
|
48
|
-
response = self.
|
48
|
+
response = self.response_json(version, "/teams/#{team}/#{season}/#{season_type}/statistics.json")
|
49
49
|
|
50
|
-
return TeamSeasonStats.new(response
|
50
|
+
return TeamSeasonStats.new(response)
|
51
51
|
end
|
52
52
|
|
53
53
|
##
|
54
54
|
# Fetch NFL player seaon stats for a given team, season and season type
|
55
55
|
def self.player_season_stats(team, season, season_type, version = DEFAULT_VERSION)
|
56
|
-
response = self.
|
56
|
+
response = self.response_json(version, "/teams/#{team}/#{season}/#{season_type}/statistics.json")
|
57
57
|
|
58
|
-
return PlayerSeasonStats.new(response
|
58
|
+
return PlayerSeasonStats.new(response)
|
59
59
|
end
|
60
60
|
|
61
61
|
##
|
@@ -64,17 +64,28 @@ module SportsDataApi
|
|
64
64
|
season = season.to_s.upcase.to_sym
|
65
65
|
raise SportsDataApi::Nfl::Exception.new("#{season} is not a valid season") unless Season.valid?(season)
|
66
66
|
|
67
|
-
response = self.
|
67
|
+
response = self.response_json(version, "/#{year}/#{season}/#{week}/#{away}/#{home}/boxscore.json")
|
68
68
|
|
69
|
-
return Game.new(year, season, week, response
|
69
|
+
return Game.new(year, season, week, response)
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Fetches statistics for a given NFL game
|
74
|
+
def self.game_statistics(year, season, week, home, away, version = DEFAULT_VERSION)
|
75
|
+
season = season.to_s.upcase.to_sym
|
76
|
+
raise SportsDataApi::Nfl::Exception.new("#{season} is not a valid season") unless Season.valid?(season)
|
77
|
+
|
78
|
+
response = self.response_json(version, "/#{year}/#{season}/#{week}/#{away}/#{home}/statistics.json")
|
79
|
+
|
80
|
+
return Game.new(year, season, week, response)
|
70
81
|
end
|
71
82
|
|
72
83
|
##
|
73
84
|
# Fetches all NFL teams
|
74
85
|
def self.teams(version = DEFAULT_VERSION)
|
75
|
-
response = self.
|
86
|
+
response = self.response_json(version, "/teams/hierarchy.json")
|
76
87
|
|
77
|
-
return Teams.new(response
|
88
|
+
return Teams.new(response)
|
78
89
|
end
|
79
90
|
|
80
91
|
##
|
@@ -83,16 +94,17 @@ module SportsDataApi
|
|
83
94
|
season = season.to_s.upcase.to_sym
|
84
95
|
raise SportsDataApi::Nfl::Exception.new("#{season} is not a valid season") unless Season.valid?(season)
|
85
96
|
|
86
|
-
response = self.
|
97
|
+
response = self.response_json(version, "/#{year}/#{season}/#{week}/schedule.json")
|
87
98
|
|
88
|
-
return Games.new(response
|
99
|
+
return Games.new(year, season, week, response)
|
89
100
|
end
|
90
101
|
|
91
102
|
private
|
92
|
-
|
103
|
+
|
104
|
+
def self.response_json(version, url)
|
93
105
|
base_url = BASE_URL % { access_level: SportsDataApi.access_level(SPORT), version: version }
|
94
106
|
response = SportsDataApi.generic_request("#{base_url}#{url}", SPORT)
|
95
|
-
|
107
|
+
MultiJson.load(response.to_s)
|
96
108
|
end
|
97
109
|
end
|
98
110
|
end
|
@@ -2,14 +2,13 @@ module SportsDataApi
|
|
2
2
|
module Nfl
|
3
3
|
class Broadcast
|
4
4
|
attr_reader :network, :satellite, :internet
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@internet = xml['internet']
|
5
|
+
def initialize(broadcast_hash)
|
6
|
+
if broadcast_hash
|
7
|
+
@network = broadcast_hash['network']
|
8
|
+
@satellite = broadcast_hash['satellite'] || ''
|
9
|
+
@internet = broadcast_hash['internet']
|
11
10
|
end
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
15
|
-
end
|
14
|
+
end
|
@@ -5,35 +5,30 @@ module SportsDataApi
|
|
5
5
|
:away_team, :status, :quarter, :clock, :venue, :broadcast, :weather,
|
6
6
|
:year, :season, :week
|
7
7
|
|
8
|
-
def initialize(year, season, week,
|
9
|
-
@year = year
|
10
|
-
@season = season
|
11
|
-
@week = week
|
8
|
+
def initialize(year, season, week, game_hash)
|
9
|
+
@year = year
|
10
|
+
@season = season
|
11
|
+
@week = week
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@quarter = xml['quarter'].to_i
|
21
|
-
@clock = xml['clock']
|
13
|
+
@id = game_hash['id']
|
14
|
+
@scheduled = Time.parse game_hash['scheduled']
|
15
|
+
@home = game_hash['home'] || game_hash['home_team']['id']
|
16
|
+
@away = game_hash['away'] || game_hash['away_team']['id']
|
17
|
+
@status = game_hash['status']
|
18
|
+
@quarter = game_hash['quarter'].to_i
|
19
|
+
@clock = game_hash['clock']
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@weather = Weather.new(xml.xpath('weather'))
|
29
|
-
end
|
21
|
+
@home_team = Team.new(game_hash['home_team'])
|
22
|
+
@away_team = Team.new(game_hash['away_team'])
|
23
|
+
@venue = Venue.new(game_hash['venue'])
|
24
|
+
@broadcast = Broadcast.new(game_hash['broadcast'])
|
25
|
+
@weather = Weather.new(game_hash['weather'])
|
30
26
|
end
|
31
27
|
|
32
28
|
##
|
33
29
|
# Wrapper for Nfl.statistics
|
34
|
-
# TODO
|
35
30
|
def statistics
|
36
|
-
|
31
|
+
Nfl.game_statistics(year, season, week, home, away, 1)
|
37
32
|
end
|
38
33
|
|
39
34
|
##
|
@@ -4,13 +4,13 @@ module SportsDataApi
|
|
4
4
|
include Enumerable
|
5
5
|
attr_reader :games, :year, :season, :week
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@year =
|
9
|
-
@season =
|
10
|
-
@week =
|
7
|
+
def initialize(year, season, week, games_hash)
|
8
|
+
@year = year
|
9
|
+
@season = season
|
10
|
+
@week = week
|
11
11
|
|
12
|
-
@games =
|
13
|
-
Game.new(@year, @season, @week,
|
12
|
+
@games = games_hash['games'].map do |game_hash|
|
13
|
+
Game.new(@year, @season, @week, game_hash)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -23,7 +23,6 @@ module SportsDataApi
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
27
|
end
|
29
|
-
end
|
28
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nfl
|
3
3
|
class Player
|
4
|
-
def initialize(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
player_ivar[attr_name.to_sym] = attr_value.value
|
10
|
-
end
|
4
|
+
def initialize(json)
|
5
|
+
player_ivar = self.instance_variable_set("@player", {})
|
6
|
+
self.class.class_eval { attr_reader :"player" }
|
7
|
+
json.each_pair do | attr_name, attr_value|
|
8
|
+
player_ivar[attr_name.to_sym] = attr_value
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
@@ -2,22 +2,12 @@ module SportsDataApi
|
|
2
2
|
module Nfl
|
3
3
|
class PlayerSeasonStats
|
4
4
|
attr_reader :stats, :id, :players
|
5
|
-
def initialize(
|
6
|
-
xml = xml.first if xml.is_a? Nokogiri::XML::NodeSet
|
5
|
+
def initialize(json)
|
7
6
|
@players = []
|
8
|
-
|
7
|
+
json['players'].each do | p |
|
9
8
|
player = {}
|
10
|
-
stats = []
|
11
|
-
|
12
|
-
p.children.each do | stat |
|
13
|
-
if stat.name == "text"
|
14
|
-
next
|
15
|
-
end
|
16
|
-
stats << SportsDataApi::Stats.new(stat)
|
17
|
-
end
|
18
|
-
|
19
9
|
player[:id] = p['id']
|
20
|
-
player[:stats] =
|
10
|
+
player[:stats] = p['statistics']
|
21
11
|
@players << player
|
22
12
|
end
|
23
13
|
end
|
@@ -3,14 +3,12 @@ module SportsDataApi
|
|
3
3
|
class Season
|
4
4
|
attr_reader :year, :type, :weeks
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(season_hash)
|
7
7
|
@weeks = []
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
Week.new(@year, @type, week_xml)
|
13
|
-
end
|
8
|
+
@year = season_hash['season']
|
9
|
+
@type = season_hash['type'].to_sym
|
10
|
+
@weeks = season_hash['weeks'].map do |week_hash|
|
11
|
+
Week.new(@year, @type, week_hash)
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -1,22 +1,36 @@
|
|
1
1
|
module SportsDataApi
|
2
2
|
module Nfl
|
3
3
|
class Team
|
4
|
-
attr_reader :id, :name, :conference, :division, :market, :remaining_challenges,
|
4
|
+
attr_reader :id, :name, :conference, :division, :market, :remaining_challenges,
|
5
|
+
:remaining_timeouts, :score, :quarters, :venue, :points, :statistics, :players
|
5
6
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
@name = xml['name']
|
7
|
+
def initialize(team_hash, conference = nil, division = nil)
|
8
|
+
if team_hash
|
9
|
+
@id = team_hash['id']
|
10
|
+
@name = team_hash['name']
|
11
11
|
@conference = conference
|
12
12
|
@division = division
|
13
|
-
@market =
|
14
|
-
@remaining_challenges =
|
15
|
-
@remaining_timeouts =
|
16
|
-
@quarters =
|
17
|
-
|
13
|
+
@market = team_hash['market']
|
14
|
+
@remaining_challenges = team_hash['remaining_challenges']
|
15
|
+
@remaining_timeouts = team_hash['remaining_timeouts']
|
16
|
+
@quarters = []
|
17
|
+
if team_hash['scoring']
|
18
|
+
team_hash['scoring'].each do |scoring_hash|
|
19
|
+
@quarters[scoring_hash['quarter']-1] = scoring_hash['points']
|
20
|
+
end
|
18
21
|
end
|
19
22
|
@quarters = @quarters.fill(0, @quarters.size, 4 - @quarters.size)
|
23
|
+
|
24
|
+
# Parse the Venue data if it exists
|
25
|
+
if team_hash.key?('venue')
|
26
|
+
@venue = Venue.new(team_hash['venue'])
|
27
|
+
end
|
28
|
+
|
29
|
+
if team_hash['statistics']
|
30
|
+
@statistics = parse_team_statistics(team_hash['statistics'])
|
31
|
+
@players = parse_player_statistics(team_hash['statistics'])
|
32
|
+
end
|
33
|
+
@points = team_hash['points'] || score
|
20
34
|
end
|
21
35
|
end
|
22
36
|
|
@@ -41,6 +55,31 @@ module SportsDataApi
|
|
41
55
|
end
|
42
56
|
end
|
43
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
def parse_team_statistics(stats_hash)
|
61
|
+
stats = {}
|
62
|
+
stats_hash.keys.each do |key|
|
63
|
+
stats[key] = stats_hash[key]['team']
|
64
|
+
end
|
65
|
+
stats
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_player_statistics(stats_hash)
|
69
|
+
players = []
|
70
|
+
stats_hash.keys.each do |key|
|
71
|
+
next if !stats_hash[key]['players']
|
72
|
+
stats_hash[key]['players'].each do |p|
|
73
|
+
player = players.select{|a| a['id'] == p['id']}.first || {}
|
74
|
+
players << player if !players.select{|a| a['id'] == p['id']}.first
|
75
|
+
['id', 'name', 'jersey', 'position'].each do |k|
|
76
|
+
player[k] = p.delete(k)
|
77
|
+
end
|
78
|
+
player[key] = p
|
79
|
+
end
|
80
|
+
end
|
81
|
+
players
|
82
|
+
end
|
44
83
|
end
|
45
84
|
end
|
46
85
|
end
|
@@ -3,12 +3,9 @@ module SportsDataApi
|
|
3
3
|
class TeamRoster
|
4
4
|
attr_reader :players
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(json)
|
7
7
|
@players = []
|
8
|
-
|
9
|
-
if player.name == "text"
|
10
|
-
next
|
11
|
-
end
|
8
|
+
json['players'].each do | player |
|
12
9
|
@players << Player.new(player)
|
13
10
|
end
|
14
11
|
end
|
@@ -2,16 +2,11 @@ module SportsDataApi
|
|
2
2
|
module Nfl
|
3
3
|
class TeamSeasonStats
|
4
4
|
attr_reader :id, :stats
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
@id = xml['id']
|
5
|
+
def initialize(json)
|
6
|
+
@id = json['id']
|
8
7
|
@stats = []
|
9
|
-
|
10
|
-
|
11
|
-
if stat.name == "text"
|
12
|
-
next
|
13
|
-
end
|
14
|
-
@stats << SportsDataApi::Stats.new(stat)
|
8
|
+
json['statistics'].each_pair do | key, val |
|
9
|
+
@stats << { key: val }
|
15
10
|
end
|
16
11
|
end
|
17
12
|
end
|