feat: add site data api
This commit is contained in:
parent
e8e73e9afe
commit
0aa021259a
6 changed files with 353 additions and 5 deletions
|
|
@ -6,5 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.24"
|
||||
reqwest = { version = "0.11.17", features = ["json"] }
|
||||
serde = { version = "1.0.163", features = ["derive"] }
|
||||
uuid = { version = "1.3.2", features = ["serde"] }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
mod models;
|
||||
|
||||
use models::Resource;
|
||||
use chrono::NaiveDate;
|
||||
use models::{Resource, Data, SiteData};
|
||||
|
||||
const USER_AGENT: &str = "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0";
|
||||
|
||||
|
|
@ -16,7 +17,13 @@ impl AffluencesClient {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn available(&mut self) -> reqwest::Result<Vec<Resource>> {
|
||||
self.client.get("https://reservation.affluences.com/api/resources/026b8caa-d310-464f-b714-4c21a2cf98ea/available?date=2023-05-11&type=1").send().await?.json::<Vec<Resource>>().await
|
||||
pub async fn available(&mut self, resource_uuid: &str, date: NaiveDate, resource_type: u32) -> reqwest::Result<Vec<Resource>> {
|
||||
let url = format!("https://reservation.affluences.com/api/resources/{}/available", resource_uuid);
|
||||
self.client.get(url).query(&[("date", date.format("%Y-%m-%d").to_string()), ("type", resource_type.to_string())]).send().await?.json::<Vec<Resource>>().await
|
||||
}
|
||||
|
||||
pub async fn site_data(&mut self, name: &str) -> reqwest::Result<SiteData> {
|
||||
let url = format!("https://api.affluences.com/app/v3/sites/{}", name);
|
||||
Ok(self.client.get(url).send().await?.json::<Data<SiteData>>().await?.data)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,3 +38,134 @@ pub struct Resource {
|
|||
pub slots_state: u32,
|
||||
pub hours: Vec<Hour>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Data<T> {
|
||||
pub data: T
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataCategory {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
pub name_plural: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataLocationCoordinates {
|
||||
pub latitude: f64,
|
||||
pub longitude: f64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataLocationAddress {
|
||||
pub route: String,
|
||||
pub city: String,
|
||||
pub zip_code: String,
|
||||
pub region: String,
|
||||
pub country_code: String
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataLocation {
|
||||
pub coordinates: SiteDataLocationCoordinates,
|
||||
pub address: SiteDataLocationAddress
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataForecast {
|
||||
pub opened: bool,
|
||||
pub occupancy: u64,
|
||||
// waiting_time
|
||||
pub waiting_time_overflow: bool
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataNotice {
|
||||
message: String,
|
||||
url: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataChild {
|
||||
pub id: uuid::Uuid,
|
||||
pub slug: String,
|
||||
pub parent: Option<String>,
|
||||
pub primary_name: String,
|
||||
pub secondary_name: String,
|
||||
pub concat_name: String,
|
||||
pub categories: Vec<SiteDataCategory>,
|
||||
pub time_zone: String,
|
||||
pub location: SiteDataLocation,
|
||||
pub phone_number: String,
|
||||
pub email: String,
|
||||
pub url: String,
|
||||
pub notices: Vec<SiteDataNotice>,
|
||||
// messages
|
||||
pub estimated_distance: f64,
|
||||
pub current_forecast: SiteDataForecast,
|
||||
pub today_forecasts: Vec<SiteDataForecast>,
|
||||
// events
|
||||
// children
|
||||
// actions
|
||||
// services
|
||||
// infos
|
||||
pub poster_image: String,
|
||||
// images
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataService {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataInfo {
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteDataStatus {
|
||||
pub state: String,
|
||||
pub text: String,
|
||||
pub color: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct SiteData {
|
||||
pub id: uuid::Uuid,
|
||||
pub slug: String,
|
||||
parent: Option<String>,
|
||||
pub primary_name: String,
|
||||
pub secondary_name: String,
|
||||
pub concat_name: String,
|
||||
pub categories: Vec<SiteDataCategory>,
|
||||
pub time_zone: String,
|
||||
pub location: SiteDataLocation,
|
||||
pub phone_number: Option<String>,
|
||||
pub email: Option<String>,
|
||||
pub url: Option<String>,
|
||||
notices: Vec<SiteDataNotice>,
|
||||
// messages
|
||||
pub estimated_distance: f64,
|
||||
pub current_forecast: SiteDataForecast,
|
||||
pub today_forecasts: Vec<SiteDataForecast>,
|
||||
// events
|
||||
pub children: Vec<SiteData>,
|
||||
// actions
|
||||
pub services: Vec<SiteDataService>,
|
||||
pub infos: Vec<SiteDataInfo>,
|
||||
pub poster_image: String,
|
||||
pub image: Option<Vec<String>>,
|
||||
// status
|
||||
pub closed: bool,
|
||||
pub booking_available: bool,
|
||||
pub extended_forecasts: bool,
|
||||
pub booking_url: Option<String>,
|
||||
pub validated: bool,
|
||||
pub validationStatus: String,
|
||||
pub publicationStatus: String
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue