fujc/curse_api/
mod.rs

1use reqwest::header::HeaderMap;
2
3use crate::errors::CreatorError;
4
5pub mod minecraft;
6pub mod modloader;
7pub mod mods;
8
9/// The base URL for the CurseForge API.
10pub static CURSE_API_URL: &str = "https://api.curseforge.com/v1/";
11
12/// The CurseForge API wrapper.
13pub struct CurseApi {
14    http_client: reqwest::Client,
15}
16
17impl CurseApi {
18    /// Creates a new CurseForge API wrapper.
19    /// 
20    /// # Arguments
21    /// 
22    /// * `api_token` - The API token to use for requests.
23    /// 
24    /// # Returns
25    /// 
26    /// A new CurseForge API wrapper.
27    /// 
28    /// # Errors
29    /// 
30    /// If the API token is invalid, or if the HTTP client cannot be created.
31    pub fn new<S>(api_token: S) -> Result<Self, CreatorError>
32    where
33        S: AsRef<str>,
34    {
35        let mut headers = HeaderMap::new();
36        headers.insert("X-Api-Key", api_token.as_ref().parse().unwrap());
37
38        let http_client = reqwest::Client::builder()
39            .default_headers(headers)
40            .build()?;
41
42        Ok(Self { http_client })
43    }
44}