steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
//! Inventory example for steam-user crate.
//!
//! This example demonstrates:
//! - Fetching user inventory contents
//! - Iterating through items
//!
//! Run with: cargo run --example inventory

use steam_user::{SteamID, SteamUser, SteamUserError};
use steam_user::types::{AppId, ContextId};
use tracing::info;

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

    // Create a new SteamUser client with cookies from session login
    let community = SteamUser::new(&["steamLoginSecure=76561198012345678||YOUR_ACCESS_TOKEN", "sessionid=YOUR_SESSION_ID"])?;

    // Target user's Steam ID (can be your own or another user's public inventory)
    let target_steam_id = SteamID::from(76561198012345678u64);

    // Common app IDs:
    // 730 = CS2 (Counter-Strike 2)
    // 440 = TF2 (Team Fortress 2)
    // 570 = Dota 2
    // 753 = Steam (trading cards, emoticons, backgrounds)
    let app_id = AppId::new(730); // CS2

    // Context ID (usually 2 for game items, 6 for community items like cards)
    let context_id = ContextId::new(2);

    info!("Fetching inventory for {}...", target_steam_id.steam_id64());
    info!("App ID: {}, Context ID: {}", app_id, context_id);

    match community.get_user_inventory_contents(target_steam_id, app_id, context_id).await {
        Ok(items) => {
            info!("\nFound {} items:", items.len());
            for (i, item) in items.iter().enumerate().take(10) {
                info!("\n=== Item {} ===", i + 1);
                info!("  Asset ID: {}", item.assetid);
                info!("  Name: {}", item.desc.name);
                info!("  Market Hash Name: {}", item.desc.market_hash_name);
                info!("  Type: {}", item.desc.item_type);
                info!("  Tradable: {}", item.desc.tradable);
                info!("  Marketable: {}", item.desc.marketable);
                if item.amount > 1 {
                    info!("  Amount: {}", item.amount);
                }
            }
            if items.len() > 10 {
                info!("\n... and {} more items", items.len() - 10);
            }
        }
        Err(e) => {
            info!("Failed to fetch inventory: {}", e);
        }
    }

    // Example: Fetch Steam trading cards
    info!("\n\n=== Steam Trading Cards ===");
    let steam_app_id = AppId::new(753); // Steam
    let cards_context_id = ContextId::new(6); // Community items

    match community.get_user_inventory_contents(target_steam_id, steam_app_id, cards_context_id).await {
        Ok(items) => {
            info!("Found {} community items", items.len());

            // Filter for trading cards
            let cards: Vec<_> = items.iter().filter(|item| item.desc.item_type.contains("Card")).collect();

            info!("Trading cards: {}", cards.len());
            for card in cards.iter().take(5) {
                info!("  - {} ({})", card.desc.name, card.desc.market_hash_name);
            }
        }
        Err(e) => {
            info!("Failed to fetch community items: {}", e);
        }
    }

    Ok(())
}