bbox_map_server/
inventory.rs1use crate::wms_capabilities::*;
2use serde::Serialize;
3use serde_xml_rs::from_reader;
4
5#[derive(Serialize, Clone, Default, Debug)]
6pub struct Inventory {
7 pub wms_services: Vec<WmsService>,
8}
9
10#[derive(Serialize, Clone, Debug)]
11pub struct WmsService {
12 pub id: String,
13 pub wms_path: String,
15 pub cap_type: CapType,
16}
17
18#[derive(Serialize, Clone, PartialEq, Debug)]
19pub enum CapType {
20 Ogc,
21 Qgis,
22}
23
24impl WmsService {
25 fn _project(&self) -> &str {
26 self.wms_path.split('/').last().expect("invalid wms_path")
27 }
28 #[allow(dead_code)]
29 fn cap_request(&self) -> &str {
30 match self.cap_type {
31 CapType::Ogc => "GetCapabilities",
32 CapType::Qgis => "GetProjectSettings",
33 }
34 }
35 #[allow(dead_code)]
36 pub fn url(&self, base_url: &str) -> String {
37 format!("{}{}", base_url, self.wms_path)
38 }
39 #[allow(dead_code)]
40 pub async fn capabilities(&self, base_url: &str) -> WmsCapabilities {
41 let client = awc::Client::default();
42 let mut response = client
43 .get(format!(
44 "{}?SERVICE=WMS&VERSION=1.3.0&REQUEST={}",
45 &self.url(base_url),
46 self.cap_request()
47 ))
48 .send()
49 .await
50 .expect("GetCapabilities");
51
52 let body = response.body().await.unwrap();
53 let cap: WmsCapabilities = from_reader(body.as_ref()).unwrap();
54 cap
55 }
56}