espn_pub 0.1.9 → 0.1.10
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/lib/espn_pub/entities/game.rb +43 -2
- data/lib/espn_pub/entities/game_stat.rb +14 -0
- data/lib/espn_pub/entities/league.rb +1 -0
- data/lib/espn_pub/entities/player.rb +0 -1
- data/lib/espn_pub/version.rb +1 -1
- data/lib/espn_pub.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 14da1d20a38673887a74f2c5bbedcbd9b25bb6cffc3a37c1d9be0b8e74947f51
|
|
4
|
+
data.tar.gz: 8b1c4e95eaf88f9c36b5892c435bcd9a8182c462aa1651d1c55e08c159b4a8e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2007bfe5fae90ddb387028065ac41070cb8209deb000c8c7fb5d82c9f98949490b3990ddbf44b620cf2c90b9f6f76c64d150e5663344f7aafcfea7b1a7350bf0
|
|
7
|
+
data.tar.gz: 64a3f0cf5598139d5885a0f2e0fa1d1aed5871eb3115621e22c95fdc339018dc386e947b9d33133f1de56cd835b876493a0e245b010f4f123a92dfa44f3aeb83
|
|
@@ -10,13 +10,15 @@ module EspnPub
|
|
|
10
10
|
POSTSEASON = 'postseason'
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
SUMMARY_PATH = '/apis/site/%s/sports/%s/%s/summary?event=%s'
|
|
14
|
+
|
|
13
15
|
GAME_TYPES = {
|
|
14
16
|
1 => Type::PRESEASON,
|
|
15
17
|
2 => Type::REGULAR,
|
|
16
18
|
3 => Type::POSTSEASON
|
|
17
19
|
}.freeze
|
|
18
20
|
|
|
19
|
-
attr_reader :id, :home_team, :away_team, :date, :type, :venue
|
|
21
|
+
attr_reader :id, :home_team, :away_team, :date, :type, :venue, :league, :game_stats
|
|
20
22
|
|
|
21
23
|
# Initialize a Game entity.
|
|
22
24
|
#
|
|
@@ -26,8 +28,9 @@ module EspnPub
|
|
|
26
28
|
# @param date [DateTime] The scheduled game date.
|
|
27
29
|
# @param type [String] The type of the game.
|
|
28
30
|
# @param venue [EspnPub::Entities::Venue] The venue of the game.
|
|
29
|
-
def initialize(id:, home_team:, away_team:, date:, type: nil, venue: nil)
|
|
31
|
+
def initialize(id:, league:, home_team:, away_team:, date:, type: nil, venue: nil)
|
|
30
32
|
@id = id
|
|
33
|
+
@league = league
|
|
31
34
|
@home_team = home_team
|
|
32
35
|
@away_team = away_team
|
|
33
36
|
@date = date
|
|
@@ -35,6 +38,44 @@ module EspnPub
|
|
|
35
38
|
@venue = venue
|
|
36
39
|
super()
|
|
37
40
|
end
|
|
41
|
+
|
|
42
|
+
def game_stats
|
|
43
|
+
unless defined?(@game_stats)
|
|
44
|
+
begin
|
|
45
|
+
path = format SUMMARY_PATH, EspnPub::Client::API_VERSION, league.sport, league.league_name, id
|
|
46
|
+
response = EspnPub::Client.new.send_request(path)
|
|
47
|
+
teams = response.dig('boxscore', 'players')
|
|
48
|
+
@game_stats = []
|
|
49
|
+
|
|
50
|
+
return @game_stats unless teams
|
|
51
|
+
|
|
52
|
+
teams.each do |team_data|
|
|
53
|
+
team = [home_team, away_team].find { |team| team.id == team_data['team']['id'] }
|
|
54
|
+
stats_keys = team_data['statistics'][0].dig('names')
|
|
55
|
+
|
|
56
|
+
team_data['statistics'][0]['athletes'].each do |athlete|
|
|
57
|
+
player = EspnPub::Entities::Player.new(
|
|
58
|
+
id: athlete['athlete']['id'],
|
|
59
|
+
sport: league.sport,
|
|
60
|
+
league_name: league.league_name
|
|
61
|
+
)
|
|
62
|
+
stats_data = {}
|
|
63
|
+
stats_keys.each_with_index do |key, index|
|
|
64
|
+
stats_data[key] = athlete['stats'][index]
|
|
65
|
+
end
|
|
66
|
+
@game_stats << EspnPub::Entities::GameStat.new(
|
|
67
|
+
player: player, team: team, stats_data: stats_data
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
rescue Client::UnexpectedResponseCodeError => e
|
|
72
|
+
warn "Failed to fetch game stats for #{id}: #{e.message}"
|
|
73
|
+
return []
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
@game_stats
|
|
78
|
+
end
|
|
38
79
|
end
|
|
39
80
|
end
|
|
40
81
|
end
|
|
@@ -86,6 +86,7 @@ module EspnPub
|
|
|
86
86
|
(games_resp['events'] || []).map do |game_data|
|
|
87
87
|
EspnPub::Entities::Game.new(
|
|
88
88
|
id: game_data['id'],
|
|
89
|
+
league: self,
|
|
89
90
|
type: Game::GAME_TYPES[game_data.dig('season', 'type')],
|
|
90
91
|
home_team: EspnPub::Entities::Team.fetch_by_id(
|
|
91
92
|
id: game_data.dig('competitions', 0, 'competitors', 0, 'id'),
|
|
@@ -84,7 +84,6 @@ module EspnPub
|
|
|
84
84
|
position: athlete_data.dig('position', 'abbreviation'),
|
|
85
85
|
team_id: athlete_data.dig('team', 'id'),
|
|
86
86
|
date_of_birth: parse_date_of_birth(athlete_data['dateOfBirth']),
|
|
87
|
-
birth_place_data: athlete_data['birthPlace'],
|
|
88
87
|
height: athlete_data['displayHeight'],
|
|
89
88
|
weight: athlete_data['displayWeight'],
|
|
90
89
|
debut_year: athlete_data['debutYear']
|
data/lib/espn_pub/version.rb
CHANGED
data/lib/espn_pub.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: espn_pub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeffrey Bowman
|
|
@@ -149,6 +149,7 @@ files:
|
|
|
149
149
|
- lib/espn_pub/client.rb
|
|
150
150
|
- lib/espn_pub/entities/base.rb
|
|
151
151
|
- lib/espn_pub/entities/game.rb
|
|
152
|
+
- lib/espn_pub/entities/game_stat.rb
|
|
152
153
|
- lib/espn_pub/entities/league.rb
|
|
153
154
|
- lib/espn_pub/entities/player.rb
|
|
154
155
|
- lib/espn_pub/entities/team.rb
|