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.

//! CloudFiles 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::*;

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

impl<'a> CloudFilesService<'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
    }

    /// Get a single cloud file by id
    ///
    /// `GET /cloud_files/{cloudFileId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn cloud_file(
        &self,
        cloud_file_id: i64,
    ) -> Result<GetCloudFileResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_CLOUD_FILE, &[&cloud_file_id]);
        self.client.send(operation).await
    }

    /// Create a new cloud file in a vault.
    /// `url` is validated against the selected service's patterns, so it must be a
    /// real link for that service; use service "other" for anything that matches no
    /// recognized service. Omitting `title` is allowed and reads back as
    /// "Untitled".
    ///
    /// `POST /buckets/{bucketId}/vaults/{vaultId}/cloud_files.json` — not idempotent, sent exactly once.
    pub async fn create_cloud_file(
        &self,
        bucket_id: i64,
        vault_id: i64,
        body: &CreateCloudFileRequestContent,
    ) -> Result<CreateCloudFileResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_CLOUD_FILE, &[&bucket_id, &vault_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Replace a cloud file with a new complete representation.
    /// BC3 builds a brand-new CloudFile from the permitted params and swaps the
    /// recordable wholesale, so the request body is the full writable state:
    /// omitting `title` clears it (and the cloud file then reads back as
    /// "Untitled"), and omitting `description` clears it. `url` and `service` carry
    /// presence/format validations, so they are required here rather than
    /// clearable — a request without them is a 422, not a silent wipe.
    /// Updating a drafted cloud file also publishes it.
    /// Subscribers are the exception to omission-clears: a drafted cloud file keeps
    /// its current subscribers when the request addresses neither `subscriptions`
    /// nor `notify`. The creator is always on the list.
    /// The legacy bucket-scoped path PUT /buckets/{bucketId}/cloud_files/{id}.json
    /// is also accepted by BC3; this flat spelling is the documented one.
    ///
    /// `PUT /cloud_files/{cloudFileId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_cloud_file(
        &self,
        cloud_file_id: i64,
        body: &UpdateCloudFileRequestContent,
    ) -> Result<UpdateCloudFileResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_CLOUD_FILE, &[&cloud_file_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}