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