use super::*;
use reqwest::Method;
use crate::QQSecret;
use std::str::FromStr;
use url::Url;
#[derive(Debug)]
pub struct GetGuildListResponse {
pub items: Vec<GuildItem>,
}
impl GetGuildListResponse {
pub fn end_point() -> String {
if cfg!(debug_assertions) {
format!("https://sandbox.api.sgroup.qq.com/users/@me/guilds")
}
else {
format!("https://api.sgroup.qq.com/users/@me/guilds")
}
}
pub async fn send(key: &QQSecret) -> QQResult<Self> {
let url = Url::from_str(&Self::end_point())?;
let response = key.as_request(Method::GET, url).send().await?;
Ok(Self { items: response.json().await? })
}
}
#[derive(Deserialize, Debug)]
pub struct GuildItem {
pub name: String,
pub description: String,
#[serde(deserialize_with = "crate::utils::read_url")]
pub icon: Url,
#[serde(deserialize_with = "crate::utils::read_u64")]
pub id: u64,
pub max_members: u32,
pub member_count: u32,
pub owner: bool,
#[serde(deserialize_with = "crate::utils::read_u64")]
pub owner_id: u64,
pub joined_at: String,
}