sleeper_api 1.6.0 → 1.7.0
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/CHANGELOG.md +14 -0
- data/CLAUDE.md +1 -1
- data/README.md +8 -1
- data/lib/sleeper_api/client.rb +20 -1
- data/lib/sleeper_api/version.rb +1 -1
- data/lib/sleeper_api.rb +3 -0
- 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: 764f1f24badfe4fbb8f017956f376a7e5604561d4d386e01a2ca77cf2174ddb8
|
|
4
|
+
data.tar.gz: 2616db091ddd38b8e942dce78929f8e56e2ad75de4e0bc5b5b5d52b7697bbddd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aea41e6b36a4cad02e526d35b0de424a32b20ce59d8d683bf8eccdd366669053c037c7ae6d2be6151031018c06d5b8d717733c8f941d3f9e7ab5bb6feb19cdb9
|
|
7
|
+
data.tar.gz: 2348a7481c68aaab18441ddf0096a02b5a4dc3a409ae7d7d1c90365af6139d1bdc919c62a9c9ab247c973c2bb03a7e989f17167ae3c5d23bdd95c2fc17ccf5a8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.7.0] - 2026-10-02
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- **`Client#player(player_id, sport: "nfl")`** fetches one player from the
|
|
6
|
+
undocumented `/v1/players/{sport}/{id}`: the same fields as a catalog row, in
|
|
7
|
+
about 1.2 KB rather than the 14.6 MB `#get_players` downloads. It is live and
|
|
8
|
+
uncached, so it is the way to read an `injury_status` or `depth_chart_order`
|
|
9
|
+
fresher than a nightly catalog.
|
|
10
|
+
- **`SleeperApi::PlayerNotFound`, a subclass of `SleeperApi::Error`.** An
|
|
11
|
+
unknown player id is a `404`, checked live 2026-10-02, unlike an unknown
|
|
12
|
+
user's `200` and `null`. Any other failure is still a plain
|
|
13
|
+
`SleeperApi::Error`.
|
|
14
|
+
|
|
1
15
|
## [1.6.0] - 2026-09-28
|
|
2
16
|
|
|
3
17
|
### Added
|
data/CLAUDE.md
CHANGED
|
@@ -70,7 +70,7 @@ Four layers, with a deliberate split between HTTP and modeling:
|
|
|
70
70
|
|
|
71
71
|
**Guard nil defensively.** Sleeper omits fields freely — users without `metadata`, rosters without `players`, matchups without `points`. Real leagues hit these; the spec fixtures often don't. Use `&.dig` rather than `[]` on anything nested off an API response.
|
|
72
72
|
|
|
73
|
-
**Never fan out `get_players`.** It's a multi-megabyte payload of every NFL player. It's cached for 24h in an ivar on the client instance — which means the cache dies with the client. Consumers holding a short-lived client re-download it every time.
|
|
73
|
+
**Never fan out `get_players`.** It's a multi-megabyte payload of every NFL player. It's cached for 24h in an ivar on the client instance — which means the cache dies with the client. Consumers holding a short-lived client re-download it every time. For one player, `#player(id)` fetches `/v1/players/nfl/{id}` live (~1.2 KB, undocumented, uncached); an unknown id is a **404** there, not the `200`/`null` an unknown user gets, and becomes `PlayerNotFound`.
|
|
74
74
|
|
|
75
75
|
### Undocumented endpoints carry undocumented vocabularies
|
|
76
76
|
|
data/README.md
CHANGED
|
@@ -243,10 +243,15 @@ Access player data with automatic caching:
|
|
|
243
243
|
# Get all players (cached for 24 hours)
|
|
244
244
|
players = client.get_players
|
|
245
245
|
|
|
246
|
-
# Find specific player
|
|
246
|
+
# Find specific player (reads the cached catalog above)
|
|
247
247
|
player = client.get_player_by_id("1234")
|
|
248
248
|
puts "#{player['first_name']} #{player['last_name']} - #{player['position']}"
|
|
249
249
|
|
|
250
|
+
# One player, live and uncached: ~1.2 KB instead of the whole catalog.
|
|
251
|
+
# Use it for a fresher injury_status or depth_chart_order than the catalog has.
|
|
252
|
+
fresh = client.player("1234")
|
|
253
|
+
puts "#{fresh['injury_status']} (#{fresh['injury_body_part']})"
|
|
254
|
+
|
|
250
255
|
# Get trending players
|
|
251
256
|
trending_adds = client.trending_players(type: "add", limit: 10)
|
|
252
257
|
trending_drops = client.trending_players(type: "drop", limit: 10)
|
|
@@ -370,6 +375,8 @@ end
|
|
|
370
375
|
|
|
371
376
|
- SleeperApi::UserNotFound - a subclass of SleeperApi::Error: no Sleeper user has that identifier. Permanent, so rescue it before SleeperApi::Error if you retry the rest
|
|
372
377
|
|
|
378
|
+
- SleeperApi::PlayerNotFound - a subclass of SleeperApi::Error: `client.player` was given an id Sleeper does not have. Permanent, like UserNotFound
|
|
379
|
+
|
|
373
380
|
- ArgumentError - Invalid parameters passed to methods
|
|
374
381
|
|
|
375
382
|
## Performance Considerations
|
data/lib/sleeper_api/client.rb
CHANGED
|
@@ -472,6 +472,21 @@ module SleeperApi
|
|
|
472
472
|
get_players(sport)[player_id]
|
|
473
473
|
end
|
|
474
474
|
|
|
475
|
+
# Fetch one player, live: about 1.2 KB where #get_players is 14.6 MB, and
|
|
476
|
+
# not cached. Undocumented; same fields as a catalog row.
|
|
477
|
+
#
|
|
478
|
+
# Sleeper answers an unknown id with 404, unlike an unknown user's 200 and
|
|
479
|
+
# null, and that 404 becomes {SleeperApi::PlayerNotFound}.
|
|
480
|
+
#
|
|
481
|
+
# @param player_id [String] Player ID
|
|
482
|
+
# @param sport [String] Sport code (default: "nfl")
|
|
483
|
+
# @return [HTTParty::Response] The player's raw data
|
|
484
|
+
# @raise [SleeperApi::PlayerNotFound] If no player has that ID
|
|
485
|
+
def player(player_id, sport: "nfl")
|
|
486
|
+
make_request(path("v1", "players", sport, player_id),
|
|
487
|
+
not_found: -> { PlayerNotFound.new("No Sleeper player #{player_id.to_s.inspect}") })
|
|
488
|
+
end
|
|
489
|
+
|
|
475
490
|
private
|
|
476
491
|
|
|
477
492
|
# Every request path is built here, from escaped segments. An unescaped
|
|
@@ -503,9 +518,11 @@ module SleeperApi
|
|
|
503
518
|
#
|
|
504
519
|
# @param path [String] API endpoint path
|
|
505
520
|
# @param host [String, nil] a different host, e.g. WEB_HOST
|
|
521
|
+
# @param not_found [Proc, nil] builds the error a 404 raises, for an
|
|
522
|
+
# endpoint where 404 means "no such thing" rather than a failure
|
|
506
523
|
# @return [HTTParty::Response]
|
|
507
524
|
# @raise [SleeperApi::Error] On HTTP errors or timeouts
|
|
508
|
-
def make_request(path, host: nil)
|
|
525
|
+
def make_request(path, host: nil, not_found: nil)
|
|
509
526
|
named = host ? "#{host}#{path}" : path
|
|
510
527
|
options = { timeout: @config.timeout }
|
|
511
528
|
options[:base_uri] = host if host
|
|
@@ -519,6 +536,8 @@ module SleeperApi
|
|
|
519
536
|
response
|
|
520
537
|
else
|
|
521
538
|
@config.logger&.error("Failed to fetch #{named}: #{response.code}")
|
|
539
|
+
raise not_found.call if not_found && response.code == 404
|
|
540
|
+
|
|
522
541
|
raise SleeperApi::Error, "Failed to fetch #{named}: #{response.code}"
|
|
523
542
|
end
|
|
524
543
|
rescue Net::OpenTimeout, Net::ReadTimeout => e
|
data/lib/sleeper_api/version.rb
CHANGED
data/lib/sleeper_api.rb
CHANGED
|
@@ -13,6 +13,9 @@ module SleeperApi
|
|
|
13
13
|
# Error — retrying will not help — so a caller can rescue it on its own.
|
|
14
14
|
class UserNotFound < Error; end
|
|
15
15
|
|
|
16
|
+
# The id names no Sleeper player. Permanent, like UserNotFound.
|
|
17
|
+
class PlayerNotFound < Error; end
|
|
18
|
+
|
|
16
19
|
class << self
|
|
17
20
|
attr_writer :configuration
|
|
18
21
|
end
|