From a9fde833aaedd663a512ace33c550c153629857f Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 3 Jun 2026 21:37:23 -0400 Subject: [PATCH] Changed type check --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/twilio/api/mod.rs | 49 +++++++++++++++++++------------------------ 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d7b497..050e8c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1658,8 +1658,8 @@ dependencies = [ [[package]] name = "textsender_models" -version = "0.3.0" -source = "git+ssh://git@git.kundeng.us/phoenix/textsender-models.git?tag=v0.3.0-20-15820d5505-111#15820d550526aea3016821c01f508d8d590292cc" +version = "0.2.5" +source = "git+ssh://git@git.kundeng.us/phoenix/textsender-models.git?tag=v0.2.5-v0.3.0-migrate-38dbcb09f7-111#38dbcb09f7c2c572f429ec382c01e14b72b1d615" dependencies = [ "const_format", "dotenvy", diff --git a/Cargo.toml b/Cargo.toml index b8c365a..0b3834e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ uuid = { version = "1.23.1", features = ["v4", "serde"] } base64-ng = { version = "1.0.6" } const_format = { version = "0.2.36" } josekit = { version = "0.10.3" } -textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0-20-15820d5505-111" } +textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.2.5-v0.3.0-migrate-38dbcb09f7-111" } [dev-dependencies] tempfile = { version = "3.27.0" } diff --git a/src/twilio/api/mod.rs b/src/twilio/api/mod.rs index fccd0cb..f6ef1bd 100644 --- a/src/twilio/api/mod.rs +++ b/src/twilio/api/mod.rs @@ -8,7 +8,7 @@ pub async fn send_mssage( param: crate::twilio::types::Parameters, config: &textsender_models::config::auxiliary::TwilioConfig, ) -> Result { - if config.account_sid.is_nil() { + if config.account_sid.is_empty() { Err(std::io::Error::other("Account SID is empty")) } else if config.auth_token.is_empty() { Err(std::io::Error::other(" Auth token is empty")) @@ -45,9 +45,7 @@ pub async fn send_mssage( let converted = date_value.to_string(); converted } - None => { - String::new() - } + None => String::new(), }; if param.schedule && is_scheduleable(&Some(now), ¶m.schedule_at) { params.insert("ScheduleType", "fixed"); @@ -60,7 +58,8 @@ pub async fn send_mssage( params.insert("Body", msg.content.as_str()); let url = format!( - "https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json", config.account_sid + "https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json", + config.account_sid ); // let client = reqwest::Client::new(); @@ -73,13 +72,12 @@ pub async fn send_mssage( match request.send().await { Ok(response) => { - match response.json::().await { - Ok(resp) => { - Ok(resp) - } - Err(err) => { - Err(std::io::Error::other(err)) - } + match response + .json::() + .await + { + Ok(resp) => Ok(resp), + Err(err) => Err(std::io::Error::other(err)), } /* match response.text().await { @@ -104,15 +102,13 @@ pub async fn send_mssage( } } -fn generate_auth(config: &textsender_models::config::auxiliary::TwilioConfig) -> Result { +fn generate_auth( + config: &textsender_models::config::auxiliary::TwilioConfig, +) -> Result { let input = format!("{}:{}", config.account_sid, config.auth_token); match base64_ng::encode(input.as_bytes()) { - Ok(encoded) => { - Ok(format!("Basic {encoded}")) - } - Err(err) => { - Err(err) - } + Ok(encoded) => Ok(format!("Basic {encoded}")), + Err(err) => Err(err), } } /* @@ -215,15 +211,12 @@ fn is_scheduleable( ) -> bool { match scheduled { Some(schedule_at) => { - let early = now.unwrap().checked_add(time::Duration::seconds(300)).unwrap(); - if *schedule_at > early { - true - } else { - false - } - } - None => { - false + let early = now + .unwrap() + .checked_add(time::Duration::seconds(300)) + .unwrap(); + if *schedule_at > early { true } else { false } } + None => false, } }