steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
//! Basic usage example for steam-user crate.
//!
//! This example demonstrates:
//! - Creating a SteamUser client
//! - Setting cookies from a session
//! - Checking login status
//! - Getting notifications
//! - Getting friends list
//!
//! Run with: cargo run --example basic_usage

use steam_user::{SteamUser, SteamUserError};
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), SteamUserError> {
    // Initialize tracing for logging
    tracing_subscriber::fmt::init();

    // Create a new SteamUser client with cookies from a previous steam-session
    // login These cookies come from the LoginSession after successful
    // authentication
    let community = SteamUser::new(&["steamLoginSecure=76561198012345678||YOUR_ACCESS_TOKEN", "sessionid=YOUR_SESSION_ID"])?;

    // Check if we're logged in
    let (logged_in, family_view_restricted) = community.logged_in().await?;
    info!("Logged in: {}", logged_in);
    info!("Family view restricted: {}", family_view_restricted);

    if !logged_in {
        info!("Not logged in. Please provide valid cookies.");
        return Ok(());
    }

    // Get Steam ID
    if let Some(steam_id) = community.steam_id() {
        info!("Steam ID: {}", steam_id.steam_id64());
    }

    // Get notification counts
    match community.get_notifications().await {
        Ok(notifications) => {
            info!("\n=== Notifications ===");
            info!("  Trade offers: {}", notifications.trades);
            info!("  Comments: {}", notifications.comments);
            info!("  Items: {}", notifications.items);
            info!("  Invites: {}", notifications.invites);
            info!("  Gifts: {}", notifications.gifts);
            info!("  Chat messages: {}", notifications.chat);
        }
        Err(e) => {
            info!("Failed to get notifications: {}", e);
        }
    }

    // Get friends list
    match community.get_friends_list().await {
        Ok(friends) => {
            info!("\n=== Friends ===");
            info!("Total friends: {}", friends.len());
            for (steam_id, relationship) in friends.iter().take(5) {
                info!("  {} - Relationship: {}", steam_id.steam_id64(), relationship);
            }
            if friends.len() > 5 {
                info!("  ... and {} more", friends.len() - 5);
            }
        }
        Err(e) => {
            info!("Failed to get friends list: {}", e);
        }
    }

    // Get trade URL
    match community.get_trade_url().await {
        Ok(Some(url)) => {
            info!("\n=== Trade URL ===");
            info!("  URL: {}", url);
        }
        Ok(None) => {
            info!("\n=== Trade URL ===");
            info!("  No trade URL found.");
        }
        Err(e) => {
            info!("Failed to get trade URL: {}", e);
        }
    }

    Ok(())
}