espn_pub 0.1.9 → 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 +4 -4
- data/lib/espn_pub/entities/game.rb +87 -2
- data/lib/espn_pub/entities/league.rb +1 -0
- data/lib/espn_pub/entities/player.rb +0 -1
- data/lib/espn_pub/entities/player_game_stat.rb +16 -0
- data/lib/espn_pub/entities/team_game_stat.rb +15 -0
- data/lib/espn_pub/version.rb +1 -1
- data/lib/espn_pub.rb +2 -0
- metadata +3 -1
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
|
|
@@ -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
|
|
20
22
|
|
|
21
23
|
# Initialize a Game entity.
|
|
22
24
|
#
|
|
@@ -26,8 +28,10 @@ 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
|
-
|
|
31
|
+
# @param minutes [Integer] The length of the game in minutes.
|
|
32
|
+
def initialize(id:, league:, home_team:, away_team:, date:, type: nil, venue: nil)
|
|
30
33
|
@id = id
|
|
34
|
+
@league = league
|
|
31
35
|
@home_team = home_team
|
|
32
36
|
@away_team = away_team
|
|
33
37
|
@date = date
|
|
@@ -35,6 +39,87 @@ module EspnPub
|
|
|
35
39
|
@venue = venue
|
|
36
40
|
super()
|
|
37
41
|
end
|
|
42
|
+
|
|
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]
|
|
63
|
+
end
|
|
64
|
+
@player_game_stats << EspnPub::Entities::PlayerGameStat.new(
|
|
65
|
+
player: player, team: team, stats_data: stats_data
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
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
|
|
122
|
+
end
|
|
38
123
|
end
|
|
39
124
|
end
|
|
40
125
|
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']
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EspnPub
|
|
4
|
+
module Entities
|
|
5
|
+
class PlayerGameStat < Base
|
|
6
|
+
attr_reader :player, :team, :stats_data
|
|
7
|
+
|
|
8
|
+
def initialize(player:, team:, stats_data: {})
|
|
9
|
+
@player = player
|
|
10
|
+
@team = team
|
|
11
|
+
@stats_data = stats_data
|
|
12
|
+
super()
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
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,6 +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/player_game_stat'
|
|
17
|
+
require_relative 'espn_pub/entities/team_game_stat'
|
|
16
18
|
|
|
17
19
|
module EspnPub
|
|
18
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
|
|
@@ -151,7 +151,9 @@ files:
|
|
|
151
151
|
- lib/espn_pub/entities/game.rb
|
|
152
152
|
- lib/espn_pub/entities/league.rb
|
|
153
153
|
- lib/espn_pub/entities/player.rb
|
|
154
|
+
- lib/espn_pub/entities/player_game_stat.rb
|
|
154
155
|
- lib/espn_pub/entities/team.rb
|
|
156
|
+
- lib/espn_pub/entities/team_game_stat.rb
|
|
155
157
|
- lib/espn_pub/entities/venue.rb
|
|
156
158
|
- lib/espn_pub/version.rb
|
|
157
159
|
homepage: https://github.com/bowmanje/espn-pub-rb
|