espn_pub 0.1.2 → 0.1.3

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: 4bce533b327d0ad217ebdce3abf887f7960ddc5c275a93063aae8df8918af0af
4
- data.tar.gz: cc6468fbbcdc9f8d27fdaf8481bb2f9b9591266c700f10f18ac0708f038cd0eb
3
+ metadata.gz: 39ccc2c710cc3da7638c7b0471a14a091007afe60eb54d9c7ff82c4c2cebdff2
4
+ data.tar.gz: 3fc94b08470f001ac7bf59ef5d44910c3f981e8a6934eddfa49ba68633a80e7a
5
5
  SHA512:
6
- metadata.gz: 84196f6df201cfacf81b1239506694468d570a46e98c31f41c08e0dcf4c2b1ef8a757e7185d35c4e1478d2673f1ecd330942b62e3d2e176e312bbf062036246e
7
- data.tar.gz: 7f8534155c22dcee1271fc9357254f636325c7dab6bf6528360bb4bae6f4f522a9fcabf974984b61cfc8d59c29223b394d10b4aa40ec2157251c864a9e4513d3
6
+ metadata.gz: e1888c3976d0013fb1f8ed12013ca16e320a46135c3666324870cd3ab4d2913223b6f2c536f571067deb660e924a2bdddae5f67da440b9007743112ad447e736
7
+ data.tar.gz: 983e4c30d6e86a00a7ddab38cf56b905abb7e9b7fdbfb2e9ea9bdb5f59c3391e3ad2c3938d70645aadddbae7094f4e6c7c3a6bb111e308bc1a3fe4105f834197
data/espn_pub.gemspec CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
23
23
  %w[espn_pub.gemspec README.md]
24
24
 
25
25
  spec.require_paths = ['lib']
26
+ spec.add_dependency 'date', '~> 3.3'
26
27
  spec.add_dependency 'json', '~> 2.6'
27
28
  spec.add_dependency 'net-http', '~> 0.3'
28
29
  spec.add_dependency 'uri', '~> 0.11'
29
- spec.add_dependency 'date', '~> 3.3'
30
30
  spec.add_development_dependency 'rake', '~> 13.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.13'
32
32
  spec.add_development_dependency 'rubocop', '~> 1.65'
@@ -14,15 +14,16 @@ module EspnPub
14
14
  end
15
15
 
16
16
  private
17
+
17
18
  # Build a new EspnPub::Client for API requests.
18
19
  #
19
20
  # @return [EspnPub::Client]
20
21
  def init_client
21
22
  EspnPub::Client.new(
22
23
  base_uri: Client::BASE_URI,
23
- version: Client::API_VERSION,
24
+ version: Client::API_VERSION
24
25
  )
25
26
  end
26
27
  end
27
28
  end
28
- end
29
+ end
@@ -21,4 +21,4 @@ module EspnPub
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -36,7 +36,7 @@ module EspnPub
36
36
  def teams
37
37
  unless defined?(@teams)
38
38
  begin
39
- path = format TEAMS_PATH, client.version, self.sport, name
39
+ path = format TEAMS_PATH, client.version, sport, name
40
40
  teams_resp = client.send_request(path)
41
41
  @teams = (teams_resp.dig('sports', 0, 'leagues', 0, 'teams') || []).map do |team_data|
