use serde::{Deserialize, Serialize};
use serde_json::{from_value, Value};
use crate::{
errors::{ErrorHandle, SteamUserError},
macros::{do_http, optional_argument},
Steam, BASE,
};
use super::INTERFACE;
const ENDPOINT: &str = "ResolveVanityURL";
const VERSION: &str = "1";
#[derive(Serialize, Deserialize, Debug)]
struct Wrapper {
response: Response,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Response {
pub message: Option<String>,
pub steamid: Option<String>,
pub success: u8,
}
impl Steam {
pub async fn resolve_vanity_url(
&self,
vanity_url: &str,
url_type: Option<i32>,
) -> Result<Response, SteamUserError> {
let query = vec![
format!("?key={}", &self.api_key),
format!("&vanityurl={}", vanity_url),
optional_argument!(url_type),
];
let url = format!(
"{}/{}/{}/v{}/{}",
BASE,
INTERFACE,
ENDPOINT,
VERSION,
query.concat()
);
let json = do_http!(url, Value, ErrorHandle, SteamUserError::ResolveVanityURL);
let wrapper: Wrapper = ErrorHandle!(
from_value(json.to_owned()),
SteamUserError::ResolveVanityURL
);
Ok(wrapper.response)
}
}