cargo fmt
catapult PR / Clippy (pull_request) Successful in 55s
catapult PR / Rustfmt (pull_request) Successful in 1m0s
catapult PR / Check (pull_request) Successful in 1m21s

This commit is contained in:
2026-06-24 15:29:21 -04:00
parent 452c63fd14
commit c67ca1b2a1
5 changed files with 62 additions and 60 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ pub async fn load_app() -> Result<App, std::io::Error> {
auth_url: envs[1].value.clone(), auth_url: envs[1].value.clone(),
service_username: envs[2].value.clone(), service_username: envs[2].value.clone(),
service_passphrase: envs[3].value.clone(), service_passphrase: envs[3].value.clone(),
twilio_config: twilio_config, twilio_config,
}), }),
Err(err) => Err(err), Err(err) => Err(err),
} }
+1 -1
View File
@@ -30,7 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut svc = catapult::service::core::Service { let mut svc = catapult::service::core::Service {
app: app.clone(), app: app.clone(),
token: token, token,
}; };
loop { loop {
+3 -3
View File
@@ -22,7 +22,7 @@ impl Service {
} }
}; };
if !queue_item.is_some() { if queue_item.is_none() {
println!("No queue item found"); println!("No queue item found");
return; return;
} }
@@ -39,8 +39,8 @@ impl Service {
Then do the real work. Then do the real work.
1. Check the queue 1. Check the queue - Done
2. If there is an item, get the data, 2. If there is an item, get the data - Done
3. Evaluate if it is schedulable 3. Evaluate if it is schedulable
4. Get the events and iterate each one 4. Get the events and iterate each one
5. starting with the message 5. starting with the message
+1 -1
View File
@@ -73,7 +73,7 @@ pub mod auth {
} }
async fn parse_token_response( async fn parse_token_response(
response: &String, response: &str,
) -> Result<textsender_models::token::LoginResult, std::io::Error> { ) -> Result<textsender_models::token::LoginResult, std::io::Error> {
match serde_json::from_str::<serde_json::Value>(response) { match serde_json::from_str::<serde_json::Value>(response) {
Ok(j) => { Ok(j) => {
+56 -54
View File
@@ -1,66 +1,68 @@
pub struct Queue { pub struct Queue {
pub app: crate::app::App, pub app: crate::app::App,
pub token: textsender_models::token::LoginResult pub token: textsender_models::token::LoginResult,
} }
impl Queue { impl Queue {
pub async fn get_queue(&self) -> Result<textsender_models::message::scheduling::ScheduledMessage, std::io::Error> { pub async fn get_queue(
let client = reqwest::Client::new(); &self,
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,
) -> Result<textsender_models::message::scheduling::ScheduledMessage, std::io::Error> { ) -> Result<textsender_models::message::scheduling::ScheduledMessage, std::io::Error> {
match serde_json::from_str::<serde_json::Value>(response) { let client = reqwest::Client::new();
Ok(j) => { let endpoint = String::from("api/v1/schedule/message/fetch");
let message = &j["message"]; let api_url = format!("{}/{endpoint}", self.app.api_url);
let data = &j["data"];
println!("Message: {message:?}"); println!("Url: {api_url:?}");
println!("Data: {data:?}");
match j.get("data") { let (key, header) = super::auth_header(&self.token.access_token);
Some(serde_json::Value::Array(lrs)) => {
if lrs.is_empty() { match client.get(api_url).header(key, header).send().await {
Err(std::io::Error::other("Error response is empty")) Ok(response) => match response.status() {
} else { reqwest::StatusCode::OK => {
let lr = lrs[0].clone(); println!("Response: {response:?}");
let ll: textsender_models::message::scheduling::ScheduledMessage = match response.text().await {
match serde_json::from_value(lr) { Ok(val) => match parse_queue_response(&val).await {
Ok(lr) => lr, Ok(login_result) => Ok(login_result),
Err(err) => { Err(err) => Err(err),
return Err(std::io::Error::other(err.to_string())); },
} Err(err) => Err(std::io::Error::other(err)),
};
Ok(ll)
}
} }
_ => 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())), Err(err) => Err(std::io::Error::other(err.to_string())),
} }
} }
}
async fn parse_queue_response(
response: &str,
) -> Result<textsender_models::message::scheduling::ScheduledMessage, std::io::Error> {
match serde_json::from_str::<serde_json::Value>(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())),
}
}