jolly-roger icon indicating copy to clipboard operation
jolly-roger copied to clipboard

Feature request: Simple REST(?) API for adding puzzles

Open egnor opened this issue 2 years ago • 4 comments

We have users (@dougz) who like to write little scrapers to auto-populate our solving aids from the Hunt site. In recent years, Hunt site runners have been offering puzzle lists in JSON or otherwise machine-readable format which is amazing!

To make this easier to do it would be neat to have some very simple interface which scripts could use to add puzzles. (And maybe enumerate existing puzzles, so they could check for dupes.)

egnor avatar Jan 08 '24 07:01 egnor

Huh, I don't think I had realized there was a JSON dump. We've had an open ticket (#237) to build this kind of scraping into Jolly Roger for ages, but I'd also be pretty open to exposing an API for external scripting.

We do have some basic REST API structure. Right now it exists to allow a third-party team website to use Jolly Roger as an authz source, but it shouldn't be terribly hard to extend. Some basic notes on how it works (since we should - but don't currently - have any docs):

  • You can grab your API key by running await Meteor.callAsync('fetchAPIKey', {}) in the console. There's also a rollAPIKey that does what it sounds like.
  • The API lives under /api and takes HTTP Bearer auth.
  • The code for the API starts in /imports/server/api-init.ts and threads through from there.

ebroder avatar Jan 08 '24 07:01 ebroder

@ebroder (get your barf bag out) as a stopgap, would just adding an entry to the database do the right thing as far as adding a puzzle? (obviously very brittle and to be replaced with a proper API in future) or is there enough denormalized content around puzzle creation (not to mention sheet creation, etc) that it would be way too hard?

egnor avatar Jan 11 '24 02:01 egnor

Hmm. It might work? I definitely wouldn't recommend it. Main thing I'll note is to make sure you get the types right (although the database schema should enforce it). I think the main functionality you'll lose is the ability to create puzzles with Google Docs instead of Sheets - may not be important to you but we tend to use it for meta-hunt things.

If you really want to hack something together, I might try to find a standalone DDP client (a la https://github.com/Gregivy/simpleddp) and invoke the Meteor methods that way.

ebroder avatar Jan 11 '24 03:01 ebroder

FYI, https://github.com/jpd236/jolly-roger/tree/add-puzzle-api is an initial pass at a proper API for adding puzzles. There are also APIs to list hunts and tags for a hunt to complete the picture. I didn't add an API to list puzzles for dupe checks, but this branch is built atop https://github.com/deathandmayhem/jolly-roger/pull/2313 which attempts to detect duplicate puzzles on addition, so that should be handled.

I plan to send this as a PR once we've aligned on the approach to deduping (which I imagine won't happen until after this year's hunt), but maybe it'll be useful if you want something for this year. No promises it doesn't have weird bugs as it's wholly unreviewed.

jpd236 avatar Nov 27 '24 05:11 jpd236