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 +4 -4
- data/lib/espn_pub/entities/base.rb +4 -0
- data/lib/espn_pub/entities/league.rb +15 -15
- data/lib/espn_pub/entities/player.rb +7 -7
- data/lib/espn_pub/entities/team.rb +9 -9
- data/lib/espn_pub/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2313dc03f24eb1a9ece5883a51a186acd8497790d2d6b2b4291cdaa997c4c977
|
|
4
|
+
data.tar.gz: f2238e3abe174ade734ac70e183d2741e9f11f5fd49a96d6a77000b82086cd75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32011085498d278e9076c1332e53bc6aee395345f30adc547ded45705713e7e358e2c3da8663f3abd0c1ec7f179fc6b4f703f4d84e27c4f6f9ccc3dd79d4eb3f
|
|
7
|
+
data.tar.gz: 2b4bbf38c0aa43eeee07b4848c7eaaf9bde8d167cacb2890c657ea668ebd5132042a51b815c5485eaece594d7f8a3cab89ae8290f3eec5c99a6e29dce15de9f6
|
|
@@ -20,13 +20,13 @@ module EspnPub
|
|
|
20
20
|
'nfl' => 'football'
|
|
21
21
|
}.freeze
|
|
22
22
|
|
|
23
|
-
attr_reader :
|
|
23
|
+
attr_reader :league_name
|
|
24
24
|
|
|
25
|
-
def self.fetch_season_details(
|
|
26
|
-
raise ArgumentError, "Unknown league 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[
|
|
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
|
|
46
|
-
def initialize(
|
|
47
|
-
@
|
|
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,
|
|
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
|
-
|
|
66
|
+
league_name: league_name
|
|
67
67
|
)
|
|
68
68
|
end
|
|
69
69
|
rescue Client::UnexpectedResponseCodeError => e
|
|
70
|
-
warn "Failed to fetch teams for league #{
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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 #{
|
|
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[
|
|
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
|
-
:
|
|
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
|
|
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:,
|
|
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
|
-
@
|
|
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:,
|
|
67
|
+
def self.fetch_by_id(id:, sport:, league_name:)
|
|
68
68
|
client = EspnPub::Client.new
|
|
69
|
-
path = format ATHLETE_PATH, sport,
|
|
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
|
-
|
|
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
|
-
:
|
|
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
|
|
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:,
|
|
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
|
-
@
|
|
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:,
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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'],
|
data/lib/espn_pub/version.rb
CHANGED