5个版本 (3个破坏性更新)
0.4.0 | 2024年5月1日 |
---|---|
0.3.1 | 2024年3月25日 |
0.3.0 | 2023年11月15日 |
0.2.0 | 2022年8月16日 |
0.1.0 | 2022年8月8日 |
#21 in #steam
每月47次下载
20KB
316 行
steamr 🦀
steamr 是一个简单的Rust库,可以帮助您与Valve的 Steam API 进行交互。它底层使用 reqwest crate。
需求
您需要一个有效的API密钥才能充分利用此库。请访问 https://steamcommunity.com/dev/apikey 获取您的密钥。
示例
use steamr::client::SteamClient;
use steamr::errors::SteamError;
fn main() -> Result<(), SteamError> {
// Create a new client that will be used to communicate with Steam's API.
let api_key = String::from("your-api-key");
let steam_client = SteamClient::from(api_key);
// Get a list of all games from the user with the provided Steam ID (given that they are publicly visible)
let steam_id = "some-steam-id";
let steam_lib = steam_client.get_library(&steam_id)?;
// Print out the games that were played for more than an hour.
steam_lib.games.iter()
.filter(|g| g.playtime_forever > 60)
.for_each(|g| println!("{}", g.name));
Ok(())
}
有一些端点不需要API密钥。如果您只需要这些,可以使用 SteamClient
如此
use steamr::client::SteamClient;
use steamr::errors::SteamError;
fn main() -> Result<(), SteamError> {
// Create a new SteamClient without an API key
let steam_client = SteamClient::new();
// Get news for a game
let app_id = "10";
let news = steam_client.get_game_news(app_id, 5, 100)?;
news.game_news.iter()
.for_each(|n| println!("The article '{}' was written by '{}'", n.title, n.author));
Ok(())
}
依赖项
~4–15MB
~212K SLoC