Crates.io | smite |
lib.rs | smite |
version | 0.4.3 |
source | src |
created_at | 2024-07-22 18:43:56.843302 |
updated_at | 2024-09-10 18:21:32.798028 |
description | Library for interacting with the Smite API |
homepage | https://github.com/mateusz2173/smite-rs |
repository | https://github.com/mateusz2173/smite-rs |
max_upload_size | |
id | 1311520 |
size | 41,335 |
Smite-rs is a Rust library for interacting with the Smite API. It is designed to be easy to use and provide a simple interface for interacting with the API.
In order to use the Smite API, you will need to obtain a dev-id and auth-key from the Hi-Rez Developer Portal. Once you have it, you can use it to create a new Client
instance and start making requests.
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(())
}
Some endpoints are not yet fully supported by library.
In this case you can use Client::make_request
method to make custom requests.
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(())
}