From c67ca1b2a11cdec149e16ee0ca81453e9c0f4e4e Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 24 Jun 2026 15:29:21 -0400 Subject: [PATCH] cargo fmt --- src/app.rs | 2 +- src/main.rs | 2 +- src/service/core.rs | 6 +-- src/service/mod.rs | 2 +- src/service/queue.rs | 110 ++++++++++++++++++++++--------------------- 5 files changed, 62 insertions(+), 60 deletions(-) diff --git a/src/app.rs b/src/app.rs index 310eab0..3086f50 100644 --- a/src/app.rs +++ b/src/app.rs @@ -46,7 +46,7 @@ pub async fn load_app() -> Result { auth_url: envs[1].value.clone(), service_username: envs[2].value.clone(), service_passphrase: envs[3].value.clone(), - twilio_config: twilio_config, + twilio_config, }), Err(err) => Err(err), } diff --git a/src/main.rs b/src/main.rs index a1a87c3..911720c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ async fn main() -> Result<(), Box> { let mut svc = catapult::service::core::Service { app: app.clone(), - token: token, + token, }; loop { diff --git a/src/service/core.rs b/src/service/core.rs index d9869aa..7a5e042 100644 --- a/src/service/core.rs +++ b/src/service/core.rs @@ -22,7 +22,7 @@ impl Service { } }; - if !queue_item.is_some() { + if queue_item.is_none() { println!("No queue item found"); return; } @@ -39,8 +39,8 @@ impl Service { Then do the real work. - 1. Check the queue - 2. If there is an item, get the data, + 1. Check the queue - Done + 2. If there is an item, get the data - Done 3. Evaluate if it is schedulable 4. Get the events and iterate each one 5. starting with the message diff --git a/src/service/mod.rs b/src/service/mod.rs index 7fcb09e..788f4cc 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -73,7 +73,7 @@ pub mod auth { } async fn parse_token_response( - response: &String, + response: &str, ) -> Result { match serde_json::from_str::(response) { Ok(j) => { diff --git a/src/service/queue.rs b/src/service/queue.rs index 7321441..b5c50d2 100644 --- a/src/service/queue.rs +++ b/src/service/queue.rs @@ -1,66 +1,68 @@ pub struct Queue { pub app: crate::app::App, - pub token: textsender_models::token::LoginResult + pub token: textsender_models::token::LoginResult, } impl Queue { - pub async fn get_queue(&self) -> Result { - let client = reqwest::Client::new(); - let endpoint = String::from("api/v1/schedule/message/fetch"); - let api_url = format!("{}/{endpoint}", self.app.api_url); - - println!("Url: {api_url:?}"); - - let (key, header) = super::auth_header(&self.token.access_token); - - match client.get(api_url).header(key, header).send().await { - Ok(response) => match response.status() { - reqwest::StatusCode::OK => { - println!("Response: {response:?}"); - match response.text().await { - Ok(val) => match parse_queue_response(&val).await { - Ok(login_result) => Ok(login_result), - Err(err) => Err(err), - }, - Err(err) => Err(std::io::Error::other(err)), - } - } - _ => Err(std::io::Error::other("Error getting token")), - }, - Err(err) => Err(std::io::Error::other(err.to_string())), - } - } -} - - async fn parse_queue_response( - response: &String, + pub async fn get_queue( + &self, ) -> Result { - match serde_json::from_str::(response) { - Ok(j) => { - let message = &j["message"]; - let data = &j["data"]; + let client = reqwest::Client::new(); + let endpoint = String::from("api/v1/schedule/message/fetch"); + let api_url = format!("{}/{endpoint}", self.app.api_url); - println!("Message: {message:?}"); - println!("Data: {data:?}"); - match j.get("data") { - Some(serde_json::Value::Array(lrs)) => { - if lrs.is_empty() { - Err(std::io::Error::other("Error response is empty")) - } else { - let lr = lrs[0].clone(); - let ll: textsender_models::message::scheduling::ScheduledMessage = - match serde_json::from_value(lr) { - Ok(lr) => lr, - Err(err) => { - return Err(std::io::Error::other(err.to_string())); - } - }; - Ok(ll) - } + println!("Url: {api_url:?}"); + + let (key, header) = super::auth_header(&self.token.access_token); + + match client.get(api_url).header(key, header).send().await { + Ok(response) => match response.status() { + reqwest::StatusCode::OK => { + println!("Response: {response:?}"); + match response.text().await { + Ok(val) => match parse_queue_response(&val).await { + Ok(login_result) => Ok(login_result), + Err(err) => Err(err), + }, + Err(err) => Err(std::io::Error::other(err)), } - _ => Err(std::io::Error::other("Error parsing response")), } - } + _ => Err(std::io::Error::other("Error getting token")), + }, Err(err) => Err(std::io::Error::other(err.to_string())), } } +} + +async fn parse_queue_response( + response: &str, +) -> Result { + match serde_json::from_str::(response) { + Ok(j) => { + let message = &j["message"]; + let data = &j["data"]; + + println!("Message: {message:?}"); + println!("Data: {data:?}"); + match j.get("data") { + Some(serde_json::Value::Array(lrs)) => { + if lrs.is_empty() { + Err(std::io::Error::other("Error response is empty")) + } else { + let lr = lrs[0].clone(); + let ll: textsender_models::message::scheduling::ScheduledMessage = + match serde_json::from_value(lr) { + Ok(lr) => lr, + Err(err) => { + return Err(std::io::Error::other(err.to_string())); + } + }; + Ok(ll) + } + } + _ => Err(std::io::Error::other("Error parsing response")), + } + } + Err(err) => Err(std::io::Error::other(err.to_string())), + } +}