1pub mod ddnet;
2pub mod ddstats;
3
4use crate::errors::ApiError;
5use reqwest::{Client, Error};
6use serde::de::DeserializeOwned;
7
8pub struct DDApi {
9 client: Client,
10}
11
12impl DDApi {
13 pub fn new() -> Self {
14 let client = Client::new();
15 DDApi { client }
16 }
17
18 pub fn new_with_client(client: Client) -> Self {
19 DDApi { client }
20 }
21
22 async fn send_request(&self, uri: &str) -> Result<String, Error> {
23 self.client.get(uri).send().await?.text().await
24 }
25
26 async fn _generator<T>(&self, uri: &str) -> Result<T, ApiError>
27 where
28 T: DeserializeOwned,
29 {
30 let response = self.send_request(uri).await?;
31 Ok(serde_json::from_str(&response)?)
32 }
33}
34
35impl Default for DDApi {
36 fn default() -> Self {
37 Self::new()
38 }
39}