Skip to content

Alastair-smith2/rusty_hyrule_compendium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A rust library for consuming the Hyrule Compendium API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages