furse/api_calls/mod_calls.rs
1use super::*;
2use mod_structs::*;
3
4impl Furse {
5 /// Get mod with ID `mod_id`
6 ///
7 /// ## Example
8 /// ```rust
9 /// # tokio_test::block_on(async {
10 /// # let curseforge = furse::Furse::new(env!("CURSEFORGE_API_KEY"));
11 /// // Get the Terralith mod
12 /// let terralith_mod = curseforge.get_mod(513688).await?;
13 /// // Check that it is made by Starmute
14 /// assert_eq!(terralith_mod.authors[0].name, "Starmute");
15 /// # Ok::<_, furse::Error>(()) }).unwrap()
16 /// ```
17 pub async fn get_mod(&self, mod_id: ID) -> Result<Mod> {
18 Ok(self
19 .get(API_URL_BASE.join("mods/")?.join(&mod_id.to_string())?)
20 .await?
21 .data)
22 }
23
24 /// Get multiple mods with IDs `mod_ids`
25 ///
26 /// ## Example
27 /// ```rust
28 /// # tokio_test::block_on(async {
29 /// # let curseforge = furse::Furse::new(env!("CURSEFORGE_API_KEY"));
30 /// // Get Xaero's Minimap and World Map mods
31 /// let mods = curseforge.get_mods(vec![263420, 317780]).await?;
32 /// let [minimap, worldmap, ..] = mods.as_slice() else {
33 /// panic!("Expected 2 mods, got less");
34 /// };
35 /// // Check that both are made by `xaero96`
36 /// assert_eq!(minimap.authors[0].name, "xaero96");
37 /// assert_eq!(worldmap.authors[0].name, "xaero96");
38 /// # Ok::<_, furse::Error>(()) }).unwrap()
39 /// ```
40 pub async fn get_mods(&self, mod_ids: Vec<ID>) -> Result<Vec<Mod>> {
41 #[derive(serde::Serialize)]
42 #[serde(rename_all = "camelCase")]
43 struct GetModsByIdsListRequestBody {
44 mod_ids: Vec<ID>,
45 }
46 Ok(self
47 .post(
48 API_URL_BASE.join("mods")?,
49 &GetModsByIdsListRequestBody { mod_ids },
50 )
51 .await?
52 .data)
53 }
54
55 /// Get the description of mod with ID `mod_id`
56 ///
57 /// ## Example
58 /// ```rust
59 /// # tokio_test::block_on(async {
60 /// # let curseforge = furse::Furse::new(env!("CURSEFORGE_API_KEY"));
61 /// // Get the Terralith mod's description
62 /// let terralith_mod_description = curseforge.get_mod_description(513688).await?;
63 /// // The description should contain the mod's name
64 /// assert!(terralith_mod_description.contains("Terralith"));
65 /// # Ok::<_, furse::Error>(()) }).unwrap()
66 /// ```
67 pub async fn get_mod_description(&self, mod_id: ID) -> Result<String> {
68 Ok(self
69 .get(
70 API_URL_BASE
71 .join("mods/")?
72 .join(&(mod_id.to_string() + "/"))?
73 .join("description")?,
74 )
75 .await?
76 .data)
77 }
78}