steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
//! Script to inspect real Steam Market histogram API response.
//!
//! This example makes a direct HTTP request to the Steam Market
//! itemordershistogram API endpoint and prints the raw JSON response for
//! inspection.
//!
//! Run with: cargo run --example inspect_histogram

use reqwest::Client;
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    info!("=== Steam Market Item Orders Histogram API Inspector ===\n");

    // Example item_nameid: 176413986
    // You can find this by inspecting the market listing page for an item
    let item_nameid = "176413986";
    let country = "VN";
    let currency = "15"; // VND

    info!("Request parameters:");
    info!("  item_nameid: {}", item_nameid);
    info!("  country: {}", country);
    info!("  currency: {}\n", currency);

    let client = Client::builder().user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36").build()?;

    let url = "https://steamcommunity.com/market/itemordershistogram";

    let response = client.get(url).query(&[("country", country), ("language", "english"), ("currency", currency), ("item_nameid", item_nameid), ("two_factor", "0")]).send().await?;

    info!("Response status: {}", response.status());
    info!("Response headers:");
    for (name, value) in response.headers().iter() {
        if name.as_str().starts_with("content") || name.as_str().starts_with("x-") {
            info!("  {}: {:?}", name, value);
        }
    }
    info!(" ");

    let json: serde_json::Value = response.json().await?;

    info!("=== Raw JSON Response (pretty-printed) ===\n");
    info!("{}", serde_json::to_string_pretty(&json)?);

    // Parse specific fields for inspection
    info!("\n=== Key Fields ===\n");

    if let Some(success) = json.get("success") {
        info!("success: {}", success);
    }

    if let Some(highest_buy) = json.get("highest_buy_order") {
        info!("highest_buy_order: {}", highest_buy);
    }

    if let Some(lowest_sell) = json.get("lowest_sell_order") {
        info!("lowest_sell_order: {}", lowest_sell);
    }

    if let Some(price_prefix) = json.get("price_prefix") {
        info!("price_prefix: {}", price_prefix);
    }

    if let Some(price_suffix) = json.get("price_suffix") {
        info!("price_suffix: {}", price_suffix);
    }

    if let Some(buy_order_graph) = json.get("buy_order_graph") {
        if let Some(arr) = buy_order_graph.as_array() {
            info!("\nbuy_order_graph entries: {}", arr.len());
            if let Some(first) = arr.first() {
                info!("  First entry: {}", first);
            }
        }
    }

    if let Some(sell_order_graph) = json.get("sell_order_graph") {
        if let Some(arr) = sell_order_graph.as_array() {
            info!("sell_order_graph entries: {}", arr.len());
            if let Some(first) = arr.first() {
                info!("  First entry: {}", first);
            }
        }
    }

    Ok(())
}