steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
use steamid::SteamID;

use super::super::{GasError, GasSteamUser};
use crate::types::{GroupInfoXml, GroupOverview, InvitableGroup};

impl GasSteamUser {
    pub async fn join_group(&self, group_id: SteamID) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call_void("join_group", &[("groupId", &gid)]).await
    }
    pub async fn leave_group(&self, group_id: SteamID) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call_void("leave_group", &[("groupId", &gid)]).await
    }
    pub async fn get_group_members(&self, group_id: SteamID) -> Result<Vec<SteamID>, GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call("get_group_members", &[("groupId", &gid)]).await
    }
    pub async fn post_group_announcement(&self, group_id: SteamID, headline: &str, content: &str) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call_void("post_group_announcement", &[("groupId", &gid), ("headline", headline), ("content", content)]).await
    }
    pub async fn kick_group_member(&self, group_id: SteamID, member_id: SteamID) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        let mid = member_id.steam_id64().to_string();
        self.call_void("kick_group_member", &[("groupId", &gid), ("memberId", &mid)]).await
    }
    pub async fn invite_user_to_group(&self, user_id: SteamID, group_id: SteamID) -> Result<(), GasError> {
        let uid = user_id.steam_id64().to_string();
        let gid = group_id.steam_id64().to_string();
        self.call_void("invite_user_to_group", &[("steamId64", &uid), ("groupId", &gid)]).await
    }
    pub async fn invite_users_to_group(&self, user_ids: &[SteamID], group_id: SteamID) -> Result<(), GasError> {
        let id_values: Vec<u64> = user_ids.iter().map(|id| id.steam_id64()).collect();
        let ids_json = serde_json::to_string(&id_values).map_err(GasError::Json)?;
        let gid = group_id.steam_id64().to_string();
        self.call_void("invite_users_to_group", &[("steamIds", &ids_json), ("groupId", &gid)]).await
    }
    pub async fn accept_group_invite(&self, group_id: SteamID) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call_void("accept_group_invite", &[("groupId", &gid)]).await
    }
    pub async fn ignore_group_invite(&self, group_id: SteamID) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call_void("ignore_group_invite", &[("groupId", &gid)]).await
    }
    pub async fn get_group_overview(&self, gid: Option<SteamID>, group_url: Option<&str>, page: Option<i32>, search_key: Option<&str>) -> Result<GroupOverview, GasError> {
        let mut params: Vec<(&str, String)> = Vec::new();
        if let Some(g) = gid {
            params.push(("gid", g.steam_id64().to_string()));
        }
        if let Some(u) = group_url {
            params.push(("groupUrl", u.to_string()));
        }
        if let Some(p) = page {
            params.push(("page", p.to_string()));
        }
        if let Some(k) = search_key {
            params.push(("searchKey", k.to_string()));
        }
        let refs: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
        self.call("get_group_overview", &refs).await
    }
    pub async fn get_group_steam_id_from_vanity_url(&self, vanity_url: &str) -> Result<String, GasError> {
        self.call("get_group_steam_id_from_vanity_url", &[("vanityUrl", vanity_url)]).await
    }
    pub async fn get_group_info_xml(&self, gid: Option<SteamID>, group_url: Option<&str>, page: Option<u32>) -> Result<GroupInfoXml, GasError> {
        let mut params: Vec<(&str, String)> = Vec::new();
        if let Some(g) = gid {
            params.push(("gid", g.steam_id64().to_string()));
        }
        if let Some(u) = group_url {
            params.push(("groupUrl", u.to_string()));
        }
        if let Some(p) = page {
            params.push(("page", p.to_string()));
        }
        let refs: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
        self.call("get_group_info_xml", &refs).await
    }
    pub async fn get_group_info_xml_full(&self, gid: Option<SteamID>, group_url: Option<&str>) -> Result<GroupInfoXml, GasError> {
        let mut params: Vec<(&str, String)> = Vec::new();
        if let Some(g) = gid {
            params.push(("gid", g.steam_id64().to_string()));
        }
        if let Some(u) = group_url {
            params.push(("groupUrl", u.to_string()));
        }
        let refs: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
        self.call("get_group_info_xml_full", &refs).await
    }
    pub async fn get_invitable_groups(&self, user_steam_id: SteamID) -> Result<Vec<InvitableGroup>, GasError> {
        let id = user_steam_id.steam_id64().to_string();
        self.call("get_invitable_groups", &[("steamId64", &id)]).await
    }
    pub async fn invite_all_friends_to_group(&self, group_id: SteamID) -> Result<(), GasError> {
        let gid = group_id.steam_id64().to_string();
        self.call_void("invite_all_friends_to_group", &[("groupId", &gid)]).await
    }
}