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.

//! Forwards 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 `ListForwards`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListForwardsParams {
    /// 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 `ListForwardReplies`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListForwardRepliesParams {
    /// 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>,
}

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

impl<'a> ForwardsService<'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 a forward by ID
    ///
    /// `GET /inbox_forwards/{forwardId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, forward_id: i64) -> Result<GetForwardResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_FORWARD, &[&forward_id]);
        self.client.send(operation).await
    }

    /// Get an inbox by ID
    ///
    /// `GET /inboxes/{inboxId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_inbox(&self, inbox_id: i64) -> Result<GetInboxResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_INBOX, &[&inbox_id]);
        self.client.send(operation).await
    }

    /// Get a forward reply by ID
    ///
    /// `GET /inbox_forwards/{forwardId}/replies/{replyId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_reply(
        &self,
        forward_id: i64,
        reply_id: i64,
    ) -> Result<GetForwardReplyResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_FORWARD_REPLY, &[&forward_id, &reply_id]);
        self.client.send(operation).await
    }

    /// List all forwards in an inbox
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /inboxes/{inboxId}/inbox_forwards.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list(
        &self,
        inbox_id: i64,
        params: &ListForwardsParams,
    ) -> Result<Page<ListForwardsResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::LIST_FORWARDS, &[&inbox_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 all replies to a forward
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /inbox_forwards/{forwardId}/replies.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_replies(
        &self,
        forward_id: i64,
        params: &ListForwardRepliesParams,
    ) -> Result<Page<ListForwardRepliesResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_FORWARD_REPLIES, &[&forward_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }
}