psn_rs 0.1.0

Interact with PlayStation Network API in full Rust!
Documentation
use std::fmt::Display;

use chrono::{DateTime, Utc};
use serde::Deserialize;
use serde_repr::Deserialize_repr;

#[derive(Debug, Deserialize)]
pub struct TrophyTitles {
    #[serde(rename = "trophyTitles")]
    pub trophy_titles: Vec<TrophyTitle>,
    #[serde(rename = "nextOffset")]
    pub next_offset: Option<usize>,
    #[serde(rename = "totalItemCount")]
    pub total_item_count: usize,
}

#[derive(Debug, Deserialize)]
pub struct TrophyTitle {
    #[serde(rename = "npServiceName")]
    pub np_service_name: String,
    #[serde(rename = "npCommunicationId")]
    pub np_communication_id: String,
    #[serde(rename = "trophySetVersion")]
    pub trophy_set_version: String,
    #[serde(rename = "trophyTitleName")]
    pub trophy_title_name: String,
    #[serde(rename = "trophyTitleIconUrl")]
    pub trophy_title_icon_url: String,
    #[serde(rename = "trophyTitlePlatform")]
    pub trophy_title_platform: String,
    #[serde(rename = "hasTrophyGroups")]
    pub has_trophy_groups: bool,
    #[serde(rename = "trophyGroupCount")]
    pub trophy_group_count: u32,
    #[serde(rename = "definedTrophies")]
    pub defined_trophies: DefinedTrophies,
    pub progress: u32,
    #[serde(rename = "earnedTrophies")]
    pub earned_trophies: DefinedTrophies,
    #[serde(rename = "hiddenFlag")]
    pub hidden_flag: bool,
    #[serde(rename = "lastUpdatedDateTime")]
    pub last_updated_date_time: String,
}

#[derive(Debug, Deserialize)]
pub struct DefinedTrophies {
    pub bronze: u32,
    pub silver: u32,
    pub gold: u32,
    pub platinum: u32,
}

#[derive(Debug, Deserialize)]
pub struct TitleTrophies {
    #[serde(rename = "nextOffset")]
    pub next_offset: Option<usize>,
    #[serde(rename = "trophySetVersion")]
    pub trophy_set_version: String,
    #[serde(rename = "hasTrophyGroups")]
    pub has_trophy_groups: bool,
    #[serde(rename = "lastUpdatedDateTime")]
    pub last_updated_date_time: Option<DateTime<Utc>>,
    pub trophies: Vec<Trophy>,
    #[serde(rename = "totalItemCount")]
    pub total_item_count: u32,
    #[serde(rename = "rarestTrophies")]
    pub rarest_trophies: Vec<Trophy>,
}

#[derive(Debug, Deserialize)]
pub struct Trophy {
    #[serde(rename = "trophyId")]
    pub id: u32,
    #[serde(rename = "trophyHidden")]
    pub hidden: bool,
    #[serde(rename = "earned")]
    pub earned: bool,
    #[serde(rename = "earnedDateTime")]
    pub earned_date_time: Option<DateTime<Utc>>,
    #[serde(rename = "trophyType")]
    pub trophy_type: TrophyType,
    #[serde(rename = "trophyRare")]
    pub rarity: TrophyRarity,
    #[serde(rename = "trophyEarnedRate")]
    pub earned_rate: String,
    #[serde(rename = "trophyProgressTargetValue")]
    pub progress_target_value: Option<String>,
    #[serde(rename = "trophyRewardName")]
    pub trophy_reward_name: Option<String>,
    #[serde(rename = "trophyRewardImageUrl")]
    pub trophy_reward_image_url: Option<String>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum TrophyType {
    Bronze,
    Silver,
    Gold,
    Platinum,
}

impl Display for TrophyType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TrophyType::Bronze => write!(f, "Bronze"),
            TrophyType::Silver => write!(f, "Silver"),
            TrophyType::Gold => write!(f, "Gold"),
            TrophyType::Platinum => write!(f, "Platinum"),
        }
    }
}

#[derive(Debug, Deserialize_repr)]
#[repr(u8)]
pub enum TrophyRarity {
    UltraRare = 0,
    VeryRare = 1,
    Rare = 2,
    Common = 3,
}

impl Display for TrophyRarity {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TrophyRarity::UltraRare => write!(f, "Ultra Rare"),
            TrophyRarity::VeryRare => write!(f, "Very Rare"),
            TrophyRarity::Rare => write!(f, "Rare"),
            TrophyRarity::Common => write!(f, "Common"),
        }
    }
}