espn_pub 0.1.0 → 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 +4 -4
- data/README.md +116 -1
- data/espn_pub.gemspec +3 -2
- data/lib/espn_pub/client.rb +1 -1
- data/lib/espn_pub/entities/base.rb +3 -2
- data/lib/espn_pub/entities/game.rb +7 -7
- data/lib/espn_pub/entities/league.rb +22 -16
- data/lib/espn_pub/entities/player.rb +78 -4
- data/lib/espn_pub/entities/team.rb +47 -7
- data/lib/espn_pub/entities/venue.rb +63 -0
- data/lib/espn_pub/version.rb +1 -1
- data/lib/espn_pub.rb +1 -0
- metadata +16 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 39ccc2c710cc3da7638c7b0471a14a091007afe60eb54d9c7ff82c4c2cebdff2
|
|
4
|
+
data.tar.gz: 3fc94b08470f001ac7bf59ef5d44910c3f981e8a6934eddfa49ba68633a80e7a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1888c3976d0013fb1f8ed12013ca16e320a46135c3666324870cd3ab4d2913223b6f2c536f571067deb660e924a2bdddae5f67da440b9007743112ad447e736
|
|
7
|
+
data.tar.gz: 983e4c30d6e86a00a7ddab38cf56b905abb7e9b7fdbfb2e9ea9bdb5f59c3391e3ad2c3938d70645aadddbae7094f4e6c7c3a6bb111e308bc1a3fe4105f834197
|
data/README.md
CHANGED
|
@@ -1 +1,116 @@
|
|
|
1
|
-
# espn-pub-rb
|
|
1
|
+
# espn-pub-rb
|
|
2
|
+
|
|
3
|
+
`espn_pub` is a lightweight Ruby client for the public ESPN API. It provides a simple interface for fetching league teams, team rosters, players, and game scoreboards.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Fetch NBA and NFL teams
|
|
8
|
+
- Retrieve team rosters and player metadata
|
|
9
|
+
- Query league scoreboards for a specific date
|
|
10
|
+
- Wraps ESPN public API endpoints with Ruby objects
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's `Gemfile`:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'espn_pub'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then run:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bundle install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or install directly with:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install espn_pub
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Requirements
|
|
33
|
+
|
|
34
|
+
- Ruby `>= 3.3.0`
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
Require the gem and instantiate entities directly:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
require 'espn_pub'
|
|
42
|
+
|
|
43
|
+
league = EspnPub::Entities::League.new(EspnPub::Entities::League::NAME::NBA)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Fetch teams for a league
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
teams = league.teams
|
|
50
|
+
puts teams.map(&:name)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Fetch a team's roster
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
team = teams.first
|
|
57
|
+
players = team.players
|
|
58
|
+
players.each do |player|
|
|
59
|
+
puts "#{player.full_name} (#{player.position})"
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Fetch games for a league
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
require 'date'
|
|
67
|
+
|
|
68
|
+
games = league.games(date: Date.today)
|
|
69
|
+
games.each do |game|
|
|
70
|
+
puts "Game ID: #{game.id} | Home: #{game.home_team_id} | Away: #{game.away_team_id} | Date: #{game.date}"
|
|
71
|
+
end
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Use the raw client directly
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
client = EspnPub::Client.new(
|
|
78
|
+
base_uri: EspnPub::Client::BASE_URI,
|
|
79
|
+
version: EspnPub::Client::API_VERSION
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
response = client.send_request('/apis/site/v2/sports/basketball/nba/teams')
|
|
83
|
+
puts response['sports'][0]['leagues'][0]['teams'].map { |team| team.dig('team', 'name') }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Error handling
|
|
87
|
+
|
|
88
|
+
The client raises `EspnPub::Client::UnexpectedResponseCodeError` when the API response status is not `200`.
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
begin
|
|
92
|
+
client.send_request('/invalid/path')
|
|
93
|
+
rescue EspnPub::Client::UnexpectedResponseCodeError => e
|
|
94
|
+
warn "API request failed: #{e.message}"
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
Clone the repository and install development dependencies:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
git clone https://github.com/bowmanje/espn-pub-rb.git
|
|
104
|
+
cd espn-pub-rb
|
|
105
|
+
bundle install
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Run the test suite with:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
bundle exec rspec
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
`espn_pub` is licensed under the MIT License.
|
data/espn_pub.gemspec
CHANGED
|
@@ -14,7 +14,8 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.required_ruby_version = '>= 3.3.0'
|
|
15
15
|
spec.metadata = {
|
|
16
16
|
'homepage_uri' => spec.homepage,
|
|
17
|
-
'source_code_uri' => spec.homepage
|
|
17
|
+
'source_code_uri' => spec.homepage,
|
|
18
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/espn_pub'
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
spec.files = Dir.glob('{lib,sig}/**/*', File::FNM_DOTMATCH)
|
|
@@ -22,10 +23,10 @@ Gem::Specification.new do |spec|
|
|
|
22
23
|
%w[espn_pub.gemspec README.md]
|
|
23
24
|
|
|
24
25
|
spec.require_paths = ['lib']
|
|
26
|
+
spec.add_dependency 'date', '~> 3.3'
|
|
25
27
|
spec.add_dependency 'json', '~> 2.6'
|
|
26
28
|
spec.add_dependency 'net-http', '~> 0.3'
|
|
27
29
|
spec.add_dependency 'uri', '~> 0.11'
|
|
28
|
-
spec.add_dependency 'date', '~> 3.3'
|
|
29
30
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
30
31
|
spec.add_development_dependency 'rspec', '~> 3.13'
|
|
31
32
|
spec.add_development_dependency 'rubocop', '~> 1.65'
|
data/lib/espn_pub/client.rb
CHANGED
|
@@ -18,7 +18,7 @@ module EspnPub
|
|
|
18
18
|
#
|
|
19
19
|
# @param base_uri [String] The base URI for ESPN API requests.
|
|
20
20
|
# @param version [String] The API version string.
|
|
21
|
-
def initialize(base_uri
|
|
21
|
+
def initialize(base_uri: BASE_URI, version: API_VERSION)
|
|
22
22
|
@uri = get_uri(base_uri)
|
|
23
23
|
@version = version
|
|
24
24
|
end
|
|
@@ -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
|
|
@@ -4,21 +4,21 @@ module EspnPub
|
|
|
4
4
|
module Entities
|
|
5
5
|
# Represents a game between two teams.
|
|
6
6
|
class Game < Base
|
|
7
|
-
attr_reader :id, :
|
|
7
|
+
attr_reader :id, :home_team, :away_team, :date
|
|
8
8
|
|
|
9
9
|
# Initialize a Game entity.
|
|
10
10
|
#
|
|
11
11
|
# @param id [String] The game identifier.
|
|
12
|
-
# @param
|
|
13
|
-
# @param
|
|
12
|
+
# @param home_team [EspnPub::Entities::Team] The home team.
|
|
13
|
+
# @param away_team [EspnPub::Entities::Team] The away team.
|
|
14
14
|
# @param date [DateTime] The scheduled game date.
|
|
15
|
-
def initialize(id:,
|
|
15
|
+
def initialize(id:, home_team:, away_team:, date:)
|
|
16
16
|
@id = id
|
|
17
|
-
@
|
|
18
|
-
@
|
|
17
|
+
@home_team = home_team
|
|
18
|
+
@away_team = away_team
|
|
19
19
|
@date = date
|
|
20
20
|
super()
|
|
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,
|
|
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,22 +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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
)
|
|
80
83
|
end
|
|
84
|
+
rescue Client::UnexpectedResponseCodeError => e
|
|
85
|
+
warn "Failed to fetch games for league #{name}: #{e.message}"
|
|
86
|
+
[]
|
|
81
87
|
end
|
|
82
88
|
|
|
83
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
|
-
|
|
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
|
-
@full_name ||= first_name
|
|
101
|
+
@full_name ||= "#{first_name} #{last_name}"
|
|
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
|
|
40
114
|
end
|
|
41
115
|
end
|
|
42
116
|
end
|
|
43
|
-
end
|
|
117
|
+
end
|
|
@@ -4,7 +4,7 @@ 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
|
-
|
|
7
|
+
TEAM_PATH = '/apis/site/%s/sports/%s/%s/teams/%s'
|
|
8
8
|
ROSTER_PATH = '/apis/site/%s/sports/%s/%s/teams/%s/roster'
|
|
9
9
|
|
|
10
10
|
attr_reader :id,
|
|
@@ -12,7 +12,8 @@ module EspnPub
|
|
|
12
12
|
:location,
|
|
13
13
|
:abbreviation,
|
|
14
14
|
:sport,
|
|
15
|
-
:league
|
|
15
|
+
:league,
|
|
16
|
+
:venue
|
|
16
17
|
|
|
17
18
|
# Initialize a Team entity.
|
|
18
19
|
#
|
|
@@ -22,16 +23,41 @@ module EspnPub
|
|
|
22
23
|
# @param abbreviation [String] The team abbreviation.
|
|
23
24
|
# @param sport [String] The sport name.
|
|
24
25
|
# @param league [String] The league identifier.
|
|
25
|
-
|
|
26
|
+
# @param venue [EspnPub::Entities::Venue, nil] The team's home venue.
|
|
27
|
+
def initialize(id:, name:, location:, abbreviation:, sport:, league:, venue: nil)
|
|
26
28
|
@id = id
|
|
27
29
|
@name = name
|
|
28
30
|
@location = location
|
|
29
31
|
@abbreviation = abbreviation
|
|
30
32
|
@sport = sport
|
|
31
33
|
@league = league
|
|
34
|
+
@venue = venue
|
|
32
35
|
super()
|
|
33
36
|
end
|
|
34
37
|
|
|
38
|
+
def self.fetch_by_id(id:, sport:, league:)
|
|
39
|
+
client = EspnPub::Client.new
|
|
40
|
+
path = format TEAM_PATH, client.version, sport, league, id
|
|
41
|
+
begin
|
|
42
|
+
team_data = client.send_request(path)['team']
|
|
43
|
+
rescue Client::UnexpectedResponseCodeError => e
|
|
44
|
+
warn "Failed to fetch team data for #{id}: #{e.message}"
|
|
45
|
+
return nil
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
return nil unless team_data
|
|
49
|
+
|
|
50
|
+
new(
|
|
51
|
+
id: team_data['id'],
|
|
52
|
+
name: team_data['name'],
|
|
53
|
+
location: team_data['location'],
|
|
54
|
+
abbreviation: team_data['abbreviation'],
|
|
55
|
+
sport: sport,
|
|
56
|
+
league: league,
|
|
57
|
+
venue: EspnPub::Entities::Venue.from_api(team_data.dig('franchise', 'venue'))
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
35
61
|
# Fetch the roster for this team.
|
|
36
62
|
#
|
|
37
63
|
# @return [Array<EspnPub::Entities::Player>]
|
|
@@ -40,15 +66,22 @@ module EspnPub
|
|
|
40
66
|
begin
|
|
41
67
|
path = format ROSTER_PATH, client.version, sport, league, id
|
|
42
68
|
roster_resp = client.send_request(path)
|
|
43
|
-
@roster = (roster_resp
|
|
44
|
-
|
|
69
|
+
@roster = (roster_resp['athletes'] || []).map do |athlete_data|
|
|
70
|
+
EspnPub::Entities::Player.new(
|
|
45
71
|
id: athlete_data['id'],
|
|
46
72
|
sport: sport,
|
|
47
73
|
league: league,
|
|
48
74
|
first_name: athlete_data['firstName'],
|
|
49
75
|
last_name: athlete_data['lastName'],
|
|
50
76
|
position: athlete_data['position']['abbreviation'],
|
|
51
|
-
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']
|
|
52
85
|
)
|
|
53
86
|
end
|
|
54
87
|
rescue Client::UnexpectedResponseCodeError => e
|
|
@@ -59,6 +92,13 @@ module EspnPub
|
|
|
59
92
|
|
|
60
93
|
@roster
|
|
61
94
|
end
|
|
95
|
+
|
|
96
|
+
# Return the team's full name.
|
|
97
|
+
#
|
|
98
|
+
# @return [String] The team's full name.
|
|
99
|
+
def full_name
|
|
100
|
+
@full_name ||= "#{location} #{name}"
|
|
101
|
+
end
|
|
62
102
|
end
|
|
63
103
|
end
|
|
64
|
-
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
|
data/lib/espn_pub/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2026-09-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: date
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
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: '
|
|
26
|
+
version: '3.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: json
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
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: '
|
|
40
|
+
version: '2.6'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
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.
|
|
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.
|
|
54
|
+
version: '0.3'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: uri
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
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: '
|
|
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:
|
|
@@ -160,6 +161,7 @@ licenses:
|
|
|
160
161
|
metadata:
|
|
161
162
|
homepage_uri: https://github.com/bowmanje/espn-pub-rb
|
|
162
163
|
source_code_uri: https://github.com/bowmanje/espn-pub-rb
|
|
164
|
+
documentation_uri: https://www.rubydoc.info/gems/espn_pub
|
|
163
165
|
post_install_message:
|
|
164
166
|
rdoc_options: []
|
|
165
167
|
require_paths:
|