1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use hyper::{body::Bytes, StatusCode};
use serde::Deserialize;

use crate::{request::Requestable, ClientError};

/// Information about a custom skin.
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct SkinInfo {
    /// The name of the skin.
    #[serde(rename = "skinName")]
    pub name: Box<str>,
    /// The author (skinner, parsed from the skin's skin.ini) of the skin.
    #[serde(rename = "skinAuthor")]
    pub author: Box<str>,
    /// The download link for this custom skin, from issou.best servers.
    #[serde(rename = "downloadLink")]
    pub download_link: Box<str>,
}

impl Requestable for SkinInfo {
    fn response_error(status: StatusCode, bytes: Bytes) -> ClientError {
        if status == StatusCode::NOT_FOUND {
            match serde_json::from_slice(&bytes) {
                Ok(error) => ClientError::SkinDeleted { error },
                Err(source) => ClientError::Parsing {
                    body: bytes.into(),
                    source,
                },
            }
        } else {
            ClientError::response_error(bytes, status.as_u16())
        }
    }
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct SkinDeleted {
    /// true if found, false if not.
    pub found: bool,
    /// true if removed, false if not.
    pub removed: bool,
    /// The info message, in english, of an error.
    pub message: Box<str>,
    /// The name of the skin.
    pub name: Option<Box<str>>,
    /// The author (skinner, parsed from the skin's skin.ini) of the skin.
    pub author: Option<Box<str>>,
}