#bungie #destiny #api-bindings

destiny_rs

一个异步库,用于与Bungie的destiny 2 API交互

2个版本

0.1.1 2021年4月2日
0.1.0 2021年4月1日

#1268 in 文本处理

MIT许可协议

96KB
2.5K SLoC

Destiny-rs

license docs

一个用于与Bungie的destiny 2 API和清单交互的库

一个简单的示例,通过bungie.net ID查找某人的角色,并多次查询清单

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,
        );
    }
}

依赖项

~9–24MB
~333K SLoC