espn_pub 0.1.0 → 0.1.2

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: 4dee5305666108de85913d5ef82a426b3e43c7c011833c4f9f0be06d9ebb6ae6
4
- data.tar.gz: aa60cb29dbfe5abba1e77b75bc96fe4b4bb6cb90c00318ff59934b5171528898
3
+ metadata.gz: 4bce533b327d0ad217ebdce3abf887f7960ddc5c275a93063aae8df8918af0af
4
+ data.tar.gz: cc6468fbbcdc9f8d27fdaf8481bb2f9b9591266c700f10f18ac0708f038cd0eb
5
5
  SHA512:
6
- metadata.gz: ca5aeb78fe7c56960d27a55e58e4763652527dece17663cf02e5847fd73349f9aa7d1293db8d8b7751c0d250d3a4b065ee1c3e98a8774f73719829fd1a36e87a
7
- data.tar.gz: a5dc7c9b283be22e3d2813955e122fd0916a9fec69821f551016957a139ce55f1fd55b6cbb745773857b4f1216ed5d49080200472102c6360e4bc4aa6b26ab6f
6
+ metadata.gz: 84196f6df201cfacf81b1239506694468d570a46e98c31f41c08e0dcf4c2b1ef8a757e7185d35c4e1478d2673f1ecd330942b62e3d2e176e312bbf062036246e
7
+ data.tar.gz: 7f8534155c22dcee1271fc9357254f636325c7dab6bf6528360bb4bae6f4f522a9fcabf974984b61cfc8d59c29223b394d10b4aa40ec2157251c864a9e4513d3
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)
@@ -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:, version:)
21
+ def initialize(base_uri: BASE_URI, version: API_VERSION)
22
22
  @uri = get_uri(base_uri)
23
23
  @version = version
24
24
  end
@@ -4,18 +4,18 @@ module EspnPub
4
4
  module Entities
5
5
  # Represents a game between two teams.
6
6
  class Game < Base
7
- attr_reader :id, :home_team_id, :away_team_id, :date
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 home_team_id [String] The home team identifier.
13
- # @param away_team_id [String] The away team identifier.
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:, home_team_id:, away_team_id:, date:)
15
+ def initialize(id:, home_team:, away_team:, date:)
16
16
  @id = id
17
- @home_team_id = home_team_id
18
- @away_team_id = away_team_id
17
+ @home_team = home_team
18
+ @away_team = away_team
19
19
  @date = date
20
20
  super()
21
21
  end
@@ -69,8 +69,16 @@ module EspnPub
69
69
  (games_resp.dig('events') || []).map do |game_data|
70
70
  EspnPub::Entities::Game.new(
71
71
  id: game_data['id'],
72
- home_team_id: game_data.dig('competitions', 0, 'competitors', 0, 'id'),
73
- away_team_id: game_data.dig('competitions', 0, 'competitors', 1, '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
+ ),
74
82
  date: DateTime.parse(game_data['date'])
75
83
  )
76
84
  end
@@ -36,7 +36,7 @@ module EspnPub
36
36
  #
37
37
  # @return [String] The player's full name.
38
38
  def full_name
39
- @full_name ||= first_name + ' ' + last_name
39
+ @full_name ||= "#{first_name} #{last_name}"
40
40
  end
41
41
  end
42
42
  end
@@ -5,6 +5,7 @@ module EspnPub
5
5
  # Represents a sports team, eg. Miami Heat, New England Patriots, etc.
6
6
  class Team < Base
7
7
 
8
+ TEAM_PATH = '/apis/site/%s/sports/%s/%s/teams/%s'
8
9
  ROSTER_PATH = '/apis/site/%s/sports/%s/%s/teams/%s/roster'
9
10
 
10
11
  attr_reader :id,
@@ -32,6 +33,28 @@ module EspnPub
32
33
  super()
33
34
  end
34
35
 
36
+ def self.fetch_by_id(id:, sport:, league:)
37
+ client = EspnPub::Client.new
38
+ path = format TEAM_PATH, client.version, sport, league, id
39
+ begin
40
+ team_data = client.send_request(path).dig('team')
41
+ rescue Client::UnexpectedResponseCodeError => e
42
+ warn "Failed to fetch team data for #{id}: #{e.message}"
43
+ return nil
44
+ end
45
+
46
+ return nil unless team_data
47
+
48
+ new(
49
+ id: team_data['id'],
50
+ name: team_data['name'],
51
+ location: team_data['location'],
52
+ abbreviation: team_data['abbreviation'],
53
+ sport: sport,
54
+ league: league
55
+ )
56
+ end
57
+
35
58
  # Fetch the roster for this team.
36
59
  #
37
60
  # @return [Array<EspnPub::Entities::Player>]
@@ -59,6 +82,13 @@ module EspnPub
59
82
 
60
83
  @roster
61
84
  end
85
+
86
+ # Return the team's full name.
87
+ #
88
+ # @return [String] The team's full name.
89
+ def full_name
90
+ @full_name ||= "#{location} #{name}"
91
+ end
62
92
  end
63
93
  end
64
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EspnPub
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espn_pub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
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-18 00:00:00.000000000 Z
11
+ date: 2026-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -160,6 +160,7 @@ licenses:
160
160
  metadata:
161
161
  homepage_uri: https://github.com/bowmanje/espn-pub-rb
162
162
  source_code_uri: https://github.com/bowmanje/espn-pub-rb
163
+ documentation_uri: https://www.rubydoc.info/gems/espn_pub
163
164
  post_install_message:
164
165
  rdoc_options: []
165
166
  require_paths: