feat: modular league adapters (NBA + WNBA) #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ada/nba-calendar-utility:feat/modular-leagues"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Breaks the monolithic
index.mjsinto swapable modules so you can add new leagues without touching the calendar or config logic.New structure
NBA vs WNBA API differences
The NBA uses a nested
leagueSchedule.gameDates[].games[]structure withhomeTeam/awayTeamobjects. The WNBA uses a flatresults.schedule[]array withhome/visitorobjects. The adapter pattern normalizes both intoGameinstances.Config
The
leaguefield defaults to"nba"for backward compatibility.Adding a league
Implement the adapter interface (see README) and register it in
src/leagues/index.jsand theLEAGUESmap inindex.mjs.Also fixes
https.requestfetch withnode-fetch(already a dependency — the old one returned rawIncomingMessagesores.json()would not have worked)Promise.sleepmonkey-patch with localsleep()throw "string"withthrow new Error()Break the monolithic index.mjs into separate modules: - src/game.js: Normalized Game class with toCalendarEvent() - src/calendar.js: Google auth, clearEvents, saveEvents - src/config.js: readConfig() with league support - src/leagues/nba.js: NBA adapter (cdn.nba.com schedule API) - src/leagues/wnba.js: WNBA adapter (content-api-prod.nba.com) - src/leagues/index.js: Re-exports all adapters The WNBA API has a completely different URL and response shape (flat game list with visitor/home objects) compared to the NBA API (nested gameDates/games with homeTeam/awayTeam). The adapter pattern normalizes both into Game instances so the calendar layer doesn't need to know the difference. Config now supports a 'league' field ('nba' or 'wnba'). The teamCode and year fields work the same way. Adding a new league requires implementing the adapter interface and registering it. Also fixes: replaced custom https.request fetch with node-fetch (the existing dependency), replaced Promise.sleep monkey-patch with local sleep(), replaced bare throw strings with Error objects, added rate limiting on calendar inserts.