rusty_hyrule_compendium

Crates.iorusty_hyrule_compendium
lib.rsrusty_hyrule_compendium
version0.1.3
sourcesrc
created_at2022-11-11 18:53:05.80494
updated_at2022-11-12 10:33:44.848349
descriptionA rust library for the Hyrule Compendium API
homepage
repositoryhttps://github.com/Alastair-smith2/rusty_hyrule_compendium
max_upload_size
id712995
size40,855
Alastair Smith (Alastair-smith2)

documentation

https://docs.rs/rusty_hyrule_compendium

README

Rusty Hyrule Compendium

A library for consuming the Hyrule Compendium API in Rust

MIT licensed

Overview

This library exposes a client that can be used to request information from the API

Examples

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.

Singular entry by identifer

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

All entries for a given category

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(())
}

All entries in compendium

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(())
}

Available resources from the API

  • Monsters (standard and master mode ones)
  • Creatures
  • Equipment
  • Materials
  • Treasure
Commit count: 15

cargo fmt