Crates.io | rbgg |
lib.rs | rbgg |
version | 0.1.1 |
source | src |
created_at | 2023-12-05 19:22:42.255198 |
updated_at | 2023-12-05 19:31:14.736481 |
description | A simple Rust library that will fetch the BGG data using the APIs defined on boardgamegeek.com (https://boardgamegeek.com/wiki/page/BGG_XML_API). This will take input queries and return JSON responses. |
homepage | https://github.com/crustymonkey/rbgg |
repository | https://github.com/crustymonkey/rbgg |
max_upload_size | |
id | 1058958 |
size | 71,772 |
This is a library that allows you to conveniently use the boardgamegeek.com APIs. This is a pretty thin wrapper over the APIs, so with the documentation on BGG's site and the docs here, you should be able to get up and running quickly.
API version 1: https://boardgamegeek.com/wiki/page/BGG_XML_API
API version 2: https://boardgamegeek.com/wiki/page/BGG_XML_API2
The basics of this library are pretty simple. You make a call that matches up with the API, like search after creating a client and you get a serde_json::Value response that contains the converted XML.
The other items to be aware of in this library is that async
calls are the
default, but blocking calls are supported by simply appending "_b" to the end
of the method name.
For example, if you want to call the search()
method, here are the ways
in which you would do this.
use rbgg::bgg2::*;
// There's also a Client2::new() that allows you to change root url and
// API path, but unless you have some specfic use case, you want to use
// the defaults.
let client = Client2::new_from_defaults();
// Calling the search function async. I'll note that all results, both async
// and sync, will be `Result<Value>`
let result = client.search("bruges", &vec![Search::BoardGame], None).await?;
// Similarly, calling it using a blocking call
let result = client.search_b("bruges", &vec![Search::BoardGame], None)?;
While API v1 tracks pretty much exactly the documentation on BGG's site and, technically, so does API v2, but with some additional convenience methods.
For example, the thing API allows you to specify IDs
and one or more things to get. While you're welcome to use that raw API, each
of the "things" has it's own direct call. Here are a couple of examples,
first using the direct thing API, then the boardgame()
convenience method.
use rbgg::{bgg2::*, utils::Params};
let client = Client2::new_from_defaults();
// You can set any of the parameters for the call using the `Params` in the
// utils lib.
let params = Params::from([
("comments".into(), "1".into()),
("stats".into(), "1".into()),
]);
// You can retrieve more than 1 item at a time
let game_ids = vec![136888, 133473];
let ttypes = vec![Thing::BoardGame];
// We'll use the blocking call in this example
let res = client.thing_b(&game_ids, &ttypes, Some(params));
// Alternatively, you can implicitly just use the "thing" type of boardgame.
// Here is the same call with the convenience function.
let res = client.boardgame_b(&game_ids, Some(params));
There are similar methods for all of the family items as well.
Beyond that, you are pretty much just following what the docs say on BGG's site as that's what the library implements. Happy gaming!
{
"error": {
"message": "Rate limit exceeded."
}
}