42
42
  EspnPub::Entities::Team.new(
@@ -62,30 +62,28 @@ module EspnPub
62
62
  # @param date [Date, DateTime, nil] An optional date to filter games.
63
63
  # @return [Array<EspnPub::Entities::Game>]
64
64
  def games(date: nil)
65
- begin
66
- path = format GAMES_PATH, client.version, self.sport, name
67
- path += "?dates=#{date.strftime('%Y%m%d')}" if date
68
- games_resp = client.send_request(path)
69
- (games_resp.dig('events') || []).map do |game_data|
70
- EspnPub::Entities::Game.new(
71
- id: game_data['id'],
72
- home_team: EspnPub::Entities::Team.fetch_by_id(
73
- id: game_data.dig('competitions', 0, 'competitors', 0, 'id'),
74
- sport: sport,
75
- league: name
76
- ),
77
- away_team: EspnPub::Entities::Team.fetch_by_id(
78
- id: game_data.dig('competitions', 0, 'competitors', 1, 'id'),
79
- sport: sport,
80
- league: name
81
- ),
82
- date: DateTime.parse(game_data['date'])
83
- )
84
- end
85
- rescue Client::UnexpectedResponseCodeError => e
86
- warn "Failed to fetch games for league #{name}: #{e.message}"
87
- return []
65
+ path = format GAMES_PATH, client.version, sport, name
66
+ path += "?dates=#{date.strftime('%Y%m%d')}" if date
67
+ games_resp = client.send_request(path)
68
+ (games_resp['events'] || []).map do |game_data|
69
+ EspnPub::Entities::Game.new(
70
+ id: game_data['id'],
71
+ home_team: EspnPub::Entities::Team.fetch_by_id(
72
+ id: game_data.dig('competitions', 0, 'competitors', 0, 'id'),
73
+ sport: sport,
74
+ league: name
75
+ ),
76
+ away_team: EspnPub::Entities::Team.fetch_by_id(
77
+ id: game_data.dig('competitions', 0, 'competitors', 1, 'id'),
78
+ sport: sport,
79
+ league: name
80
+ ),
81
+ date: DateTime.parse(game_data['date'])
82
+ )
88
83
  end
84
+ rescue Client::UnexpectedResponseCodeError => e
85
+ warn "Failed to fetch games for league #{name}: #{e.message}"
86
+ []
89
87
  end
90
88
 
91
89
  # Return the sport name for this league.
@@ -1,16 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
4
+
3
5
  module EspnPub
4
6
  module Entities
5
7
  # Represents a player on a team.
6
8
  class Player < Base
9
+ ATHLETE_PATH = '/apis/common/v3/sports/%s/%s/athletes/%s'
10
+
7
11
  attr_reader :id,
8
12
  :sport,
9
13
  :league,
10
14
  :first_name,
11
15
  :last_name,
12
16
  :position,
13
- :team_id
17
+ :team_id,
18
+ :date_of_birth,
19
+ :birthCity,
20
+ :birthState,
21
+ :birthCountry,
22
+ :height,
23
+ :weight,
24
+ :debut_year
14
25
 
15
26
  # Initialize a Player entity.
16
27
  #
@@ -21,7 +32,15 @@ module EspnPub
21
32
  # @param last_name [String, nil] The player's last name.
22
33
  # @param position [String, nil] The player's position abbreviation.
23
34
  # @param team_id [String, nil] The identifier of the player's team.
24
- def initialize(id:, sport:, league:, first_name: nil, last_name: nil, position: nil, team_id: nil)
35
+ # @param date_of_birth [Date, nil] The player's date of birth.
36
+ # @param birthCity [String, nil] The player's birth city.
37
+ # @param birthState [String, nil] The player's birth state.
38
+ # @param birthCountry [String, nil] The player's birth country.
39
+ # @param height [String, nil] The player's listed height.
40
+ # @param weight [String, nil] The player's listed weight.
41
+ # @param debut_year [Integer, nil] The year the player made their debut.
42
+ def initialize(id:, sport:, league:, first_name: nil, last_name: nil, position: nil, team_id: nil,
43
+ date_of_birth: nil, birthCity: nil, birthState: nil, birthCountry: nil, height: nil, weight: nil, debut_year: nil)
25
44
  @id = id
26
45
  @sport = sport
27
46
  @league = league
@@ -29,15 +48,70 @@ module EspnPub
29
48
  @last_name = last_name
30
49
  @position = position
31
50
  @team_id = team_id
51
+ @date_of_birth = self.class.parse_date_of_birth(date_of_birth)
52
+ @birthCity = birthCity
53
+ @birthState = birthState
54
+ @birthCountry = birthCountry
55
+ @height = height
56
+ @weight = weight
57
+ @debut_year = debut_year
32
58
  super()
33
59
  end
34
60
 
61
+ # Fetch a player by ID from the ESPN common v3 athlete endpoint.
62
+ #
63
+ # @param id [String] The player identifier.
64
+ # @param sport [String] The sport name.
65
+ # @param league [String] The league identifier.
66
+ # @return [Player, nil] The player, or nil when the request fails or data is missing.
67
+ def self.fetch_by_id(id:, sport:, league:)
68
+ client = EspnPub::Client.new
69
+ path = format ATHLETE_PATH, sport, league, id
70
+ begin
71
+ athlete_data = client.send_request(path)['athlete']
72
+ rescue Client::UnexpectedResponseCodeError => e
73
+ warn "Failed to fetch player data for #{id}: #{e.message}"
74
+ return nil
75
+ end
76
+
77
+ return nil unless athlete_data
78
+
79
+ new(
80
+ id: athlete_data['id'],
81
+ sport: sport,
82
+ league: league,
83
+ first_name: athlete_data['firstName'],
84
+ last_name: athlete_data['lastName'],
85
+ position: athlete_data.dig('position', 'abbreviation'),
86
+ team_id: athlete_data.dig('team', 'id'),
87
+ date_of_birth: parse_date_of_birth(athlete_data['dateOfBirth']),
88
+ birthCity: athlete_data.dig('birthPlace', 'city'),
89
+ birthState: athlete_data.dig('birthPlace', 'state'),
90
+ birthCountry: athlete_data.dig('birthPlace', 'country'),
91
+ height: athlete_data['displayHeight'],
92
+ weight: athlete_data['displayWeight'],
93
+ debut_year: athlete_data['debutYear']
94
+ )
95
+ end
96
+
35
97
  # Return the player's full name.
36
98
  #
37
99
  # @return [String] The player's full name.
38
100
  def full_name
39
101
  @full_name ||= "#{first_name} #{last_name}"
40
102
  end
103
+
104
+ # @param value [String, Date, nil]
105
+ # @return [Date, nil]
106
+ def self.parse_date_of_birth(value)
107
+ return nil unless value
108
+ return value if value.is_a?(Date)
109
+ return nil unless value.is_a?(String)
110
+
111
+ Date.parse(value)
112
+ rescue ArgumentError
113
+ nil
114
+ end
41
115
  end
42
116
  end
43
- end
117
+ end
@@ -4,7 +4,6 @@ module EspnPub
4
4
  module Entities
5
5
  # Represents a sports team, eg. Miami Heat, New England Patriots, etc.
6
6
  class Team < Base
7
-
8
7
  TEAM_PATH = '/apis/site/%s/sports/%s/%s/teams/%s'
9
8
  ROSTER_PATH = '/apis/site/%s/sports/%s/%s/teams/%s/roster'
10
9
 
@@ -13,7 +12,8 @@ module EspnPub
13
12
  :location,
14
13
  :abbreviation,
15
14
  :sport,
16
- :league
15
+ :league,
16
+ :venue
17
17
 
18
18
  # Initialize a Team entity.
19
19
  #
@@ -23,13 +23,15 @@ module EspnPub
23
23
  # @param abbreviation [String] The team abbreviation.
24
24
  # @param sport [String] The sport name.
25
25
  # @param league [String] The league identifier.
26
- def initialize(id:, name:, location:, abbreviation:, sport:, league:)
26
+ # @param venue [EspnPub::Entities::Venue, nil] The team's home venue.
27
+ def initialize(id:, name:, location:, abbreviation:, sport:, league:, venue: nil)
27
28
  @id = id
28
29
  @name = name
29
30
  @location = location
30
31
  @abbreviation = abbreviation
31
32
  @sport = sport
32
33
  @league = league
34
+ @venue = venue
33
35
  super()
34
36
  end
35
37
 
@@ -37,7 +39,7 @@ module EspnPub
37
39
  client = EspnPub::Client.new
38
40
  path = format TEAM_PATH, client.version, sport, league, id
39
41
  begin
40
- team_data = client.send_request(path).dig('team')
42
+ team_data = client.send_request(path)['team']
41
43
  rescue Client::UnexpectedResponseCodeError => e
42
44
  warn "Failed to fetch team data for #{id}: #{e.message}"
43
45
  return nil
@@ -51,7 +53,8 @@ module EspnPub
51
53
  location: team_data['location'],
52
54
  abbreviation: team_data['abbreviation'],
53
55
  sport: sport,
54
- league: league
56
+ league: league,
57
+ venue: EspnPub::Entities::Venue.from_api(team_data.dig('franchise', 'venue'))
55
58
  )
