espn_pub 0.1.8 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2313dc03f24eb1a9ece5883a51a186acd8497790d2d6b2b4291cdaa997c4c977
4
- data.tar.gz: f2238e3abe174ade734ac70e183d2741e9f11f5fd49a96d6a77000b82086cd75
3
+ metadata.gz: 14da1d20a38673887a74f2c5bbedcbd9b25bb6cffc3a37c1d9be0b8e74947f51
4
+ data.tar.gz: 8b1c4e95eaf88f9c36b5892c435bcd9a8182c462aa1651d1c55e08c159b4a8e5
5
5
  SHA512:
6
- metadata.gz: 32011085498d278e9076c1332e53bc6aee395345f30adc547ded45705713e7e358e2c3da8663f3abd0c1ec7f179fc6b4f703f4d84e27c4f6f9ccc3dd79d4eb3f
7
- data.tar.gz: 2b4bbf38c0aa43eeee07b4848c7eaaf9bde8d167cacb2890c657ea668ebd5132042a51b815c5485eaece594d7f8a3cab89ae8290f3eec5c99a6e29dce15de9f6
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
21
+ attr_reader :id, :home_team, :away_team, :date, :type, :venue, :league, :game_stats
20
22
 
21
23
  # Initialize a Game entity.
22
24
  #
@@ -25,14 +27,55 @@ module EspnPub
25
27
  # @param away_team [EspnPub::Entities::Team] The away team.
26
28
  # @param date [DateTime] The scheduled game date.
27
29
  # @param type [String] The type of the game.
28
- def initialize(id:, home_team:, away_team:, date:, type: nil)
30
+ # @param venue [EspnPub::Entities::Venue] The venue of the game.
31
+ def initialize(id:, league:, home_team:, away_team:, date:, type: nil, venue: nil)
29
32
  @id = id
33
+ @league = league
30
34
  @home_team = home_team
31
35
  @away_team = away_team
32
36
  @date = date
33
37
  @type = type
38
+ @venue = venue
34
39
  super()
35
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
36
79
  end
37
80
  end
38
81
  end
@@ -0,0 +1,14 @@
1
+ module EspnPub
2
+ module Entities
3
+ class GameStat < Base
4
+
5
+ attr_reader :player, :team, :stats_data
6
+
7
+ def initialize(player:, team:, stats_data: {})
8
+ @player = player
9
+ @team = team
10
+ @stats_data = stats_data
11
+ end
12
+ end
13
+ end
14
+ 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'),
@@ -97,7 +98,8 @@ module EspnPub
97
98
  sport: sport,
98
99
  league_name: league_name
99
100
  ),
100
- date: DateTime.parse(game_data['date'])
101
+ date: DateTime.parse(game_data['date']),
102
+ venue: EspnPub::Entities::Venue.from_api(game_data.dig('competitions', 0, 'venue'))
101
103
  )
102
104
  end
103
105
  rescue Client::UnexpectedResponseCodeError => e
@@ -33,14 +33,13 @@ module EspnPub
33
33
  # @param position [String, nil] The player's position abbreviation.
34
34
  # @param team_id [String, nil] The identifier of the player's team.
35
35
  # @param date_of_birth [Date, nil] The player's date of birth.
36
- # @param birth_city [String, nil] The player's birth city.
37
- # @param birth_state [String, nil] The player's birth state.
38
- # @param birth_country [String, nil] The player's birth country.
36
+ # @param birth_place_data [Hash, nil] The player's birth place data.
39
37
  # @param height [String, nil] The player's listed height.
40
38
  # @param weight [String, nil] The player's listed weight.
41
39
  # @param debut_year [Integer, nil] The year the player made their debut.
42
40
  def initialize(id:, sport:, league_name:, first_name: nil, last_name: nil, position: nil, team_id: nil,
43
- date_of_birth: nil, birth_city: nil, birth_state: nil, birth_country: nil, height: nil, weight: nil, debut_year: nil)
41
+ date_of_birth: nil, height: nil, weight: nil, debut_year: nil,
42
+ birth_place_data: {})
44
43
  @id = id
45
44
  @sport = sport
46
45
  @league_name = league_name
