fujc/curse_api/
minecraft.rs

1use crate::errors::CreatorError;
2
3use super::{CurseApi, CURSE_API_URL};
4use serde::Deserialize;
5use time::OffsetDateTime;
6
7/// A Minecraft version struct.
8/// 
9/// This struct is used to deserialize the response from the CurseForge API.
10/// 
11/// # Fields
12/// 
13/// * `id` - The ID of the Minecraft version.
14/// * `game_version_id` - The ID of the Minecraft version's game version.
15/// * `version_string` - The string representation of the Minecraft version.
16/// * `jar_download_url` - The URL to download the Minecraft version's JAR file.
17/// * `json_download_url` - The URL to download the Minecraft version's JSON file.
18/// * `approved` - Whether or not the Minecraft version is approved.
19/// * `date_modified` - The date and time the Minecraft version was last modified.
20/// * `game_version_type_id` - The ID of the Minecraft version's game version type.
21/// * `game_version_status` - The status of the Minecraft version's game version.
22/// * `game_version_type_status` - The status of the Minecraft version's game version type. 
23#[derive(Debug, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct MinecraftVersion {
26    /// The ID of the Minecraft version.
27    pub id: u32,
28    /// The ID of the Minecraft version's game version.
29    pub game_version_id: u32,
30    /// The string representation of the Minecraft version.
31    pub version_string: String,
32    /// The URL to download the Minecraft version's JAR file.
33    pub jar_download_url: String,
34    /// The URL to download the Minecraft version's JSON file.
35    pub json_download_url: String,
36    /// Whether or not the Minecraft version is approved.
37    pub approved: bool,
38    /// The date and time the Minecraft version was last modified.
39    #[serde(with = "time::serde::rfc3339")]
40    pub date_modified: OffsetDateTime,
41    /// The ID of the Minecraft version's game version type.
42    pub game_version_type_id: u32,
43    /// The status of the Minecraft version's game version.
44    pub game_version_status: u32,
45    /// The status of the Minecraft version's game version type.
46    pub game_version_type_status: u32,
47}
48
49/// A list of Minecraft versions.
50/// 
51/// This struct is used to deserialize the response from the CurseForge API.
52/// 
53/// # Fields
54/// 
55/// * `data` - The list of Minecraft versions.
56#[derive(Debug, serde::Deserialize)]
57pub struct MinecraftVersionsList {
58    /// The list of Minecraft versions.
59    pub data: Vec<MinecraftVersion>
60}
61
62impl CurseApi {
63    /// Gets a list of Minecraft versions.
64    /// 
65    /// # Returns
66    /// 
67    /// A list of Minecraft versions.
68    pub async fn get_minecraft_versions(&self) -> Result<MinecraftVersionsList, CreatorError> {
69        let versions = self.http_client.get(format!("{}{}", CURSE_API_URL, "minecraft/version").as_str())
70            .send()
71            .await?
72            .json::<MinecraftVersionsList>()
73            .await?;
74
75        Ok(versions)
76    }
77}