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