conduit_cli/core/modrinth/
versions.rs1use super::client::ModrinthAPI;
2use crate::core::modrinth::models::Version;
3use std::fmt::Write;
4
5impl ModrinthAPI {
6 pub async fn get_versions(
7 &self,
8 id_or_slug: &str,
9 loader: Option<&str>,
10 game_version: Option<&str>,
11 ) -> Result<Vec<Version>, reqwest::Error> {
12 let mut url = format!("{}/project/{id_or_slug}/version?", self.base_url);
13
14 if let Some(l) = loader {
15 let _ = write!(url, "loaders=[\"{l}\"]&");
16 }
17 if let Some(gv) = game_version {
18 let _ = write!(url, "game_versions=[\"{gv}\"]&");
19 }
20
21 self.client
22 .get(url)
23 .send()
24 .await?
25 .error_for_status()?
26 .json::<Vec<Version>>()
27 .await
28 }
29}