From 7dd18b41dbc89d05809c84f1d2519dca50b22aed Mon Sep 17 00:00:00 2001 From: Flora Hill Date: Tue, 9 Apr 2024 01:43:22 +0000 Subject: [PATCH] Fix disruptions - Better ? vs & detection for queries - Allow service_time to deser to None for an empty string. - Properly use QUIET env --- src/helpers.rs | 16 +++++++++++----- src/lib.rs | 10 +++++++--- src/ty.rs | 2 ++ tests/main.rs | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index baf464b..25f675f 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -58,11 +58,17 @@ where { let s: Option = Option::deserialize(deserializer)?; match s { - Some(s) => Ok(Some( - NaiveDateTime::parse_from_str(&s, "%H:%M:%S").map_err(|e| { - serde::de::Error::custom(format!("Error deser service_time '{s}': {e:?}")) - })?, - )), + Some(s) => { + if s.is_empty() { + Ok(None) + } else { + Ok(Some( + NaiveDateTime::parse_from_str(&s, "%H:%M:%S").map_err(|e| { + serde::de::Error::custom(format!("Error deser service_time '{s}': {e:?}")) + })?, + )) + } + } None => Ok(None), } } diff --git a/src/lib.rs b/src/lib.rs index d2cc3f1..fcec78a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,10 +26,14 @@ impl Client { let path = format!( "/{path}{}devid={}", { - if path.ends_with('?') { - "" + if !path.contains('?') { + "?" } else { - "&" + if path.ends_with('?') { + "" + } else { + "&" + } } }, self.devid diff --git a/src/ty.rs b/src/ty.rs index 4a3897f..f6ddeb1 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -531,6 +531,8 @@ pub struct DisruptionDirection { #[serde(rename = "direction_name")] pub name: String, /// Time of service to which disruption applies. Returns None if disruption applies to multiple, or no services + /// + /// This doesn't use null, it uses a blank string. I hate it here. #[serde(deserialize_with = "de_service_time")] pub service_time: Option, } diff --git a/tests/main.rs b/tests/main.rs index 7201f2c..a64fc62 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -109,7 +109,7 @@ pub mod test { "passed".green(), elapsed, { - if std::env::var("quiet").is_ok() { + if std::env::var("QUIET").is_err() { format!("\n{}", res.cyan()) } else { " ...".cyan().to_string()