cobble_core/minecraft/models/
version_summary.rs

1use crate::minecraft::models::{VersionData, VersionType};
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4
5/// Summary of a version that is found in the version manifest.
6#[derive(Clone, Debug, Deserialize, Serialize)]
7pub struct VersionSummary {
8    /// The version ID.
9    /// Usually this is the version number for releases.
10    pub id: String,
11    /// The type of version this is.
12    /// Release, Snapshot, Beta or Alpha.
13    #[serde(rename = "type")]
14    pub _type: VersionType,
15    /// The URL of the version data JSON.
16    pub url: String,
17    /// Release time
18    #[serde(with = "time::serde::rfc3339")]
19    pub time: OffsetDateTime,
20    /// Release time
21    #[serde(alias = "releaseTime", with = "time::serde::rfc3339")]
22    pub release_time: OffsetDateTime,
23}
24
25impl VersionSummary {
26    /// Gets the version data itself from Minecraft servers.
27    pub async fn fetch_data(&self) -> reqwest::Result<VersionData> {
28        reqwest::get(&self.url)
29            .await?
30            .error_for_status()?
31            .json()
32            .await
33    }
34}