Crates.io | rusty_hyrule_compendium |
lib.rs | rusty_hyrule_compendium |
version | 0.1.3 |
source | src |
created_at | 2022-11-11 18:53:05.80494 |
updated_at | 2022-11-12 10:33:44.848349 |
description | A rust library for the Hyrule Compendium API |
homepage | |
repository | https://github.com/Alastair-smith2/rusty_hyrule_compendium |
max_upload_size | |
id | 712995 |
size | 40,855 |
A library for consuming the Hyrule Compendium API in Rust
This library exposes a client that can be used to request information from the API
Start by adding the following snippet to your Cargo.toml
[dependencies]
rusty_hyrule_compendium = "0.1.3"
To use this library, you'll need to instantiate the Compendium client. CompendiumClient::default();
preconfigures the underlying HTTP client and API url with sensible values.
use rusty_hyrule_compendium::blocking::{CompendiumApiClient, CompendiumClient};
use rusty_hyrule_compendium::domain::inputs::EntryIdentifier;
use rusty_hyrule_compendium::Result;
fn main() -> Result<()> {
// Preconfigured client using v2 of the API
let client = CompendiumClient::default();
// Requests can fail for a number of reasons, see the error module for available errors
let monster_entry = client.monster(EntryIdentifier::Id(123))?;
// "white-maned lynel"
let monster_name = monster_entry.name();
// "https://botw-compendium.herokuapp.com/api/v2/entry/white-maned_lynel/image"
let monster_image = monster_entry.image();
Ok(())
}
Each of the resources (see below for comprehensive list) have a struct representation with helper methods to the underlying data (e.g. .name()
, .image()
etc)
Here contains the raw JSON response for the example
Furthermore it's possbile to request all of the above by category but pattern matching is required to get the entries.
use rusty_hyrule_compendium::blocking::{CompendiumApiClient, CompendiumClient};
use rusty_hyrule_compendium::domain::inputs::CompendiumCategory;
use rusty_hyrule_compendium::domain::responses::CategoryResult;
use rusty_hyrule_compendium::Result;
fn main() -> Result<()> {
// Preconfigured client using v2 of the API
let client = CompendiumClient::default();
let result = client.category(CompendiumCategory::Treasure)?;
match result {
CategoryResult::Treasure(treasure) => {
// Do something with the Vec<TreasureEntry>
}
_ => { /* Return some form of error, unexpected scenario */}
}
Ok(())
}
It's also possible to get all entries by the .all_entries()
method
E.g.
use rusty_hyrule_compendium::blocking::{CompendiumApiClient, CompendiumClient};
use rusty_hyrule_compendium::Result;
fn main() -> Result<()> {
// Preconfigured client using v2 of the API
let client = CompendiumClient::default();
let all_entries = client.all_entries()?;
// Get all creature entries that are food specific, &Vec<CreatureEntry> type
let food_creatures = all_entries.creatures().food();
Ok(())
}