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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0375caa5f944f2f083cdc8cec7672f44fc9219969e8e733bde441c377e16ede4
4
- data.tar.gz: a1d54df90f2ff3ba533d11756993513eca6bae884f1a1fc0e57e51d9be84fa12
3
+ metadata.gz: 764f1f24badfe4fbb8f017956f376a7e5604561d4d386e01a2ca77cf2174ddb8
4
+ data.tar.gz: 2616db091ddd38b8e942dce78929f8e56e2ad75de4e0bc5b5b5d52b7697bbddd
5
5
  SHA512:
6
- metadata.gz: ba5338528abf3a7c924dd9fdfd7dbf6440a1ac75debc3426cca4d580520a65ce7986075c2d8a6709305a5e57720c08a9b0749710e83b46381628b2991bab702b
7
- data.tar.gz: 84ff6c0503398ca629009b1976dfd2ead6a9594d63eabdf97fb0056ed29d3b4965e8f2a4d17091c1e6d02560c1b28f469afeffeacaccc36acb7b394c3415dc2a
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SleeperApi
4
- VERSION = "1.6.0"
4
+ VERSION = "1.7.0"
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeper_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eruity1