espn_pub 0.1.7 → 0.1.8

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: 9825c4b3b3277d1addc0d50c01683144de143366bfb394bccceee46f3b043d2c
4
- data.tar.gz: 6fc6a99c1285f4523cdd60696e340e868c4a48c49c9e9b7f6a6188fcad9b28e6
3
+ metadata.gz: 2313dc03f24eb1a9ece5883a51a186acd8497790d2d6b2b4291cdaa997c4c977
4
+ data.tar.gz: f2238e3abe174ade734ac70e183d2741e9f11f5fd49a96d6a77000b82086cd75
5
5
  SHA512:
6
- metadata.gz: b7c63799f4d0bdb87601e31a89bbadce8b3ce77dd14ac93dfff521d4a3cd1586b483b0490f86814d29e10093b52839bcb0ea5aec84e11831f794915f3149d316
7
- data.tar.gz: 23f0d9d8af7f36469fa15734aeea9c02162133f92c48ff67b46737d98eec811c0cac01c4f4b37c465ae1b333f39e5af78007872c3e9b30ead77c5d77669194a4
6
+ metadata.gz: 32011085498d278e9076c1332e53bc6aee395345f30adc547ded45705713e7e358e2c3da8663f3abd0c1ec7f179fc6b4f703f4d84e27c4f6f9ccc3dd79d4eb3f
7
+ data.tar.gz: 2b4bbf38c0aa43eeee07b4848c7eaaf9bde8d167cacb2890c657ea668ebd5132042a51b815c5485eaece594d7f8a3cab89ae8290f3eec5c99a6e29dce15de9f6
@@ -24,6 +24,10 @@ module EspnPub
24
24
  version: Client::API_VERSION
25
25
  )
26
26
  end
27
+
28
+ def normalize_name(name)
29
+ name.gsub(/[^a-zA-Z0-9]/i, '_').downcase
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -20,13 +20,13 @@ module EspnPub
20
20
  'nfl' => 'football'
21
21
  }.freeze
22
22
 
23
- attr_reader :name
23
+ attr_reader :league_name
24
24
 
25
- def self.fetch_season_details(name, season_year)
26
- raise ArgumentError, "Unknown league name: #{name}" unless NAME_TO_SPORT.key?(name)
25
+ def self.fetch_season_details(league_name, season_year)
26
+ raise ArgumentError, "Unknown league name: #{league_name}" unless NAME_TO_SPORT.key?(league_name)
27
27
  raise ArgumentError, 'Season year must be an integer' unless season_year.to_i.positive?
28
28
 
29
- path = format GAMES_PATH, EspnPub::Client::API_VERSION, NAME_TO_SPORT[name], name
29
+ path = format GAMES_PATH, EspnPub::Client::API_VERSION, NAME_TO_SPORT[league_name], league_name
30
30
  path += "?dates=#{Time.new(season_year).strftime('%Y%m%d')}"
31
31
  resp = EspnPub::Client.new.send_request(path)
32
32
  season = resp.dig('leagues', 0, 'season')
@@ -42,9 +42,9 @@ module EspnPub
42
42
 
43
43
  # Initialize a League instance.
44
44
  #
45
- # @param name [String] The league identifier string.
46
- def initialize(name)
47
- @name = name
45
+ # @param league_name [String] The league identifier string.
46
+ def initialize(league_name)
47
+ @league_name = normalize_name(league_name)
48
48
  super()
49
49
  end
50
50
 
@@ -54,7 +54,7 @@ module EspnPub
54
54
  def teams
55
55
  unless defined?(@teams)
56
56
  begin
57
- path = format TEAMS_PATH, client.version, sport, name
57
+ path = format TEAMS_PATH, client.version, sport, league_name
58
58
  teams_resp = client.send_request(path)
59
59
  @teams = (teams_resp.dig('sports', 0, 'leagues', 0, 'teams') || []).map do |team_data|
60
60
  EspnPub::Entities::Team.new(
@@ -63,11 +63,11 @@ module EspnPub
63
63
  location: team_data.dig('team', 'location'),
64
64
  abbreviation: team_data.dig('team', 'abbreviation'),
65
65
  sport: sport,
66
- league: name
66
+ league_name: league_name
67
67
  )
68
68
  end
69
69
  rescue Client::UnexpectedResponseCodeError => e
70
- warn "Failed to fetch teams for league #{name}: #{e.message}"
70
+ warn "Failed to fetch teams for league #{league_name}: #{e.message}"
71
71
  return []
72
72
  end
73
73
  end
@@ -80,7 +80,7 @@ module EspnPub
80
80
  # @param date [Date, DateTime, nil] An optional date to filter games.
81
81
  # @return [Array<EspnPub::Entities::Game>]
82
82
  def games(date: nil)
83
- path = format GAMES_PATH, client.version, sport, name
83
+ path = format GAMES_PATH, client.version, sport, league_name
84
84
  path += "?dates=#{date.strftime('%Y%m%d')}" if date
85
85
  games_resp = client.send_request(path)
86
86
  (games_resp['events'] || []).map do |game_data|
@@ -90,18 +90,18 @@ module EspnPub
90
90
  home_team: EspnPub::Entities::Team.fetch_by_id(
91
91
  id: game_data.dig('competitions', 0, 'competitors', 0, 'id'),
92
92
  sport: sport,
93
- league: name
93
+ league_name: league_name
94
94
  ),
95
95
  away_team: EspnPub::Entities::Team.fetch_by_id(
96
96
  id: game_data.dig('competitions', 0, 'competitors', 1, 'id'),
97
97
  sport: sport,
98
- league: name
98
+ league_name: league_name
99
99
  ),
100
100
  date: DateTime.parse(game_data['date'])
101
101
  )
102
102
  end
