Skip to main content

conduit_cli/core/modrinth/
projects.rs

1use std::error::Error;
2
3use crate::core::modrinth::models::Project;
4
5use super::client::ModrinthAPI;
6
7impl ModrinthAPI {
8    pub async fn get_project(
9        &self,
10        id_or_slug: &str,
11    ) -> Result<Project, Box<dyn Error>> {
12        let url = format!("{}/project/{}", self.base_url, id_or_slug);
13
14        let project: Project = self
15            .client
16            .get(url)
17            .send()
18            .await?
19            .error_for_status()?
20            .json::<Project>()
21            .await?;
22
23        if project.project_type != "mod" {
24            return Err(format!(
25                "Project '{}' is a {}, but only 'mod' is supported.",
26                id_or_slug, project.project_type
27            )
28            .into());
29        }
30
31        Ok(project)
32    }
33}