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.

//! Campfires operations.

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

use bytes::Bytes;

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

/// Optional query parameters for `ListCampfireLines`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListCampfireLinesParams {
    /// created_at|updated_at
    pub sort: Option<String>,
    /// asc|desc
    pub direction: 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>,
}

/// Optional query parameters for `ListCampfireUploads`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListCampfireUploadsParams {
    /// created_at|updated_at
    pub sort: Option<String>,
    /// asc|desc
    pub direction: 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>,
}

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

impl<'a> CampfiresService<'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 chatbot for a campfire
    ///
    /// `POST /buckets/{bucketId}/chats/{campfireId}/integrations.json` — not idempotent, sent exactly once.
    pub async fn create_chatbot(
        &self,
        bucket_id: i64,
        campfire_id: i64,
        body: &CreateChatbotRequestContent,
    ) -> Result<CreateChatbotResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_CHATBOT, &[&bucket_id, &campfire_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create a new line (message) in a campfire
    ///
    /// `POST /chats/{campfireId}/lines.json` — not idempotent, sent exactly once.
    pub async fn create_line(
        &self,
        campfire_id: i64,
        body: &CreateCampfireLineRequestContent,
    ) -> Result<CreateCampfireLineResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_CAMPFIRE_LINE, &[&campfire_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Upload a file to a campfire
    ///
    /// `POST /chats/{campfireId}/uploads.json` — not idempotent, sent exactly once.
    pub async fn create_upload(
        &self,
        campfire_id: i64,
        name: &str,
        content_type: &str,
        body: Bytes,
    ) -> Result<CreateCampfireUploadResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_CAMPFIRE_UPLOAD, &[&campfire_id]);
        operation.query("name", name);
        operation.bytes(content_type, body);
        self.client.send(operation).await
    }

    /// Delete a chatbot
    ///
    /// `DELETE /buckets/{bucketId}/chats/{campfireId}/integrations/{chatbotId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete_chatbot(
        &self,
        bucket_id: i64,
        campfire_id: i64,
        chatbot_id: i64,
    ) -> Result<(), Error> {
        let operation = self.client.operation(
            &routes::DELETE_CHATBOT,
            &[&bucket_id, &campfire_id, &chatbot_id],
        );
        self.client.send_unit(operation).await
    }

    /// Delete a campfire line; allowed for the line's creator or an admin.
    /// The API responds 403 Forbidden otherwise.
    ///
    /// `DELETE /chats/{campfireId}/lines/{lineId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete_line(&self, campfire_id: i64, line_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::DELETE_CAMPFIRE_LINE, &[&campfire_id, &line_id]);
        self.client.send_unit(operation).await
    }

    /// Get a campfire by ID
    ///
    /// `GET /chats/{campfireId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, campfire_id: i64) -> Result<GetCampfireResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_CAMPFIRE, &[&campfire_id]);
        self.client.send(operation).await
    }

    /// Get a chatbot by ID
    ///
    /// `GET /buckets/{bucketId}/chats/{campfireId}/integrations/{chatbotId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_chatbot(
        &self,
        bucket_id: i64,
        campfire_id: i64,
        chatbot_id: i64,
    ) -> Result<GetChatbotResponseContent, Error> {
        let operation = self.client.operation(
            &routes::GET_CHATBOT,
            &[&bucket_id, &campfire_id, &chatbot_id],
        );
        self.client.send(operation).await
    }

    /// Get a campfire line by ID
    ///
    /// `GET /chats/{campfireId}/lines/{lineId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_line(
        &self,
        campfire_id: i64,
        line_id: i64,
    ) -> Result<GetCampfireLineResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_CAMPFIRE_LINE, &[&campfire_id, &line_id]);
        self.client.send(operation).await
    }

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

    /// List all chatbots for a campfire
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /buckets/{bucketId}/chats/{campfireId}/integrations.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_chatbots(
        &self,
        bucket_id: i64,
        campfire_id: i64,
    ) -> Result<Page<ListChatbotsResponseContent>, Error> {
        let operation = self
            .client
            .operation(&routes::LIST_CHATBOTS, &[&bucket_id, &campfire_id]);
        self.client.send_page(operation).await
    }

    /// List all lines (messages) in a campfire
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /chats/{campfireId}/lines.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_lines(
        &self,
        campfire_id: i64,
        params: &ListCampfireLinesParams,
    ) -> Result<Page<ListCampfireLinesResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_CAMPFIRE_LINES, &[&campfire_id]);
        operation.query_optional("sort", params.sort.as_ref());
        operation.query_optional("direction", params.direction.as_ref());
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// List uploaded files in a campfire
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /chats/{campfireId}/uploads.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_uploads(
        &self,
        campfire_id: i64,
        params: &ListCampfireUploadsParams,
    ) -> Result<Page<ListCampfireUploadsResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_CAMPFIRE_UPLOADS, &[&campfire_id]);
        operation.query_optional("sort", params.sort.as_ref());
        operation.query_optional("direction", params.direction.as_ref());
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Update an existing chatbot
    ///
    /// `PUT /buckets/{bucketId}/chats/{campfireId}/integrations/{chatbotId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_chatbot(
        &self,
        bucket_id: i64,
        campfire_id: i64,
        chatbot_id: i64,
        body: &UpdateChatbotRequestContent,
    ) -> Result<UpdateChatbotResponseContent, Error> {
        let mut operation = self.client.operation(
            &routes::UPDATE_CHATBOT,
            &[&bucket_id, &campfire_id, &chatbot_id],
        );
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Update an existing campfire line; the content is always treated as rich text (HTML).
    /// The server coerces every edited line to rich text and ignores any content
    /// type hint. Only the line's creator may edit it, and only text and
    /// rich-text lines are editable.
    ///
    /// `PUT /chats/{campfireId}/lines/{lineId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_line(
        &self,
        campfire_id: i64,
        line_id: i64,
        body: &UpdateCampfireLineRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_CAMPFIRE_LINE, &[&campfire_id, &line_id]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }
}