espn_pub 0.1.7 → 0.1.9
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/game.rb +4 -2
- data/lib/espn_pub/entities/league.rb +17 -16
- data/lib/espn_pub/entities/player.rb +14 -17
- data/lib/espn_pub/entities/team.rb +10 -12
- data/lib/espn_pub/entities/venue.rb +5 -18
- 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: 8b3eef8ac8d68e39e8b6a71bf2d710c7a23201942ae3bc9a36295860bea269e6
|
|
4
|
+
data.tar.gz: 5511f7625ee3536feb3a99a916bdac63e0f7b3e1f386a3508432661e4b28302c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3a38ba745e476818d6c54041768770cab08ec743f04b5f77100b5df547b082a72398a2f19e40bc5785703388c6da00112bd9e1cd8db8a978a60f2403366449e8
|
|
7
|
+
data.tar.gz: bc39cc00273050649458bb76a26c3652e26be7958db8d2da5332609171771c189708e860d61cefd3e085195ddd475179774142ce066016ba0f33698c4c01de2a
|
|
@@ -16,7 +16,7 @@ module EspnPub
|
|
|
16
16
|
3 => Type::POSTSEASON
|
|
17
17
|
}.freeze
|
|
18
18
|
|
|
19
|
-
attr_reader :id, :home_team, :away_team, :date, :type
|
|
19
|
+
attr_reader :id, :home_team, :away_team, :date, :type, :venue
|
|
20
20
|
|
|
21
21
|
# Initialize a Game entity.
|
|
22
22
|
#
|
|
@@ -25,12 +25,14 @@ module EspnPub
|
|
|
25
25
|
# @param away_team [EspnPub::Entities::Team] The away team.
|
|
26
26
|
# @param date [DateTime] The scheduled game date.
|
|
27
27
|
# @param type [String] The type of the game.
|
|
28
|
-
|
|
28
|
+
# @param venue [EspnPub::Entities::Venue] The venue of the game.
|
|
29
|
+
def initialize(id:, home_team:, away_team:, date:, type: nil, venue: nil)
|
|
29
30
|
@id = id
|
|
30
31
|
@home_team = home_team
|
|
31
32
|
@away_team = away_team
|
|
32
33
|
@date = date
|
|
33
34
|
@type = type
|
|
35
|
+
@venue = venue
|
|
34
36
|
super()
|
|
35
37
|
end
|
|
36
38
|
end
|
|
@@ -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,19 @@ 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
|
-
date: DateTime.parse(game_data['date'])
|
|
100
|
+
date: DateTime.parse(game_data['date']),
|
|
101
|
+
venue: EspnPub::Entities::Venue.from_api(game_data.dig('competitions', 0, 'venue'))
|
|
101
102
|
)
|
|
102
103
|
end
|
|
103
104
|
rescue Client::UnexpectedResponseCodeError => e
|
|
104
|
-
warn "Failed to fetch games for league #{
|
|
105
|
+
warn "Failed to fetch games for league #{league_name}: #{e.message}"
|
|
105
106
|
[]
|
|
106
107
|
end
|
|
107
108
|
|
|
@@ -109,7 +110,7 @@ module EspnPub
|
|
|
109
110
|
#
|
|
110
111
|
# @return [String, nil] The sport name or nil when unknown.
|
|
111
112
|
def sport
|
|
112
|
-
NAME_TO_SPORT[
|
|
113
|
+
NAME_TO_SPORT[league_name]
|
|
113
114
|
end
|
|
114
115
|
end
|
|
115
116
|
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,31 +27,30 @@ 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.
|
|
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
|
|
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
|
-
def initialize(id:, sport:,
|
|
43
|
-
date_of_birth: nil,
|
|
40
|
+
def initialize(id:, sport:, league_name:, first_name: nil, last_name: nil, position: nil, team_id: 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
|
|
47
46
|
@first_name = first_name
|
|
48
47
|
@last_name = last_name
|
|
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 =
|
|
53
|
-
@birth_state =
|
|
54
|
-
@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
|
|
@@ -64,9 +63,9 @@ module EspnPub
|
|
|
64
63
|
# @param sport [String] The sport name.
|
|
65
64
|
# @param league [String] The league identifier.
|
|
66
65
|
# @return [Player, nil] The player, or nil when the request fails or data is missing.
|
|
67
|
-
def self.fetch_by_id(id:, sport:,
|
|
66
|
+
def self.fetch_by_id(id:, sport:, league_name:)
|
|
68
67
|
client = EspnPub::Client.new
|
|
69
|
-
path = format ATHLETE_PATH, sport,
|
|
68
|
+
path = format ATHLETE_PATH, sport, league_name, id
|
|
70
69
|
begin
|
|
71
70
|
athlete_data = client.send_request(path)['athlete']
|
|
72
71
|
rescue Client::UnexpectedResponseCodeError => e
|
|
@@ -79,15 +78,13 @@ module EspnPub
|
|
|
79
78
|
new(
|
|
80
79
|
id: athlete_data['id'],
|
|
81
80
|
sport: sport,
|
|
82
|
-
|
|
81
|
+
league_name: league_name,
|
|
83
82
|
first_name: athlete_data['firstName'],
|
|
84
83
|
last_name: athlete_data['lastName'],
|
|
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
|
-
|
|
89
|
-
birth_state: athlete_data.dig('birthPlace', 'state'),
|
|
90
|
-
birth_country: athlete_data.dig('birthPlace', 'country'),
|
|
87
|
+
birth_place_data: athlete_data['birthPlace'],
|
|
91
88
|
height: athlete_data['displayHeight'],
|
|
92
89
|
weight: athlete_data['displayWeight'],
|
|
93
90
|
debut_year: athlete_data['debutYear']
|
|
@@ -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,20 +66,18 @@ 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'],
|
|
79
79
|
team_id: id,
|
|
80
|
-
|
|
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
|
-
:
|
|
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
|
|
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,
|
|
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
|
-
@
|
|
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
|
-
|
|
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
|
)
|
data/lib/espn_pub/version.rb
CHANGED