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.

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

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

impl<'a> SubscriptionsService<'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 subscription information for a recording
    ///
    /// `GET /recordings/{recordingId}/subscription.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, recording_id: i64) -> Result<GetSubscriptionResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_SUBSCRIPTION, &[&recording_id]);
        self.client.send(operation).await
    }

    /// Subscribe the current user to a recording
    ///
    /// `POST /recordings/{recordingId}/subscription.json` — idempotent; retries up to 2 attempt(s) on 429, 503.
    pub async fn subscribe(&self, recording_id: i64) -> Result<SubscribeResponseContent, Error> {
        let operation = self.client.operation(&routes::SUBSCRIBE, &[&recording_id]);
        self.client.send(operation).await
    }

    /// Unsubscribe the current user from a recording
    ///
    /// `DELETE /recordings/{recordingId}/subscription.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn unsubscribe(&self, recording_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::UNSUBSCRIBE, &[&recording_id]);
        self.client.send_unit(operation).await
    }

    /// Update subscriptions by adding or removing specific users
    ///
    /// `PUT /recordings/{recordingId}/subscription.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update(
        &self,
        recording_id: i64,
        body: &UpdateSubscriptionRequestContent,
    ) -> Result<UpdateSubscriptionResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_SUBSCRIPTION, &[&recording_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}