From 3d48e2f408ba0e8e525cc87a5200bd6034a19f38 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 14 Dec 2024 08:05:34 +0000 Subject: [PATCH] chore(nextcloud): remove duplicate client --- src/nextcloud/mod.rs | 138 +------------------------------------------ 1 file changed, 2 insertions(+), 136 deletions(-) diff --git a/src/nextcloud/mod.rs b/src/nextcloud/mod.rs index 721aae0..9044e85 100644 --- a/src/nextcloud/mod.rs +++ b/src/nextcloud/mod.rs @@ -1,19 +1,12 @@ -use bytes::Bytes; // use clap::Parser; -use kxio::net::{Net, ReqBuilder}; use crate::{ - api_result::APIResult, execute::Execute, - f, nextcloud::{ - card::{Create, NextcloudCardCommand}, + card::NextcloudCardCommand, deck::NextcloudDeckCommand, - model::{ - Board, Card, NextcloudBoardId, NextcloudHostname, NextcloudPassword, NextcloudStackId, - NextcloudUsername, Stack, - }, + model::{NextcloudBoardId, NextcloudHostname, NextcloudPassword, NextcloudUsername}, stack::NextcloudStackCommand, }, FullCtx, @@ -35,133 +28,6 @@ pub(crate) struct DeckClient<'ctx> { password: &'ctx NextcloudPassword, } -// Uses the API described here: https://deck.readthedocs.io/en/stable/API/#cards -impl<'ctx> DeckClient<'ctx> { - pub fn new(ctx: &'ctx FullCtx) -> Self { - Self { - ctx, - hostname: &ctx.cfg.nextcloud.hostname, - username: &ctx.cfg.nextcloud.username, - password: &ctx.cfg.nextcloud.password, - } - } - - fn url(&self, path: impl Into) -> String { - f!( - "https://{}/index.php/apps/deck/api/v1.0/{}", - self.hostname, - path.into() - ) - } - - async fn request serde::Deserialize<'a>>( - &self, - url: impl Into, - custom: fn(&Net, String) -> ReqBuilder, - ) -> APIResult { - APIResult::new( - custom(&self.ctx.net, self.url(url)) - .basic_auth(self.username.as_str(), Some(self.password.as_str())) - .header("accept", "application/json") - .header("content-type", "application/json") - .send() - .await, - &self.ctx.prt, - ) - .await - } - - async fn request_with_body serde::Deserialize<'a>>( - &self, - url: impl Into, - body: impl Into, - custom: fn(&Net, String) -> ReqBuilder, - ) -> APIResult { - APIResult::new( - custom(&self.ctx.net, self.url(url)) - .basic_auth(self.username.as_str(), Some(self.password.as_str())) - .header("accept", "application/json") - .header("content-type", "application/json") - .body(body) - .send() - .await, - &self.ctx.prt, - ) - .await - } - - pub async fn get_boards(&self) -> APIResult> { - self.request("boards", |net, url| net.get(url)).await - } - - pub async fn get_board(&self, board_id: NextcloudBoardId) -> APIResult { - self.request(f!("boards/{board_id}"), |net, url| net.get(url)) - .await - } - - pub async fn create_board(&self, title: &str, color: &str) -> APIResult { - self.request_with_body( - "boards", - serde_json::json!({ - "title": title, - "color": color - }) - .to_string(), - |net, url| net.post(url), - ) - .await - } - - pub async fn get_stacks(&self, board_id: NextcloudBoardId) -> APIResult> { - self.request(f!("boards/{board_id}/stacks"), |net, url| net.get(url)) - .await - } - - pub async fn get_stack( - &self, - board_id: NextcloudBoardId, - stack_id: NextcloudStackId, - ) -> APIResult { - self.request(f!("boards/{board_id}/stacks/{stack_id}"), |net, url| { - net.get(url) - }) - .await - } - - pub(crate) async fn create_card(&self, create: &Create) -> APIResult { - let mut body = serde_json::json!({ - "title": create.title, - }); - - if let Some(desc) = &create.description { - body["description"] = serde_json::Value::String(desc.to_string()); - } - - self.request_with_body( - format!( - "boards/{}/stacks/{}/cards", - self.ctx.cfg.nextcloud.board_id, create.stack_id - ), - body.to_string(), - |net, url| net.post(url), - ) - .await - } - - async fn get_card( - &self, - board_id: NextcloudBoardId, - stack_id: NextcloudStackId, - card_id: model::NextcloudCardId, - ) -> APIResult { - self.request( - f!("boards/{board_id}/stacks/{stack_id}/cards/{card_id}"), - |net, url| net.get(url), - ) - .await - } -} - #[derive(Parser, Debug)] pub(crate) enum NextcloudCommand { #[clap(subcommand)]