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.

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

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

impl<'a> BookmarksService<'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
    }

    /// Bookmark a recording for the current user.
    /// Idempotent: re-bookmarking returns the existing bookmark, never a duplicate.
    ///
    /// `POST /recordings/{recordingId}/bookmark.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn create_bookmark(
        &self,
        recording_id: i64,
    ) -> Result<CreateBookmarkResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::CREATE_BOOKMARK, &[&recording_id]);
        self.client.send(operation).await
    }

    /// Remove the current user's bookmark from a recording (returns 204 No Content).
    /// Idempotent: deleting an absent bookmark also returns 204.
    ///
    /// `DELETE /recordings/{recordingId}/bookmark.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn delete_bookmark(&self, recording_id: i64) -> Result<(), Error> {
        let operation = self
            .client
            .operation(&routes::DELETE_BOOKMARK, &[&recording_id]);
        self.client.send_unit(operation).await
    }

    /// Report whether the current user has bookmarked the recording.
    ///
    /// `GET /recordings/{recordingId}/bookmark.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_bookmark(
        &self,
        recording_id: i64,
    ) -> Result<GetBookmarkResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_BOOKMARK, &[&recording_id]);
        self.client.send(operation).await
    }

    /// List the current user's bookmarks, most recently bookmarked first (paginated).
    /// A bookmark is a personal link between the current user and a single recording,
    /// visible only to its creator; each entry wraps the shared recording projection.
    ///
    /// `GET /my/bookmarks.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_my_bookmarks(
        &self,
        params: &ListMyBookmarksParams,
    ) -> Result<Page<ListMyBookmarksResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_MY_BOOKMARKS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }
}