2 个版本
0.1.1 | 2023 年 5 月 5 日 |
---|---|
0.1.0 | 2023 年 5 月 5 日 |
#9 in #riot-games
47KB
476 行
Aurilion - Rust 库,简化与 Data Dragon 的交互
Aurilion 是一个小型 Rust 库,提供一些有用的函数,以帮助简化对 Riot Games Data Dragon 网页 API 的访问。
用法
通过将库添加到您的项目开始。
cargo add aurilion
获取数据
撰写本文时,只包含四个函数
get_versions()
- 获取所有补丁版本。get_all_champions()
- 获取所有可用英雄的简要信息。get_single_champion()
- 获取单个英雄的详细信息。get_all_items()
- 获取所有物品的详细信息。
示例
所有函数的示例实现可能如下所示
async fn do_everything() {
// get all versions
let versions = get_versions().await.unwrap();
//The first version in the list is always the latest version
let latest_version = versions.first().unwrap();
// get all champions, this function requires the version you are requesting champions for
let all_champions = get_all_champions(latest_version.clone()).await.unwrap();
/*
do something here with the champions
we cycle through and list out all champion names and their title for now.
*/
all_champions.data.into_iter().for_each(|value| {
println!("{} : {}", value.1.id, value.1.title);
});
let single_champion = get_single_champion("Ahri".to_string(), latest_version.clone())
.await
.unwrap();
// Get the champion from the Map received (must be the same as supplied to get_single_champion())
// In our case, it is "Ahri"
let champion_data = single_champion.data.get("Ahri").unwrap();
// Just print the name of the champions and their skills for now.
println!("\n\n{} Skill Names: ", champion_data.id);
for (num, x) in champion_data.spells.clone().into_iter().enumerate() {
println!("Skill {}: {}", num + 1, x.name)
}
}
依赖项
~6–19MB
~284K SLoC