discourse/plugins/discourse-patreon/lib/api_version
Rafael dos Santos Silva bbc2fed22b
FIX: Patreon API pagination bugs causing missing pledges (#39058)
## Summary

- **Nil patron data crash**: Patreon V1 API can return pledge entries
where `relationships.patron.data` is null (deleted/deactivated
accounts). This caused `extract` to raise `NoMethodError`, preventing
`save!` from completing — leaving the pledge store stuck at stale data
(exactly 100 pledges from a previous sync). Fixed with `dig` for safe
nil traversal, skipping entries with missing IDs.
- **Double base URL**: Pagination `next` links from Patreon are absolute
URLs, but `Api.get` was prepending the base URL again
(`https://api.patreon.comhttps://api.patreon.com/...`). Fixed by
detecting absolute URIs and using them directly.
- **Non-incremental saves**: All pages were collected before a single
`save!`. If any page failed, nothing was persisted. Now each page is
saved incrementally — first page clears stale data, subsequent pages
append. Also handles the edge case where the API returns empty data by
explicitly clearing the store so ex-patrons don't keep group access.
2026-04-01 17:18:51 -03:00
..
v1.rb
v2.rb