Plugin: rewire apple_api.py to the gateway #13

Closed
opened 2026-08-09 20:31:47 +00:00 by hermes · 1 comment
Owner

Context

Plugin rework (see #18). apple_api.py becomes a client of the gateway
instead of Apple; the response shape is fixed by the gateway API (#7) so
the parsing barely changes.

Task

In /opt/data/git/git.sams.wtf/coop/beets-appleplaylists:

  • AppleAPIClient(service_url: str, service_token: str, session=None) with
    Authorization: Bearer <service_token> on all requests
  • base path {service_url}/api/v1; endpoints /playlists and
    /playlists/{id}/tracks (match the gateway's JSON field names exactly:
    title, artist, album, isrc, track_number)
  • keep the ApplePlaylist/AppleTrack dataclasses and the track-extraction
    logic identical so matching.py/sync.py are untouched
  • 401/403 from the gateway -> AppleAPIError with the message
    "Apple Music gateway login required: run 'beet apple login' or visit
    {service_url}/login"
  • keep network-error handling (requests exceptions -> sanitized
    AppleAPIError)

Acceptance criteria

  • tests/test_apple_api.py updated to the FakeSession pattern asserting
    the request host is {service_url}/api/v1/... and the bearer header is
    sent; tests pass.
  • sync.py, matching.py, isrc.py unchanged by this issue.
## Context Plugin rework (see #18). `apple_api.py` becomes a client of the gateway instead of Apple; the response shape is fixed by the gateway API (#7) so the parsing barely changes. ## Task In `/opt/data/git/git.sams.wtf/coop/beets-appleplaylists`: - `AppleAPIClient(service_url: str, service_token: str, session=None)` with `Authorization: Bearer <service_token>` on all requests - base path `{service_url}/api/v1`; endpoints `/playlists` and `/playlists/{id}/tracks` (match the gateway's JSON field names exactly: `title`, `artist`, `album`, `isrc`, `track_number`) - keep the `ApplePlaylist`/`AppleTrack` dataclasses and the track-extraction logic identical so `matching.py`/`sync.py` are untouched - 401/403 from the gateway -> `AppleAPIError` with the message "Apple Music gateway login required: run 'beet apple login' or visit {service_url}/login" - keep network-error handling (requests exceptions -> sanitized `AppleAPIError`) ## Acceptance criteria - `tests/test_apple_api.py` updated to the FakeSession pattern asserting the request host is `{service_url}/api/v1/...` and the bearer header is sent; tests pass. - `sync.py`, `matching.py`, `isrc.py` unchanged by this issue.
Author
Owner

Implemented in coop/beets-appleplaylists commit b5a121c8c728bcf218e5e4561bed603e01e82b44. AppleAPIClient(service_url, service_token, session=None) now targets {service_url}/api/v1/playlists and /playlists/{id}/tracks, sends the bearer header through the session, maps the gateway's flat track fields, and converts 401/403 and request failures to sanitized AppleAPIError messages.

tests/test_apple_api.py covers endpoint URLs, bearer auth, response mapping, 401/403 login hints, network failures, and server failures.

Implemented in `coop/beets-appleplaylists` commit `b5a121c8c728bcf218e5e4561bed603e01e82b44`. `AppleAPIClient(service_url, service_token, session=None)` now targets `{service_url}/api/v1/playlists` and `/playlists/{id}/tracks`, sends the bearer header through the session, maps the gateway's flat track fields, and converts 401/403 and request failures to sanitized `AppleAPIError` messages. `tests/test_apple_api.py` covers endpoint URLs, bearer auth, response mapping, 401/403 login hints, network failures, and server failures.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
coop/beets-appleplaylists#13
No description provided.