Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
egnor opened this issue Jan 8, 2024 · 4 comments
Open

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

egnor opened this issue Jan 8, 2024 · 4 comments

Comments

@egnor
Copy link
Contributor

egnor commented Jan 8, 2024

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.)

@ebroder
Copy link
Member

ebroder commented Jan 8, 2024

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.

@egnor
Copy link
Contributor Author

egnor commented Jan 11, 2024

@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?

@ebroder
Copy link
Member

ebroder commented Jan 11, 2024

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.

@jpd236
Copy link
Contributor

jpd236 commented Nov 27, 2024

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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants