8 个不稳定版本 (3 个破坏性更新)
0.4.2 | 2024年8月4日 |
---|---|
0.4.1 | 2024年8月4日 |
0.3.1 | 2024年7月25日 |
0.2.0 | 2024年7月24日 |
0.1.1 | 2024年7月22日 |
#1 in #client-instance
689 每月下载量
40KB
988 代码行
Smite-rs
Smite-rs 是一个用于与 Smite API 交互的 Rust 库。它设计得易于使用,并提供了一个简单的接口来与 API 交互。
快速入门
为了使用 Smite API,您需要从 Hi-Rez 开发者门户 获取 dev-id 和 auth-key。一旦获得,您就可以使用它来创建一个新的 Client
实例并开始进行请求。
use smite::client::Client;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new("my-dev-id".to_string(), "my-auth-key".to_string());
let player_name = "player-name";
// API may return multiple players with the same name
let player_info = &client.get_player(player_name).await?[0];
println!(
"Player {player_name} played for {} hours.",
player_info.hours_played
);
Ok(())
}
自定义请求
某些端点尚未由库完全支持。在这种情况下,您可以使用 Client::make_request
方法来执行自定义请求。
use serde_json::Value;
use smite::client::Client;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let dev_id = "my-dev-id";
let auth_key = "my-auth-key";
let client = Client::new(dev_id.to_string(), auth_key.to_string());
let res: Value = client.make_request("gettopmatches", true, &[]).await?;
// ...
// Or if you want to use custom struct make sure it implements `serde_json::Deserialize`
// let response: MyCustomStruct = client.make_request("gettopmatches", true, &[]).await?;
Ok(())
}
依赖关系
~7–19MB
~281K SLoC