Crates.io | steamr |
lib.rs | steamr |
version | 0.4.0 |
source | src |
created_at | 2022-08-08 23:38:54.541528 |
updated_at | 2024-05-01 20:17:57.96557 |
description | HTTP client library to communicate with Valve's Steam API |
homepage | https://github.com/bellackn/steamr |
repository | https://github.com/bellackn/steamr |
max_upload_size | |
id | 641135 |
size | 38,435 |
steamr is a simple Rust library to help you to interact with Valve's Steam API. It uses the reqwest crate under the hood.
You need a valid API key to make full use of this library. Visit https://steamcommunity.com/dev/apikey to obtain yours.
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(())
}
There are some endpoints that don't require an API key. If you only need those,
you can use SteamClient
like so:
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(())
}