valorant_api 0.3.14

A library for interacting with the ingame Valorant-API.
Documentation
use std::fmt::Display;
use std::str::FromStr;

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientPlatform {
    platform_type: String,
    #[serde(rename = "platformOS")]
    platform_os: String,
    #[serde(rename = "platformOSVersion")]
    platform_os_version: String,
    platform_chipset: String,
}

#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum Platform {
    #[default]
    PC,
    XBOX,
    PlayStation,
}

impl Platform {
    pub(crate) fn get_client_version(&self) -> ClientPlatform {
        ClientPlatform {
            platform_type: self.get_platform_type().to_string(),
            platform_os: self.get_platform_os().to_string(),
            platform_os_version: self.get_platform_os_version().to_string(),
            platform_chipset: self.get_platform_chipset().to_string(),
        }
    }

    fn get_platform_type(&self) -> &str {
        match self {
            Platform::PC => "PC",
            Platform::XBOX => "xbox",
            Platform::PlayStation => "playstation",
        }
    }

    fn get_platform_os(&self) -> &str {
        match self {
            Platform::PC => "Windows",
            Platform::XBOX => "Xbox",
            Platform::PlayStation => "PlayStation",
        }
    }

    fn get_platform_os_version(&self) -> &str {
        match self {
            Platform::PC => "10.0.19042.1.256.64bit",
            Platform::XBOX => "10.0.19042.1.256.64bit",
            Platform::PlayStation => "10.0.19042.1.256.64bit",
        }
    }

    fn get_platform_chipset(&self) -> &str {
        match self {
            Platform::PC => "Unknown",
            Platform::XBOX => "Unknown",
            Platform::PlayStation => "Unknown",
        }
    }
}

impl FromStr for Platform {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "pc" => Ok(Platform::PC),
            "xbox" => Ok(Platform::XBOX),
            "playstation" => Ok(Platform::PlayStation),
            _ => Err(()),
        }
    }
}

impl Display for Platform {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Platform::PC => write!(f, "PC"),
            Platform::XBOX => write!(f, "XBOX"),
            Platform::PlayStation => write!(f, "PlayStation"),
        }
    }
}