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.

//! Boosts 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 `ListEventBoosts`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListEventBoostsParams {
    /// 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 `ListRecordingBoosts`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListRecordingBoostsParams {
    /// 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>,
}

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

impl<'a> BoostsService<'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 boost on a specific event within a recording. Only boostable events accept one: those whose action is completed, adopted, column_changed or moved_in (their JSON includes boosts_count and boosts_url). Any other event answers 403 Forbidden, as does an event on a recording whose comments are closed; an event on a recording the person cannot see answers 404.
    ///
    /// `POST /recordings/{recordingId}/events/{eventId}/boosts.json` — not idempotent, sent exactly once.
    pub async fn create_for_event(
        &self,
        recording_id: i64,
        event_id: i64,
        body: &CreateEventBoostRequestContent,
    ) -> Result<CreateEventBoostResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_EVENT_BOOST, &[&recording_id, &event_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create a boost on a recording
    ///
    /// `POST /recordings/{recordingId}/boosts.json` — not idempotent, sent exactly once.
    pub async fn create_for_recording(
        &self,
        recording_id: i64,
        body: &CreateRecordingBoostRequestContent,
    ) -> Result<CreateRecordingBoostResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_RECORDING_BOOST, &[&recording_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Delete a boost
    ///
    /// `DELETE /boosts/{boostId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete(&self, boost_id: i64) -> Result<(), Error> {
        let operation = self.client.operation(&routes::DELETE_BOOST, &[&boost_id]);
        self.client.send_unit(operation).await
    }

    /// Get a single boost
    ///
    /// `GET /boosts/{boostId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, boost_id: i64) -> Result<GetBoostResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_BOOST, &[&boost_id]);
        self.client.send(operation).await
    }

    /// List boosts on a specific event within a recording. Only boostable events carry boosts: those whose action is completed, adopted, column_changed or moved_in (their JSON includes boosts_count and boosts_url). Any other event answers 403 Forbidden; an event on a recording the person cannot see answers 404.
    ///
    /// `GET /recordings/{recordingId}/events/{eventId}/boosts.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_for_event(
        &self,
        recording_id: i64,
        event_id: i64,
        params: &ListEventBoostsParams,
    ) -> Result<Page<ListEventBoostsResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_EVENT_BOOSTS, &[&recording_id, &event_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// List boosts on a recording
    ///
    /// `GET /recordings/{recordingId}/boosts.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_for_recording(
        &self,
        recording_id: i64,
        params: &ListRecordingBoostsParams,
    ) -> Result<Page<ListRecordingBoostsResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_RECORDING_BOOSTS, &[&recording_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Replace the content of a boost. Only the boost's creator may update it: an
    /// admin updating someone else's boost gets 403 Forbidden, as does any caller
    /// when comments are closed on the boosted recording. A boost on a deleted
    /// recording, or in another account, answers 404. A missing or invalid
    /// `content` answers a bodiless 422. There is no bucket-scoped route.
    ///
    /// `PUT /boosts/{boostId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        boost_id: i64,
        body: &UpdateBoostRequestContent,
    ) -> Result<UpdateBoostResponseContent, Error> {
        let mut operation = self.client.operation(&routes::UPDATE_BOOST, &[&boost_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}