cfwidget/lib.rs
1//! `cfwidget` is a crate for fetching data from [cfwidget.com](https://cfwidget.com)
2//!
3//! This crate contains two main functions for reading data:
4//! - `fetch_project_by_info`
5//! - `fetch_project_by_id`
6//!
7//! Read their documentation for more info
8
9pub mod types;
10
11use crate::types::Project;
12use failure::Error;
13
14/// Fetch a CurseForge project's info by some data describing the project.
15///
16/// For example, Xaero's Minimap mod for Minecraft would be:
17///
18/// ```
19/// let minimap_mod = fetch_project_by_info("minecraft", "mc-mods", "xaeros-minimap").unwrap();
20/// ```
21///
22/// You can generally get this info from a project's CurseForge Url
23pub async fn fetch_project_by_info(
24 game_name: &str,
25 category: &str,
26 project_name: &str,
27) -> Result<Project, Error> {
28 Ok(reqwest::get(format!(
29 "https://api.cfwidget.com/{}/{}/{}",
30 game_name, category, project_name
31 ))
32 .await?
33 .json()
34 .await?)
35}
36
37/// Fetch a CurseForge project's info by its project ID
38///
39/// For example, Xaero's Minimap mod for Minecraft would be:
40///
41/// ```
42/// let minimap_mod = fetch_project_by_id(263420).unwrap();
43/// ```
44pub async fn fetch_project_by_id(id: u32) -> Result<Project, Error> {
45 Ok(reqwest::get(format!("https://api.cfwidget.com/{}", id))
46 .await?
47 .json()
48 .await?)
49}