espn_pub 0.1.10 → 0.1.11
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 549629bccc7f2a274c7c79e4b54c3eeb729c573275d4532ddd3013e250612fe5
|
|
4
|
+
data.tar.gz: 5cdb779d1d7198086eb40c7efa5cf683676d55f89b10ad2d37a1d6b5f99473df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 50d7e48c80b08c7384958414f39bfd57aade6ac2c3ce93d7567256970cd16d88a15421e8368b4a83ebefcd0477a30371ff08391d560b8abf4d2177b4cff9d6eb
|
|
7
|
+
data.tar.gz: a39dbe3f2ef9b6aea6766d84c838dcabaee451aa36c3335f7cd0926446afcb613b1ec64bf1c024f77941991f87c948a651cc8972eb4fad9abf1da3118038099b
|
|
@@ -18,7 +18,7 @@ module EspnPub
|
|
|
18
18
|
3 => Type::POSTSEASON
|
|
19
19
|
}.freeze
|
|
20
20
|
|
|
21
|
-
attr_reader :id, :home_team, :away_team, :date, :type, :venue, :league
|
|
21
|
+
attr_reader :id, :home_team, :away_team, :date, :type, :venue, :league
|
|
22
22
|
|
|
23
23
|
# Initialize a Game entity.
|
|
24
24
|
#
|
|
@@ -28,6 +28,7 @@ module EspnPub
|
|
|
28
28
|
# @param date [DateTime] The scheduled game date.
|
|
29
29
|
# @param type [String] The type of the game.
|
|
30
30
|
# @param venue [EspnPub::Entities::Venue] The venue of the game.
|
|
31
|
+
# @param minutes [Integer] The length of the game in minutes.
|
|
31
32
|
def initialize(id:, league:, home_team:, away_team:, date:, type: nil, venue: nil)
|
|
32
33
|
@id = id
|
|
33
34
|
@league = league
|
|
@@ -39,42 +40,85 @@ module EspnPub
|
|
|
39
40
|
super()
|
|
40
41
|
end
|
|
41
42
|
|
|
42
|
-
def
|
|
43
|
-
unless defined?(@
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
)
|
|
43
|
+
def player_game_stats
|
|
44
|
+
unless defined?(@player_game_stats)
|
|
45
|
+
teams = game_summary_response&.dig('boxscore', 'players')
|
|
46
|
+
@player_game_stats = []
|
|
47
|
+
|
|
48
|
+
return @player_game_stats unless teams
|
|
49
|
+
|
|
50
|
+
teams.each do |team_data|
|
|
51
|
+
team = [home_team, away_team].find { |team| team.id == team_data['team']['id'] }
|
|
52
|
+
stats_keys = team_data['statistics'][0]['names']
|
|
53
|
+
|
|
54
|
+
team_data['statistics'][0]['athletes'].each do |athlete|
|
|
55
|
+
player = EspnPub::Entities::Player.new(
|
|
56
|
+
id: athlete['athlete']['id'],
|
|
57
|
+
sport: league.sport,
|
|
58
|
+
league_name: league.league_name
|
|
59
|
+
)
|
|
60
|
+
stats_data = {}
|
|
61
|
+
stats_keys.each_with_index do |key, index|
|
|
62
|
+
stats_data[key] = athlete['stats'][index]
|
|
69
63
|
end
|
|
64
|
+
@player_game_stats << EspnPub::Entities::PlayerGameStat.new(
|
|
65
|
+
player: player, team: team, stats_data: stats_data
|
|
66
|
+
)
|
|
70
67
|
end
|
|
71
|
-
rescue Client::UnexpectedResponseCodeError => e
|
|
72
|
-
warn "Failed to fetch game stats for #{id}: #{e.message}"
|
|
73
|
-
return []
|
|
74
68
|
end
|
|
75
69
|
end
|
|
76
70
|
|
|
77
|
-
@
|
|
71
|
+
@player_game_stats
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def team_game_stats
|
|
75
|
+
unless defined?(@team_game_stats)
|
|
76
|
+
teams = game_summary_response&.dig('boxscore', 'teams')
|
|
77
|
+
@team_game_stats = []
|
|
78
|
+
|
|
79
|
+
return @team_game_stats unless teams
|
|
80
|
+
|
|
81
|
+
teams.each do |team_data|
|
|
82
|
+
team = [home_team, away_team].find { |team| team.id == team_data['team']['id'] }
|
|
83
|
+
stats_data = {}
|
|
84
|
+
team_data['statistics'].each_with_object(stats_data) do |stat, memo|
|
|
85
|
+
next memo unless labels.include?(stat['label'])
|
|
86
|
+
|
|
87
|
+
memo[stat['label']] = stat['displayValue']
|
|
88
|
+
end
|
|
89
|
+
@team_game_stats << EspnPub::Entities::TeamGameStat.new(
|
|
90
|
+
team: team, stats_data: stats_data
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
@team_game_stats
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def minutes
|
|
98
|
+
unless defined?(@minutes)
|
|
99
|
+
@minutes = 48
|
|
100
|
+
periods = game_summary_response&.dig('header', 'competitions', 0, 'competitors', 0, 'linescores')
|
|
101
|
+
@minutes += (periods.count - 4) * 5 if periods
|
|
102
|
+
end
|
|
103
|
+
@minutes
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def labels
|
|
107
|
+
['FG', '3PT', 'FT', 'Rebounds', 'Offensive Rebounds', 'Defensive Rebounds', 'Assists', 'Steals', 'Blocks',
|
|
108
|
+
'Turnovers']
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def game_summary_response
|
|
112
|
+
unless defined?(@game_summary_response)
|
|
113
|
+
begin
|
|
114
|
+
path = format SUMMARY_PATH, EspnPub::Client::API_VERSION, league.sport, league.league_name, id
|
|
115
|
+
@game_summary_response = EspnPub::Client.new.send_request(path)
|
|
116
|
+
rescue Client::UnexpectedResponseCodeError => e
|
|
117
|
+
warn "Failed to fetch game summary for #{id}: #{e.message}"
|
|
118
|
+
return nil
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
@game_summary_response
|
|
78
122
|
end
|
|
79
123
|
end
|
|
80
124
|
end
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module EspnPub
|
|
2
4
|
module Entities
|
|
3
|
-
class
|
|
4
|
-
|
|
5
|
+
class PlayerGameStat < Base
|
|
5
6
|
attr_reader :player, :team, :stats_data
|
|
6
7
|
|
|
7
8
|
def initialize(player:, team:, stats_data: {})
|
|
8
9
|
@player = player
|
|
9
10
|
@team = team
|
|
10
11
|
@stats_data = stats_data
|
|
12
|
+
super()
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
|
-
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EspnPub
|
|
4
|
+
module Entities
|
|
5
|
+
class TeamGameStat < Base
|
|
6
|
+
attr_reader :team, :stats_data
|
|
7
|
+
|
|
8
|
+
def initialize(team:, stats_data: {})
|
|
9
|
+
@team = team
|
|
10
|
+
@stats_data = stats_data
|
|
11
|
+
super()
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/espn_pub/version.rb
CHANGED
data/lib/espn_pub.rb
CHANGED
|
@@ -13,7 +13,8 @@ require_relative 'espn_pub/entities/team'
|
|
|
13
13
|
require_relative 'espn_pub/entities/venue'
|
|
14
14
|
require_relative 'espn_pub/entities/player'
|
|
15
15
|
require_relative 'espn_pub/entities/game'
|
|
16
|
-
require_relative 'espn_pub/entities/
|
|
16
|
+
require_relative 'espn_pub/entities/player_game_stat'
|
|
17
|
+
require_relative 'espn_pub/entities/team_game_stat'
|
|
17
18
|
|
|
18
19
|
module EspnPub
|
|
19
20
|
end
|
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.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeffrey Bowman
|
|
@@ -149,10 +149,11 @@ 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
|
|
153
152
|
- lib/espn_pub/entities/league.rb
|
|
154
153
|
- lib/espn_pub/entities/player.rb
|
|
154
|
+
- lib/espn_pub/entities/player_game_stat.rb
|
|
155
155
|
- lib/espn_pub/entities/team.rb
|
|
156
|
+
- lib/espn_pub/entities/team_game_stat.rb
|
|
156
157
|
- lib/espn_pub/entities/venue.rb
|
|
157
158
|
- lib/espn_pub/version.rb
|
|
158
159
|
homepage: https://github.com/bowmanje/espn-pub-rb
|