Ruza Drive / Guides
Change feed
Keep a tool in sync with a Ruza drive: initial snapshot, cursor, changes applied in order, recovery after a 410 error.
How it works
GET /changes tells everything that happens to the drive: creations, changes, moves, trashing, permanent deletions. Every answer returns an opaque cursor; the next request sends it back and gets what follows. A backup or sync tool never has to walk the whole drive again.
The feed covers the whole account: a key restricted to a folder cannot call it (403 folder_restricted). It needs the drive.files:read permission.
First synchronisation
Without a cursor, the feed starts with a snapshot of the live tree, in pages: every entry comes as upserted. While has_more is true, call again with the cursor received. When has_more turns false, your copy is complete: keep that last cursor, it marks where to resume.
Applying changes
upserted: the entry exists; create or update it fromentry(name, parent folder, size, date, revision; for a file,version_idandcontent_hash).trashed: the entry went to the trash, with everything inside if it is a folder.purged: the entry is permanently deleted;entryis absent.
Apply changes in seq order. A move is an upserted whose parent_id changed, a rename an upserted whose name changed. revision grows with every change: ignore a state older than the one you hold.
Then poll the feed at your own pace, every minute for instance. An answer without changes is light, but counts as one request in the rate limits.
Starting from now
GET /changes/cursor returns a cursor at the head of the journal, without a snapshot: to react to what happens from now on without copying what exists.
Starting again after a 410
The journal does not go back forever. Two 410 answers ask to start again without a cursor:
resync_required: your cursor is older than the journal. Take a new snapshot and compare it with your copy.restored: the drive's catalogue was restored from a backup. Take a new snapshot, and delete nothing on your side that the server lacks: the server may be the one that lost something.
Complete example
A complete sync loop, the key read from an environment variable. loadCursor, saveCursor and apply are yours to write.