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.

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

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

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

    /// Replace an upload's file with a new version
    ///
    /// The recording keeps its id, its URL and its comments; the previous file becomes a
    /// past version. Use this instead of CreateUpload when publishing a new release of the
    /// same file, so its published link keeps working.
    ///
    /// `POST /uploads/{uploadId}/versions.json` — not idempotent, sent exactly once.
    pub async fn create_version(
        &self,
        upload_id: i64,
        body: &CreateUploadVersionRequestContent,
    ) -> Result<CreateUploadVersionResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_UPLOAD_VERSION, &[&upload_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

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

    /// List uploads 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}/uploads.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(
        &self,
        vault_id: i64,
        params: &ListUploadsParams,
    ) -> Result<Page<ListUploadsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_UPLOADS, &[&vault_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// List versions of an upload
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /uploads/{uploadId}/versions.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_versions(
        &self,
        upload_id: i64,
    ) -> Result<Page<ListUploadVersionsResponseContent>, Error> {
        let operation = self
            .client
            .operation(&routes::LIST_UPLOAD_VERSIONS, &[&upload_id]);
        self.client.send_page(operation).await
    }

    /// Update an existing upload
    ///
    /// `PUT /uploads/{uploadId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        upload_id: i64,
        body: &UpdateUploadRequestContent,
    ) -> Result<UpdateUploadResponseContent, Error> {
        let mut operation = self.client.operation(&routes::UPDATE_UPLOAD, &[&upload_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}