mod agent;
pub mod client;
pub(crate) mod handler;
pub mod models;
pub use agent::TrelloAgent;
pub use client::TrelloClient;
use tokio::sync::Mutex;
pub struct TrelloState {
api_key: Mutex<Option<String>>,
api_token: Mutex<Option<String>>,
bot_member_id: Mutex<Option<String>>,
connected: Mutex<bool>,
}
impl Default for TrelloState {
fn default() -> Self {
Self::new()
}
}
impl TrelloState {
pub fn new() -> Self {
Self {
api_key: Mutex::new(None),
api_token: Mutex::new(None),
bot_member_id: Mutex::new(None),
connected: Mutex::new(false),
}
}
pub async fn set_credentials(&self, api_key: String, api_token: String) {
*self.api_key.lock().await = Some(api_key);
*self.api_token.lock().await = Some(api_token);
}
pub async fn set_bot_member_id(&self, id: String) {
*self.bot_member_id.lock().await = Some(id);
}
pub async fn set_connected(&self, val: bool) {
*self.connected.lock().await = val;
}
pub async fn is_connected(&self) -> bool {
*self.connected.lock().await
}
pub async fn credentials(&self) -> Option<(String, String)> {
let key = self.api_key.lock().await.clone()?;
let token = self.api_token.lock().await.clone()?;
Some((key, token))
}
pub async fn bot_member_id(&self) -> Option<String> {
self.bot_member_id.lock().await.clone()
}
}