Skip to main content

fume_core/user/
resolve_vanity_url.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Api, Param, Response, ResponseResult, user::SteamId};
4
5use super::INTERFACE;
6
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct VanityUrl(pub String);
9
10impl Param for VanityUrl {
11    fn name() -> &'static str {
12        "vanityurl"
13    }
14
15    fn value(&self) -> String {
16        self.0.to_owned()
17    }
18}
19
20#[derive(Clone, Debug, Default, Serialize, Deserialize)]
21pub enum UrlType {
22    #[default]
23    IndividualProfile = 1,
24    Group = 2,
25    OfficialGameGroup = 3,
26}
27
28impl Param for UrlType {
29    fn name() -> &'static str {
30        "url_type"
31    }
32
33    fn value(&self) -> String {
34        let num = match *self {
35            UrlType::IndividualProfile => 1,
36            UrlType::Group => 2,
37            UrlType::OfficialGameGroup => 3,
38        };
39        format!("{}", num)
40    }
41}
42
43#[derive(Clone, Debug)]
44pub struct ResolveVanityUrl {
45    pub vanity_url: VanityUrl,
46    pub url_type: Option<UrlType>,
47}
48
49impl ResolveVanityUrl {
50    pub const METHOD: &str = "ResolveVanityURL";
51    pub const VERSION: &str = "v1";
52}
53
54impl Api for ResolveVanityUrl {
55    fn interface() -> &'static str {
56        INTERFACE
57    }
58
59    fn method() -> &'static str {
60        Self::METHOD
61    }
62
63    fn version() -> &'static str {
64        Self::VERSION
65    }
66
67    type Response = Response<ResolveVanityUrlResponseInner>;
68
69    fn parameters(&self) -> impl Iterator<Item = (&str, String)> {
70        std::iter::once(self.vanity_url.param())
71            .chain(self.url_type.iter().map(|url_type| url_type.param()))
72    }
73}
74
75#[derive(Clone, Debug, Deserialize, Serialize)]
76#[cfg_attr(feature = "deny-unknown-fields", serde(deny_unknown_fields))]
77pub struct ResolveVanityUrlResponseInner {
78    pub success: ResponseResult,
79    #[serde(default)]
80    pub message: Option<String>,
81    #[serde(default)]
82    pub steamid: Option<SteamId>,
83}