jazzsequence / games-collector

A WordPress plugin to catalog all your tabletop (or other) games in your WordPress site and display a list of games in your collection.
GNU General Public License v3.0
1 stars 0 forks source link

Integrate BGG API #29

Closed jazzsequence closed 6 years ago

jazzsequence commented 7 years ago

https://www.boardgamegeek.com/xmlapi2

Can automatically pull data based on search into game

jazzsequence commented 7 years ago

Example game: https://www.boardgamegeek.com/xmlapi2/thing?id=3076

The mechanic for pulling a game is not ideal. First you need to run a search for the game, e.g. https://www.boardgamegeek.com/xmlapi2/search?query=puerto+rico&type=boardgame&exact=1

This does not return the game, just the game ID matching the query. A second query needs to be done in order to actually pull the game data.

If a BGG url is used in the more information link like the placeholder text suggests, we can extract this from the URL, e.g. https://boardgamegeek.com/boardgame/3076/puerto-rico

The game ID from the above url is 3076. This is easy-peasy. Less easy is if someone wanted to use a different URL. It's possible we could suggest using BGG exclusively and not fetch information from BGG if a non BGG URL was given. It's also possible we could try to hook into some other API (like Amazon or something) as a fallback if we couldn't find anything. However that's not likely to have the specific data points we want (play time, min/max players, min age), that would just give us the image which we're not using right now anyway. Probably the best solution if a BGG URL isn't given is to just do the search.

Interestingly, nowhere in the XML response for a specific game by ID is the actual URL of the game on BGG. You would need to construct that manually from the ID. This would be dangerous if not for the fact that https://boardgamegeek.com/boardgame/3076/ works just as well as https://boardgamegeek.com/boardgame/3076/puerto-rico to pull up the correct game -- so a game URL can just be boardgamegeek.com/{game_id}/, which is good for us.

For implementation, my thought is:

Major downside to this interface is the time it will take to hit the BGG API. It's not fast. We can cache what data we have but there's not much that we can cache since we're doing this per game anyway and once we have the data we need, we're never going to hit their API again.