103
103
  rescue Client::UnexpectedResponseCodeError => e
104
- warn "Failed to fetch games for league #{name}: #{e.message}"
104
+ warn "Failed to fetch games for league #{league_name}: #{e.message}"
105
105
  []
106
106
  end
107
107
 
@@ -109,7 +109,7 @@ module EspnPub
109
109
  #
110
110
  # @return [String, nil] The sport name or nil when unknown.
111
111
  def sport
112
- NAME_TO_SPORT[name]
112
+ NAME_TO_SPORT[league_name]
113
113
  end
114
114
  end
115
115
  end
@@ -10,7 +10,7 @@ module EspnPub
10
10
 
11
11
  attr_reader :id,
12
12
  :sport,
13
- :league,
13
+ :league_name,
14
14
  :first_name,
15
15
  :last_name,
16
16
  :position,
@@ -27,7 +27,7 @@ module EspnPub
27
27
  #
28
28
  # @param id [String] The player identifier.
29
29
  # @param sport [String] The sport name.
30
- # @param league [String] The league identifier.
30
+ # @param league_name [String] The league identifier.
31
31
  # @param first_name [String, nil] The player's first name.
32
32
  # @param last_name [String, nil] The player's last name.
33
33
  # @param position [String, nil] The player's position abbreviation.
@@ -39,11 +39,11 @@ module EspnPub
39
39
  # @param height [String, nil] The player's listed height.
40
40
  # @param weight [String, nil] The player's listed weight.
41
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,
42
+ def initialize(id:, sport:, league_name:, first_name: nil, last_name: nil, position: nil, team_id: nil,
43
43
  date_of_birth: nil, birth_city: nil, birth_state: nil, birth_country: nil, height: nil, weight: nil, debut_year: nil)
44
44
  @id = id
45
45
  @sport = sport
46
- @league = league
46
+ @league_name = league_name
47
47
  @first_name = first_name
48
48
  @last_name = last_name
49
49
  @position = position
@@ -64,9 +64,9 @@ module EspnPub
64
64
  # @param sport [String] The sport name.
65
65
  # @param league [String] The league identifier.
66
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:)
67
+ def self.fetch_by_id(id:, sport:, league_name:)
68
68
  client = EspnPub::Client.new
69
- path = format ATHLETE_PATH, sport, league, id
69
+ path = format ATHLETE_PATH, sport, league_name, id
70
70
  begin
71
71
  athlete_data = client.send_request(path)['athlete']
72
72
  rescue Client::UnexpectedResponseCodeError => e
@@ -79,7 +79,7 @@ module EspnPub
79
79
  new(
80
80
  id: athlete_data['id'],
81
81
  sport: sport,
82
- league: league,
82
+ league_name: league_name,
83
83
  first_name: athlete_data['firstName'],
84
84
  last_name: athlete_data['lastName'],
85
85
  position: athlete_data.dig('position', 'abbreviation'),
@@ -12,7 +12,7 @@ module EspnPub
12
12
  :location,
13
13
  :abbreviation,
14
14
  :sport,
15
- :league,
15
+ :league_name,
16
16
  :venue
17
17
 
18
18
  # Initialize a Team entity.
@@ -22,24 +22,24 @@ module EspnPub
22
22
  # @param location [String] The team location.
23
23
  # @param abbreviation [String] The team abbreviation.
24
24
  # @param sport [String] The sport name.
25
- # @param league [String] The league identifier.
25
+ # @param league_name [String] The league identifier.
26
26
  # @param venue [EspnPub::Entities::Venue, nil] The team's home venue.
27
- def initialize(id:, name:, location:, abbreviation:, sport:, league:, venue: nil)
27
+ def initialize(id:, name:, location:, abbreviation:, sport:, league_name:, venue: nil)
28
28
  @id = id
29
29
  @name = name
30
30
  @location = location
31
31
  @abbreviation = abbreviation
32
32
  @sport = sport
33
- @league = league
33
+ @league_name = league_name
34
34
  @venue = venue
35
35
  super()
36
36
  end
37
37
 
38
- def self.fetch_by_id(id:, sport:, league:, user_agent: nil)
38
+ def self.fetch_by_id(id:, sport:, league_name:, user_agent: nil)
39
39
  client = EspnPub::Client.new
40
40
  client.user_agent = user_agent if user_agent
41
41
 
42
- path = format TEAM_PATH, client.version, sport, league, id
42
+ path = format TEAM_PATH, client.version, sport, league_name, id
43
43
  begin
44
44
  team_data = client.send_request(path)['team']
45
45
  rescue Client::UnexpectedResponseCodeError => e
@@ -55,7 +55,7 @@ module EspnPub
55
55
  location: team_data['location'],
56
56
  abbreviation: team_data['abbreviation'],
57
57
  sport: sport,
58
- league: league,
58
+ league_name: league_name,
59
59
  venue: EspnPub::Entities::Venue.from_api(team_data.dig('franchise', 'venue'))
60
60
  )
61
61
  end
@@ -66,13 +66,13 @@ module EspnPub
66
66
  def players
67
67
  unless defined?(@roster)
68
68
  begin
69
- path = format ROSTER_PATH, client.version, sport, league, id
69
+ path = format ROSTER_PATH, client.version, sport, league_name, id
70
70
  roster_resp = client.send_request(path)
71
71
  @roster = (roster_resp['athletes'] || []).map do |athlete_data|
72
72
  EspnPub::Entities::Player.new(
73
73
  id: athlete_data['id'],
74
74
  sport: sport,
75
- league: league,
75
+ league_name: league_name,
76
76
  first_name: athlete_data['firstName'],
77
77
  last_name: athlete_data['lastName'],
78
78
  position: athlete_data['position']['abbreviation'],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EspnPub
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Bowman