From 92bda65a9983e60036b3d49333e9bfe9bcd0543f Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 11 Jan 2023 17:21:08 +0100 Subject: begin of mc_version api impl --- src/apis/modrinth.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/apis/modrinth.rs') diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 3880fa0..78073e6 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -194,3 +194,32 @@ pub fn extract_current_version(versions: Vec) -> Result panic!("available_versions should never be negative"), } } + +pub enum MCVersionType { + Release, + Latest, +} + +#[derive(Debug, Deserialize)] +pub struct MCVersion { + pub version: String, + pub version_type: String, + pub date: String, + pub major: bool, +} + +pub async fn get_minecraft_version(api: String, version: MCVersionType) -> String { + let data = get(api, String::from("tag/game_version")).await.unwrap().unwrap(); + let mc_versions: Vec = serde_json::from_slice(&data).unwrap(); + let ver = match version { + MCVersionType::Release => { + let mut i = 0; + while !mc_versions[i].major { + i += 1; + }; + &mc_versions[i] + }, + MCVersionType::Latest => &mc_versions[0], + }; + String::from(&ver.version) +} -- cgit v1.2.3