Skip to main content

conduit_cli/modrinth/
versions.rs

1use crate::modrinth::models::Version;
2
3use super::client::ModrinthAPI;
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/{}/version?", self.base_url, id_or_slug);
13
14        if let Some(l) = loader {
15            url.push_str(&format!("loaders=[\"{}\"]&", l));
16        }
17        if let Some(gv) = game_version {
18            url.push_str(&format!("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}