2023-10-23 16:17:50 +11:00
|
|
|
use heck::ToKebabCase;
|
|
|
|
use serde::Deserialize;
|
2023-10-25 12:24:36 +11:00
|
|
|
use std::collections::HashMap;
|
2023-10-23 16:17:50 +11:00
|
|
|
|
2023-10-25 12:24:36 +11:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
2023-10-23 16:17:50 +11:00
|
|
|
#[serde(rename_all = "UPPERCASE")]
|
2023-10-24 12:30:48 +11:00
|
|
|
pub struct TimdorrEndpoint {
|
2023-10-23 16:17:50 +11:00
|
|
|
#[serde(rename = "TYPE")]
|
2023-10-25 12:24:36 +11:00
|
|
|
pub method: String,
|
|
|
|
pub uri: String,
|
|
|
|
pub auth: bool,
|
2023-10-23 16:17:50 +11:00
|
|
|
}
|
|
|
|
|
2023-10-24 12:30:48 +11:00
|
|
|
pub fn parse(json_str: &str) -> HashMap<String, TimdorrEndpoint> {
|
|
|
|
let map: HashMap<String, TimdorrEndpoint> = serde_json::from_str(json_str).unwrap();
|
2023-10-23 16:17:50 +11:00
|
|
|
|
2023-10-25 12:24:36 +11:00
|
|
|
// Massage all URLs to have a / before "api".
|
|
|
|
let map = map
|
|
|
|
.into_iter()
|
|
|
|
.map(|(k, mut v)| {
|
|
|
|
v.uri = format!("/{}", v.uri);
|
|
|
|
(k, v)
|
|
|
|
})
|
|
|
|
.collect::<HashMap<String, TimdorrEndpoint>>();
|
|
|
|
|
|
|
|
// Rename all the keys to kebab-case
|
2023-10-23 16:17:50 +11:00
|
|
|
map.into_iter()
|
|
|
|
.map(|(k, v)| (k.to_kebab_case(), v))
|
2023-10-24 12:30:48 +11:00
|
|
|
.collect::<HashMap<String, TimdorrEndpoint>>()
|
2023-10-23 16:17:50 +11:00
|
|
|
}
|