56
59
  end
57
60
 
@@ -63,15 +66,22 @@ module EspnPub
63
66
  begin
64
67
  path = format ROSTER_PATH, client.version, sport, league, id
65
68
  roster_resp = client.send_request(path)
66
- @roster = (roster_resp.dig('athletes') || []).map do |athlete_data|
67
- player = EspnPub::Entities::Player.new(
69
+ @roster = (roster_resp['athletes'] || []).map do |athlete_data|
70
+ EspnPub::Entities::Player.new(
68
71
  id: athlete_data['id'],
69
72
  sport: sport,
70
73
  league: league,
71
74
  first_name: athlete_data['firstName'],
72
75
  last_name: athlete_data['lastName'],
73
76
  position: athlete_data['position']['abbreviation'],
74
- team_id: id
77
+ team_id: id,
78
+ birthCity: athlete_data.dig('birthPlace', 'city'),
79
+ birthState: athlete_data.dig('birthPlace', 'state'),
80
+ birthCountry: athlete_data.dig('birthPlace', 'country'),
81
+ date_of_birth: athlete_data['dateOfBirth'],
82
+ height: athlete_data['height'],
83
+ weight: athlete_data['weight'],
84
+ debut_year: athlete_data['debutYear']
75
85
  )
76
86
  end
77
87
  rescue Client::UnexpectedResponseCodeError => e
@@ -91,4 +101,4 @@ module EspnPub
91
101
  end
92
102
  end
93
103
  end
94
- end
104
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EspnPub
4
+ module Entities
5
+ # Represents a team's home venue (stadium or arena).
6
+ class Venue < Base
7
+ attr_reader :id,
8
+ :full_name,
9
+ :short_name,
10
+ :city,
11
+ :state,
12
+ :zip_code,
13
+ :country,
14
+ :indoor,
15
+ :grass
16
+
17
+ # Initialize a Venue entity.
18
+ #
19
+ # @param id [String] The venue identifier.
20
+ # @param full_name [String, nil] The venue's full name.
21
+ # @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.
26
+ # @param indoor [Boolean, nil] Whether the venue is indoors.
27
+ # @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)
30
+ @id = id
31
+ @full_name = full_name
32
+ @short_name = short_name
33
+ @city = city
34
+ @state = state
35
+ @zip_code = zip_code
36
+ @country = country
37
+ @indoor = indoor
38
+ @grass = grass
39
+ super()
40
+ end
41
+
42
+ # Build a Venue from ESPN API venue data.
43
+ #
44
+ # @param data [Hash, nil] Raw venue data from the API.
45
+ # @return [Venue, nil] A Venue instance, or nil when data is absent.
46
+ def self.from_api(data)
47
+ return nil unless data
48
+
49
+ new(
50
+ id: data['id'],
51
+ full_name: data['fullName'],
52
+ 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'),
57
+ indoor: data['indoor'],
58
+ grass: data['grass']
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EspnPub
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
data/lib/espn_pub.rb CHANGED
@@ -10,6 +10,7 @@ require_relative 'espn_pub/client'
10
10
  require_relative 'espn_pub/entities/base'
11
11
  require_relative 'espn_pub/entities/league'
12
12
  require_relative 'espn_pub/entities/team'
13
+ require_relative 'espn_pub/entities/venue'
13
14
  require_relative 'espn_pub/entities/player'
14
15
  require_relative 'espn_pub/entities/game'
15
16
 
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espn_pub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Bowman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-27 00:00:00.000000000 Z
11
+ date: 2026-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: date
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '3.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.6'
26
+ version: '3.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: net-http
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '2.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: '2.6'
41
41
  - !ruby/object:Gem::Dependency
42
- name: uri
42
+ name: net-http
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.11'
47
+ version: '0.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.11'
54
+ version: '0.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: date
56
+ name: uri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.3'
61
+ version: '0.11'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.3'
68
+ version: '0.11'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -153,6 +153,7 @@ files:
153
153
  - lib/espn_pub/entities/league.rb
154
154
  - lib/espn_pub/entities/player.rb
155
155
  - lib/espn_pub/entities/team.rb
156
+ - lib/espn_pub/entities/venue.rb
156
157
  - lib/espn_pub/version.rb
157
158
  homepage: https://github.com/bowmanje/espn-pub-rb
158
159
  licenses: