steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
//! Profile management example for steam-user crate.
//!
//! This example demonstrates:
//! - Editing profile settings
//! - Changing privacy settings
//! - Uploading avatar
//! - Posting profile status
//!
//! Run with: cargo run --example profile

use steam_user::{PrivacySettings, PrivacyState, ProfileSettings, SteamUser, SteamUserError};
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"])?;

    // Example: Edit profile settings
    info!("=== Edit Profile ===");
    let profile_settings = ProfileSettings {
        name: Some("My New Display Name".to_string()),
        real_name: Some("John Doe".to_string()),
        summary: Some("Hello! Welcome to my Steam profile.".to_string()),
        country: Some("US".to_string()),
        state: Some("CA".to_string()),
        city: Some("Los Angeles".to_string()),
        custom_url: Some("mycustomurl".to_string()),
        primary_group: None, // Group Steam ID if you want to set primary group
    };

    match community.edit_profile(profile_settings).await {
        Ok(()) => info!("Profile updated successfully!"),
        Err(e) => info!("Failed to update profile: {}", e),
    }

    // Example: Change privacy settings
    info!("\n=== Privacy Settings ===");
    let privacy_settings = PrivacySettings {
        profile: Some(PrivacyState::Public),
        inventory: Some(PrivacyState::FriendsOnly),
        inventory_gifts: Some(PrivacyState::Public),
        game_details: Some(PrivacyState::Private),
        playtime: Some(PrivacyState::Public), // false = public, true = private
        friends_list: Some(PrivacyState::FriendsOnly),
        comments: Some(1), // 0 = friends, 1 = anyone, 2 = private
    };

    match community.set_privacy_settings(privacy_settings).await {
        Ok(_) => info!("Privacy settings updated!"),
        Err(e) => info!("Failed to update privacy: {}", e),
    }

    // Example: Upload avatar
    // Read image from file
    // info!("\n=== Upload Avatar ===");
    // let image_data = std::fs::read("avatar.png")?;
    // match community.upload_avatar(&image_data, "png").await {
    // Ok(url) => info!("Avatar uploaded! URL: {}", url),
    // Err(e) => info!("Failed to upload avatar: {}", e),
    // }

    // Example: Post a status update
    info!("\n=== Post Status ===");
    let status_text = "Just started playing a new game!";
    let app_id = Some(730u32); // Optional: Associate with CS2

    match community.post_profile_status(status_text, app_id).await {
        Ok(post_id) => info!("Status posted! Post ID: {}", post_id),
        Err(e) => info!("Failed to post status: {}", e),
    }

    Ok(())
}