use serde::Deserialize;
use serde_json::{from_value, Value};
use crate::{
errors::{ErrorHandle, SteamUserError},
macros::do_http,
steam_id::SteamId,
Steam, BASE,
};
use super::INTERFACE;
const ENDPOINT: &str = "GetUserGroupList";
const VERSION: &str = "1";
#[derive(Deserialize, Debug)]
struct Wrapper {
response: Response,
}
#[derive(Deserialize, Debug, Clone)]
pub struct Response {
pub success: bool,
pub error: Option<String>,
pub groups: Vec<Group>,
}
#[derive(Deserialize, Debug, Clone)]
pub struct Group {
pub gid: String,
}
impl Steam {
pub async fn get_user_group_list(&self, steam_id: SteamId) -> Result<Response, SteamUserError> {
let query = format!("?key={}&steamid={}", &self.api_key, steam_id);
let url = format!("{}/{}/{}/v{}/{}", BASE, INTERFACE, ENDPOINT, VERSION, query);
println!("{}", url);
let json = do_http!(url, Value, ErrorHandle, SteamUserError::GetUserGroupList);
let wrapper: Wrapper = ErrorHandle!(
from_value(json.to_owned()),
SteamUserError::GetUserGroupList
);
Ok(wrapper.response)
}
}