1use http::Http;
2
3pub mod error;
4mod http;
5pub mod model;
6
7const MAP_ROTATIONS_LOCATION: &'static str = "maprotation";
8const CRAFTER_ROTATIONS_LOCATION: &'static str = "crafting";
9const ALL_ROTATIONS: (&'static str, &'static str) = ("version", "2");
10
11#[derive(Debug)]
12pub struct ApexClient<'a> {
13 token: &'a str,
14}
15
16impl<'a> ApexClient<'a> {
17 pub fn new(token: &'a str) -> Self {
18 ApexClient { token }
19 }
20
21 pub async fn get_map_rotations(
22 &self,
23 ) -> Result<crate::model::MapRotations, crate::error::ApexError> {
24 let http = Http::new_with_auth(self.token);
25 let body = http
26 .request(MAP_ROTATIONS_LOCATION, &[ALL_ROTATIONS])
27 .await?;
28 Ok(serde_json::from_str(&body)?)
29 }
30
31 pub async fn get_crafter_rotations(
32 &self,
33 ) -> Result<crate::model::Bundles, crate::error::ApexError> {
34 let http = Http::new_with_auth(self.token);
35 let body = http.request(CRAFTER_ROTATIONS_LOCATION, &[]).await?;
36 Ok(serde_json::from_str(&body)?)
37 }
38}