// use kxio::net::Net; use crate::api_result::APIResult; use crate::{config::NextcloudConfig, f}; use crate::nextcloud::model::{NextcloudHostname, NextcloudPassword, NextcloudUsername}; use model::{Board, Card, NextcloudBoardId, Stack}; pub mod model; #[cfg(test)] mod tests; pub(crate) struct DeckClient<'cfg> { net: Net, hostname: &'cfg NextcloudHostname, username: &'cfg NextcloudUsername, password: &'cfg NextcloudPassword, } impl<'cfg> DeckClient<'cfg> { pub fn new(cfg: &'cfg NextcloudConfig, net: Net) -> Self { Self { net, hostname: &cfg.hostname, username: &cfg.username, password: &cfg.password, } } fn url(&self, path: impl Into) -> String { f!( "https://{}/index.php/apps/deck/api/v1.0/{}", self.hostname, path.into() ) } pub async fn get_boards(&self) -> APIResult> { APIResult::new( self.net .get(self.url("boards")) .basic_auth(self.username.as_str(), Some(self.password.as_str())) .header("accept", "application/json") .send() .await, ) .await } pub async fn get_stacks(&self, board_id: NextcloudBoardId) -> APIResult> { APIResult::new( self.net .get(self.url(f!("boards/{board_id}/stacks"))) .basic_auth(self.username.as_str(), Some(self.password.as_str())) .header("accept", "application/json") .send() .await, ) .await } }