@@ -49,9 +48,9 @@ module EspnPub
49
48
  @position = position
50
49
  @team_id = team_id
51
50
  @date_of_birth = self.class.parse_date_of_birth(date_of_birth)
52
- @birth_city = birth_city
53
- @birth_state = birth_state
54
- @birth_country = birth_country
51
+ @birth_city = birth_place_data['city']
52
+ @birth_state = birth_place_data['state']
53
+ @birth_country = birth_place_data['country']
55
54
  @height = height
56
55
  @weight = weight
57
56
  @debut_year = debut_year
@@ -85,9 +84,6 @@ module EspnPub
85
84
  position: athlete_data.dig('position', 'abbreviation'),
86
85
  team_id: athlete_data.dig('team', 'id'),
87
86
  date_of_birth: parse_date_of_birth(athlete_data['dateOfBirth']),
88
- birth_city: athlete_data.dig('birthPlace', 'city'),
89
- birth_state: athlete_data.dig('birthPlace', 'state'),
90
- birth_country: athlete_data.dig('birthPlace', 'country'),
91
87
  height: athlete_data['displayHeight'],
92
88
  weight: athlete_data['displayWeight'],
93
89
  debut_year: athlete_data['debutYear']
@@ -77,9 +77,7 @@ module EspnPub
77
77
  last_name: athlete_data['lastName'],
78
78
  position: athlete_data['position']['abbreviation'],
79
79
  team_id: id,
80
- birth_city: athlete_data.dig('birthPlace', 'city'),
81
- birth_state: athlete_data.dig('birthPlace', 'state'),
82
- birth_country: athlete_data.dig('birthPlace', 'country'),
80
+ birth_place_data: athlete_data&.fetch('birthPlace', {}),
83
81
  date_of_birth: athlete_data['dateOfBirth'],
84
82
  height: athlete_data['height'],
85
83
  weight: athlete_data['weight'],
@@ -7,10 +7,7 @@ module EspnPub
7
7
  attr_reader :id,
8
8
  :full_name,
9
9
  :short_name,
10
- :city,
11
- :state,
12
- :zip_code,
13
- :country,
10
+ :address_data,
14
11
  :indoor,
15
12
  :grass
16
13
 
@@ -19,21 +16,14 @@ module EspnPub
19
16
  # @param id [String] The venue identifier.
20
17
  # @param full_name [String, nil] The venue's full name.
21
18
  # @param short_name [String, nil] The venue's short name.
22
- # @param city [String, nil] The venue's city.
23
- # @param state [String, nil] The venue's state or province.
24
- # @param zip_code [String, nil] The venue's postal code.
25
- # @param country [String, nil] The venue's country.
19
+ # @param address_data [Hash, nil] The venue's address data.
26
20
  # @param indoor [Boolean, nil] Whether the venue is indoors.
27
21
  # @param grass [Boolean, nil] Whether the venue has a grass surface.
28
- def initialize(id:, full_name: nil, short_name: nil, city: nil, state: nil, zip_code: nil, country: nil,
29
- indoor: nil, grass: nil)
22
+ def initialize(id:, full_name: nil, short_name: nil, indoor: nil, grass: nil, address_data: {})
30
23
  @id = id
31
24
  @full_name = full_name
32
25
  @short_name = short_name
33
- @city = city
34
- @state = state
35
- @zip_code = zip_code
36
- @country = country
26
+ @address_data = address_data
37
27
  @indoor = indoor
38
28
  @grass = grass
39
29
  super()
@@ -50,10 +40,7 @@ module EspnPub
50
40
  id: data['id'],
51
41
  full_name: data['fullName'],
52
42
  short_name: data['shortName'],
53
- city: data.dig('address', 'city'),
54
- state: data.dig('address', 'state'),
55
- zip_code: data.dig('address', 'zipCode'),
56
- country: data.dig('address', 'country'),
43
+ address_data: data['address'],
57
44
  indoor: data['indoor'],
58
45
  grass: data['grass']
59
46
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EspnPub
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.10'
5
5
  end
data/lib/espn_pub.rb CHANGED
@@ -13,6 +13,7 @@ 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/game_stat'
16
17
 
17
18
  module EspnPub
18
19
  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.8
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