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.

//! Templates 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::*;
use crate::pagination::Page;

/// Optional query parameters for `ListTemplates`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListTemplatesParams {
    /// active|archived|trashed
    pub status: Option<String>,
    /// Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.
    pub page: Option<i32>,
}

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

impl<'a> TemplatesService<'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 new template
    ///
    /// `POST /templates.json` — not idempotent, sent exactly once.
    pub async fn create(
        &self,
        body: &CreateTemplateRequestContent,
    ) -> Result<CreateTemplateResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_TEMPLATE, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create a card table template with the default columns
    ///
    /// `POST /template_library/card_tables.json` — not idempotent, sent exactly once.
    pub async fn create_library_card_table(
        &self,
        body: &CreateTemplateLibraryCardTableRequestContent,
    ) -> Result<CreateTemplateLibraryCardTableResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_TEMPLATE_LIBRARY_CARD_TABLE, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Start copying a to-do list or card table template into a project
    ///
    /// `POST /template_library/copies.json` — not idempotent, sent exactly once.
    pub async fn create_library_copy(
        &self,
        body: &CreateTemplateLibraryCopyRequestContent,
    ) -> Result<CreateTemplateLibraryCopyResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_TEMPLATE_LIBRARY_COPY, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create an empty to-do list template
    ///
    /// `POST /template_library/todolists.json` — not idempotent, sent exactly once.
    pub async fn create_library_todolist(
        &self,
        body: &CreateTemplateLibraryTodolistRequestContent,
    ) -> Result<CreateTemplateLibraryTodolistResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_TEMPLATE_LIBRARY_TODOLIST, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create a project from a template (asynchronous)
    ///
    /// `POST /templates/{templateId}/project_constructions.json` — not idempotent, sent exactly once.
    pub async fn create_project(
        &self,
        template_id: i64,
        body: &CreateProjectFromTemplateRequestContent,
    ) -> Result<CreateProjectFromTemplateResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_PROJECT_FROM_TEMPLATE, &[&template_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Templatify a to-do list or card table
    ///
    /// `POST /buckets/{bucketId}/recordings/{recordingId}/templatifications.json` — not idempotent, sent exactly once.
    pub async fn create_templatification(
        &self,
        bucket_id: i64,
        recording_id: i64,
        body: &CreateTemplatificationRequestContent,
    ) -> Result<CreateTemplatificationResponseContent, Error> {
        let mut operation = self.client.operation(
            &routes::CREATE_TEMPLATIFICATION,
            &[&bucket_id, &recording_id],
        );
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Delete a template (trash it)
    ///
    /// `DELETE /templates/{templateId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete(&self, template_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::DELETE_TEMPLATE, &[&template_id]);
        self.client.send_unit(operation).await
    }

    /// Get a single template by id
    ///
    /// `GET /templates/{templateId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, template_id: i64) -> Result<GetTemplateResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_TEMPLATE, &[&template_id]);
        self.client.send(operation).await
    }

    /// Get the status of a project construction
    ///
    /// `GET /templates/{templateId}/project_constructions/{constructionId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_construction(
        &self,
        template_id: i64,
        construction_id: i64,
    ) -> Result<GetProjectConstructionResponseContent, Error> {
        let operation = self.client.operation(
            &routes::GET_PROJECT_CONSTRUCTION,
            &[&template_id, &construction_id],
        );
        self.client.send(operation).await
    }

    /// Get the account's card table templates
    ///
    /// `GET /template_library/card_tables.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_library_card_tables(
        &self,
    ) -> Result<GetTemplateLibraryCardTablesResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_TEMPLATE_LIBRARY_CARD_TABLES, &[]);
        self.client.send(operation).await
    }

    /// Get the current status of a to-do list template copy
    ///
    /// `GET /template_library/copies/{copyId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_library_copy(
        &self,
        copy_id: i64,
    ) -> Result<GetTemplateLibraryCopyResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_TEMPLATE_LIBRARY_COPY, &[&copy_id]);
        self.client.send(operation).await
    }

    /// Get the account's to-do list templates
    ///
    /// `GET /template_library/todolists.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_library_todolists(
        &self,
    ) -> Result<GetTemplateLibraryTodolistsResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_TEMPLATE_LIBRARY_TODOLISTS, &[]);
        self.client.send(operation).await
    }

    /// Get a templatification
    ///
    /// `GET /buckets/{bucketId}/recordings/{recordingId}/templatifications/{templatificationId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_templatification(
        &self,
        bucket_id: i64,
        recording_id: i64,
        templatification_id: i64,
    ) -> Result<GetTemplatificationResponseContent, Error> {
        let operation = self.client.operation(
            &routes::GET_TEMPLATIFICATION,
            &[&bucket_id, &recording_id, &templatification_id],
        );
        self.client.send(operation).await
    }

    /// List all templates visible to the current user
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /templates.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(
        &self,
        params: &ListTemplatesParams,
    ) -> Result<Page<ListTemplatesResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_TEMPLATES, &[]);
        operation.query_optional("status", params.status.as_ref());
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Update an existing template
    ///
    /// `PUT /templates/{templateId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        template_id: i64,
        body: &UpdateTemplateRequestContent,
    ) -> Result<UpdateTemplateResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_TEMPLATE, &[&template_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}