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.

//! Vaults 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 `ListVaults`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListVaultsParams {
    /// 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>,
}

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

impl<'a> VaultsService<'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 vault (subfolder) in a vault
    ///
    /// `POST /vaults/{vaultId}/vaults.json` — not idempotent, sent exactly once.
    pub async fn create(
        &self,
        vault_id: i64,
        body: &CreateVaultRequestContent,
    ) -> Result<CreateVaultResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_VAULT, &[&vault_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

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

    /// List vaults (subfolders) in a vault
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /vaults/{vaultId}/vaults.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(
        &self,
        vault_id: i64,
        params: &ListVaultsParams,
    ) -> Result<Page<ListVaultsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_VAULTS, &[&vault_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Update an existing vault
    ///
    /// `PUT /vaults/{vaultId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        vault_id: i64,
        body: &UpdateVaultRequestContent,
    ) -> Result<UpdateVaultResponseContent, Error> {
        let mut operation = self.client.operation(&routes::UPDATE_VAULT, &[&vault_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}