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
use reqwest::header::HeaderMap;

use crate::errors::CreatorError;

mod minecraft;
mod modloader;

pub static CURSE_API_URL: &str = "https://api.curseforge.com/v1/";

/// A struct that represents the CurseForge API

pub struct CurseApi {
    http_client: reqwest::Client,
}

impl CurseApi {
    /// Create a new CurseApi
    /// 
    /// # Arguments
    /// 
    /// * `api_token` - The API token to use
    /// 
    /// # Example
    /// 
    /// ```rs
    /// use fujc_api::curse_api::CurseApi;
    /// 
    /// let curse_api = CurseApi::new("api_token");
    /// ```
    pub fn new<S>(api_token: S) -> Result<Self, CreatorError>
    where
        S: AsRef<str>,
    {
        let mut headers = HeaderMap::new();
        headers.insert("X-Api-Key", api_token.as_ref().parse().unwrap());

        let http_client = reqwest::Client::builder()
            .default_headers(headers)
            .build()?;

        Ok(Self { http_client })
    }
}