|
7 | 7 | //! The core of this crate is the [`Steam`] struct, which interacts with the Steam Web API. It typically[^1] needs to be initialized with a valid Steam API key. |
8 | 8 | //! |
9 | 9 | //! ``` |
| 10 | +//! use steam_rs::Steam; |
| 11 | +//! |
10 | 12 | //! // Retrieve the Steam API key from an environment variable. |
11 | 13 | //! let steam_api_key = &std::env::var("STEAM_API_KEY").expect("Missing an API key"); |
12 | 14 | //! |
|
16 | 18 | //! |
17 | 19 | //! Another key component of this crate is the [`SteamId`](`steam_id::SteamId`) struct. It represents a Steam user ID[^2], which is often used when querying user data. |
18 | 20 | //! |
| 21 | +//! ## Example |
| 22 | +//! |
| 23 | +//! Here is an example, where the [`Steam`] client requests data about two users using the [`.get_player_summaries(steam_ids)`](`Steam::get_player_summaries()`) method: |
| 24 | +//! |
19 | 25 | //! ``` |
20 | | -//! let steam_ids = vec![ |
21 | | -//! SteamId::new(76561198136162943), |
22 | | -//! SteamId(76561197960435530), |
23 | | -//! ]; |
| 26 | +//! use steam_rs::{steam_id::SteamId, Steam}; |
| 27 | +//! |
| 28 | +//! #[tokio::main] |
| 29 | +//! async fn main() { |
| 30 | +//! // Get the Steam API Key as an environment variable. |
| 31 | +//! let steam_api_key = &std::env::var("STEAM_API_KEY").expect("Missing an API key"); |
24 | 32 | //! |
25 | | -//! // Request the player summaries of SteamIDs `76561198136162943` and `76561197960435530`. |
26 | | -//! let player_summaries = steam.get_player_summaries(steam_ids).await.unwrap(); |
| 33 | +//! // Initialize the Steam API client. |
| 34 | +//! let steam = Steam::new(steam_api_key); |
| 35 | +//! |
| 36 | +//! // Request the player summaries of SteamIDs `76561198136162943` and `76561197960435530`. |
| 37 | +//! let steam_ids = vec![ |
| 38 | +//! SteamId::new(76561198136162943), // Garrett Howard |
| 39 | +//! SteamId(76561197960435530), // Robin Walker |
| 40 | +//! ]; |
| 41 | +//! |
| 42 | +//! let player_summaries = steam.get_player_summaries(steam_ids).await.unwrap(); |
| 43 | +//! |
| 44 | +//! // Print the recieved information about the players. |
| 45 | +//! for player in player_summaries { |
| 46 | +//! println!( |
| 47 | +//! "{:?}'s SteamID is {:?}", |
| 48 | +//! player.persona_name, player.steam_id |
| 49 | +//! ) |
| 50 | +//! } |
| 51 | +//! } |
27 | 52 | //! ``` |
28 | 53 | //! |
29 | 54 | //! [^1]: Not all API endpoints require an API key, and in that case providing one is optional. |
30 | 55 | //! [^2]: Specifically, [`SteamId`](`steam_id::SteamId`) represents a SteamID64 type, but more types, such as SteamID and SteamID3 are planned in future releases. |
31 | 56 |
|
| 57 | +#![doc( |
| 58 | + html_logo_url = "https://raw.githubusercontent.com/garhow/steam-rs/refs/heads/main/branding/docs.png" |
| 59 | +)] |
| 60 | + |
32 | 61 | pub mod econ_service; |
33 | 62 | pub mod game_servers_service; |
34 | 63 | pub mod player_service; |
|
0 commit comments