mod models; use chrono::NaiveDate; pub use models::*; const USER_AGENT: &str = "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0"; pub struct AffluencesClient { client: reqwest::Client, } impl AffluencesClient { pub fn new() -> Self { Self { client: reqwest::Client::builder() .user_agent(USER_AGENT) .build() .unwrap(), } } pub async fn search(&self, query: String) -> reqwest::Result { let url = "https://api.affluences.com/app/v3/sites"; let body = SiteSearch{ search_query: query }; Ok(self.client.post(url).json(&body).send().await?.json::>().await?.data) } pub async fn available( &self, site_id: uuid::Uuid, date: NaiveDate, resource_type: u32, ) -> reqwest::Result> { let url = format!( "https://reservation.affluences.com/api/resources/{}/available", site_id ); self.client .get(url) .query(&[ ("date", date.format("%Y-%m-%d").to_string()), ("type", resource_type.to_string()), ]) .send() .await? .json::>() .await } pub async fn site_data(&self, slug: &str) -> reqwest::Result { let url = format!("https://api.affluences.com/app/v3/sites/{}", slug); Ok(self .client .get(url) .send() .await? .json::>() .await? .data) } pub async fn make_reservation( &self, resource_id: u32, reservation: &Reservation, ) -> reqwest::Result { let url = format!( "https://reservation.affluences.com/api/reserve/{}", resource_id ); self.client .post(url) .json(reservation) .send() .await? .json::() .await } }