destiny_rs

Crates.iodestiny_rs
lib.rsdestiny_rs
version0.1.1
sourcesrc
created_at2021-04-01 13:28:47.006541
updated_at2021-04-02 07:26:21.734615
descriptionAn async library to interact with Bungie's destiny 2 api.
homepage
repositoryhttps://github.com/zeskeertwee/destiny-rs
max_upload_size
id376635
size96,878
zeskeertwee (zeskeertwee)

documentation

README

Destiny-rs

license docs

A library for interacting with Bungie's destiny 2 api, and manifest

A simple example that looks up someone's characters with their bungie.net id, and queries the manifest multiple times:

use destiny_rs::models::{api::DestinyAPI, locale::Locale, membership::MembershipType, manifest::ManifestKey, manifest_models};
use destiny_rs::traits::id::DestinyMembershipID;
use tokio;
use std::env;
use std::path::PathBuf;

#[tokio::main]
pub async fn main() {
    let api = DestinyAPI::new(&env::var("API_KEY").unwrap());

    let mut manifest_path = PathBuf::new();
    manifest_path.push("./manifest");

    let manifest = api.manifest(manifest_path, Locale::English).await.unwrap();
    
    let user = api.get_user_membership_data_by_membershipid_bng(&19377351,  &MembershipType::Steam).await.unwrap();
    let characters = user.get_characters(&api, &MembershipType::Steam).await.unwrap();

    println!("{}'s characters:", user.bungie_net_user.display_name);
    for character in characters {
        // these don't do any api calls, they just query the downloaded manifest
        let race: manifest_models::Race = manifest.query(character.race_hash, ManifestKey::Race).unwrap();
        let gender: manifest_models::Gender = manifest.query(character.gender_hash, ManifestKey::Gender).unwrap();
        let class: manifest_models::Class = manifest.query(character.class_hash, ManifestKey::Class).unwrap();

        println!(
            "{} {} {} is power level {}",
            gender.display_properties.name,
            race.display_properties.name,
            class.display_properties.name,
            character.stats.power,
        );
    }
}
Commit count: 59

cargo fmt