diff --git a/Cargo.toml b/Cargo.toml index 38909c4..5c0f973 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "api" -version = "0.7.6" +version = "0.8.0-dev" edition = "2018" license = "AGPL-3.0-or-later" authors = ["Denys Konovalov "] diff --git a/src/indiware_connector.rs b/src/indiware_connector.rs index fed14a1..22d7988 100644 --- a/src/indiware_connector.rs +++ b/src/indiware_connector.rs @@ -91,7 +91,7 @@ pub async fn get_timetable(_conn: DbConn, url: String) -> Vec { let empty_list = serde_json::Value::Array(vec![]); let empty_obj = serde_json::Value::Object(Map::new()); let empty_vec = Vec::new(); - let info_list = xml + let info_value = xml .as_object() .unwrap() .get("VpMobil") @@ -99,13 +99,15 @@ pub async fn get_timetable(_conn: DbConn, url: String) -> Vec { .get("ZusatzInfo") .unwrap_or(&empty_obj) .get("ZiZeile") - .unwrap_or(&empty_list) - .as_array() - .unwrap_or(&empty_vec); + .unwrap_or(&empty_list); let mut info = String::new(); - for item in info_list { - info.push_str(item.as_str().unwrap_or("\r\n")); - info.push_str("\r\n"); + if info_value.is_array() { + for item in info_value.as_array().unwrap_or(&empty_vec) { + info.push_str(item.as_str().unwrap_or("\r\n")); + info.push_str("\r\n"); + } + } else if info_value.is_string() { + info.push_str(info_value.as_str().unwrap_or("")); } let response = TimetableData { count: plan.len(), @@ -159,7 +161,7 @@ pub async fn get_class_timetable(_conn: DbConn, class: String, url: String) -> T let empty_list = serde_json::Value::Array(vec![]); let empty_obj = serde_json::Value::Object(Map::new()); let empty_vec = Vec::new(); - let info_list = xml + let info_value = xml .as_object() .unwrap() .get("VpMobil") @@ -167,13 +169,15 @@ pub async fn get_class_timetable(_conn: DbConn, class: String, url: String) -> T .get("ZusatzInfo") .unwrap_or(&empty_obj) .get("ZiZeile") - .unwrap_or(&empty_list) - .as_array() - .unwrap_or(&empty_vec); + .unwrap_or(&empty_list); let mut info = String::new(); - for item in info_list { - info.push_str(item.as_str().unwrap_or("\r\n")); - info.push_str("\r\n"); + if info_value.is_array() { + for item in info_value.as_array().unwrap_or(&empty_vec) { + info.push_str(item.as_str().unwrap_or("\r\n")); + info.push_str("\r\n"); + } + } else if info_value.is_string() { + info.push_str(info_value.as_str().unwrap_or("")); } let mut response = TimetableData { count: 0,