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.

//! Gauges 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 `ListGaugeNeedles`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListGaugeNeedlesParams {
    /// 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 `ListGauges`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListGaugesParams {
    /// Comma-separated list of project IDs. When provided, results are returned
    /// in the order specified instead of by risk level.
    pub bucket_ids: 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>,
}

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

impl<'a> GaugesService<'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 gauge needle (progress update) for a project
    ///
    /// `POST /projects/{projectId}/gauge/needles.json` — not idempotent, sent exactly once.
    pub async fn create_gauge_needle(
        &self,
        project_id: i64,
        body: &CreateGaugeNeedleRequestContent,
    ) -> Result<CreateGaugeNeedleResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_GAUGE_NEEDLE, &[&project_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Destroy a gauge needle
    ///
    /// `DELETE /gauge_needles/{needleId}` — idempotent; retries up to 2 attempt(s) on 429, 503.
    pub async fn destroy_gauge_needle(&self, needle_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::DESTROY_GAUGE_NEEDLE, &[&needle_id]);
        self.client.send_unit(operation).await
    }

    /// Get a gauge needle by ID
    ///
    /// `GET /gauge_needles/{needleId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn gauge_needle(
        &self,
        needle_id: i64,
    ) -> Result<GetGaugeNeedleResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_GAUGE_NEEDLE, &[&needle_id]);
        self.client.send(operation).await
    }

    /// List gauge needles for a project, ordered newest first.
    ///
    /// `GET /projects/{projectId}/gauge/needles.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_gauge_needles(
        &self,
        project_id: i64,
        params: &ListGaugeNeedlesParams,
    ) -> Result<Page<ListGaugeNeedlesResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_GAUGE_NEEDLES, &[&project_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// List gauges across all projects the authenticated user has access to.
    /// Gauges are sorted by risk level (red, yellow, green), then alphabetically.
    ///
    /// `GET /reports/gauges.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_gauges(
        &self,
        params: &ListGaugesParams,
    ) -> Result<Page<ListGaugesResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_GAUGES, &[]);
        operation.query_optional("bucket_ids", params.bucket_ids.as_ref());
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Enable or disable the gauge for a project. Only project admins can toggle gauges.
    ///
    /// `PUT /projects/{projectId}/gauge.json` — idempotent; retries up to 2 attempt(s) on 429, 503.
    pub async fn toggle_gauge(
        &self,
        project_id: i64,
        body: &ToggleGaugeRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::TOGGLE_GAUGE, &[&project_id]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Update a gauge needle's description. Position and color are immutable.
    ///
    /// `PUT /gauge_needles/{needleId}` — idempotent; retries up to 2 attempt(s) on 429, 503.
    pub async fn update_gauge_needle(
        &self,
        needle_id: i64,
        body: &UpdateGaugeNeedleRequestContent,
    ) -> Result<UpdateGaugeNeedleResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_GAUGE_NEEDLE, &[&needle_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}