basecamp-sdk 0.38.0

Official client for Basecamp - https://basecamp.com
Documentation
// Generated by basecamp-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

//! Folders operations.

#![allow(
    clippy::too_many_arguments,
    clippy::wildcard_imports,
    clippy::doc_markdown
)]

use crate::client::AccountClient;
use crate::error::Error;
use crate::generated::routes;
#[allow(unused_imports)]
use crate::generated::types::*;

/// `Folders` operations, sent through one [`AccountClient`].
#[derive(Debug, Clone, Copy)]
pub struct FoldersService<'a> {
    client: &'a AccountClient,
}

impl<'a> FoldersService<'a> {
    pub(crate) fn new(client: &'a AccountClient) -> Self {
        Self { client }
    }

    /// The client this service sends through.
    pub fn client(&self) -> &'a AccountClient {
        self.client
    }

    /// Create a folder for the authenticated user and file the given projects into it.
    ///
    /// Returns 201 with the new folder and its expanded `projects`, placed at the
    /// top of the home screen. Filing an all-access project the user has not joined
    /// **grants** them access to it. Every id is preflighted: if any is archived,
    /// trashed, or an invitation-only project the user is not on, the whole request
    /// fails with 404 and nothing is created — there is no partial success.
    ///
    /// `POST /stacks.json` — not idempotent, sent exactly once.
    pub async fn create_folder(
        &self,
        body: &CreateFolderRequestContent,
    ) -> Result<CreateFolderResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_FOLDER, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Delete a folder and unpin its projects from the home screen (returns 204 No Content).
    ///
    /// The projects themselves are not deleted and are not moved back out onto the
    /// home screen; they simply stop appearing there until pinned again.
    ///
    /// `DELETE /stacks/{folderId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete_folder(&self, folder_id: i64) -> Result<(), Error> {
        let operation = self.client.operation(&routes::DELETE_FOLDER, &[&folder_id]);
        self.client.send_unit(operation).await
    }

    /// Get one folder, with the projects grouped inside it expanded under `projects`.
    ///
    /// `GET /stacks/{folderId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_folder(&self, folder_id: i64) -> Result<GetFolderResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_FOLDER, &[&folder_id]);
        self.client.send(operation).await
    }

    /// List the authenticated user's folders in home-screen order.
    ///
    /// Returns a bare array with no pagination envelope. Items are the base folder
    /// shape: they carry `bucket_ids` but **not** the expanded `projects`, which
    /// only the single-folder operations return.
    ///
    /// `GET /stacks.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_folders(&self) -> Result<ListFoldersResponseContent, Error> {
        let operation = self.client.operation(&routes::LIST_FOLDERS, &[]);
        self.client.send(operation).await
    }

    /// Rename a folder.
    ///
    /// `name` is the only writable attribute; a folder's projects, ordering, and
    /// image are managed elsewhere and an image parameter sent here is ignored.
    ///
    /// `PUT /stacks/{folderId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_folder(
        &self,
        folder_id: i64,
        body: &UpdateFolderRequestContent,
    ) -> Result<UpdateFolderResponseContent, Error> {
        let mut operation = self.client.operation(&routes::UPDATE_FOLDER, &[&folder_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}