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.

//! Reports 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 `GetAssignedTodos`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetAssignedTodosParams {
    /// Group by "bucket" or "date"
    pub group_by: Option<String>,
}

/// Optional query parameters for `GetOverdueTodos`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetOverdueTodosParams {
    /// Page number for paginating through results. Defaults to 1. This
    /// operation is not auto-paginated in any SDK, so a page is returned as
    /// asked for and later pages are not followed.
    pub page: Option<i32>,
}

/// Optional query parameters for `GetPersonProgress`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetPersonProgressParams {
    /// 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 `GetProgressReport`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetProgressReportParams {
    /// 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>,
}

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

impl<'a> ReportsService<'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 todos assigned to a specific person
    ///
    /// `GET /reports/todos/assigned/{personId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn assigned(
        &self,
        person_id: i64,
        params: &GetAssignedTodosParams,
    ) -> Result<GetAssignedTodosResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_ASSIGNED_TODOS, &[&person_id]);
        operation.query_optional("group_by", params.group_by.as_ref());
        self.client.send(operation).await
    }

    /// Get one page of overdue todos grouped by lateness, latest first.
    ///
    /// Pages hold 15, 30, 50, then 100 to-dos, and each page fills the same four
    /// groups with only its own to-dos, so a group can continue onto the next
    /// page. A `Link: rel="next"` header names the next page and `X-Total-Count`
    /// the total. This operation is not auto-paginated in any SDK: the response
    /// is an object of four arrays, which no pagination key can name.
    ///
    /// `GET /reports/todos/overdue.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn overdue(
        &self,
        params: &GetOverdueTodosParams,
    ) -> Result<GetOverdueTodosResponseContent, Error> {
        let mut operation = self.client.operation(&routes::GET_OVERDUE_TODOS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send(operation).await
    }

    /// Get a person's activity timeline
    ///
    /// Each page is the envelope; its `events` member is the collection, which [`AccountClient::collect_all`] and [`AccountClient::items`] gather across pages. The other members are on every page: read them off the first.
    ///
    /// `GET /reports/users/progress/{personId}.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn person_progress(
        &self,
        person_id: i64,
        params: &GetPersonProgressParams,
    ) -> Result<Page<GetPersonProgressResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_PERSON_PROGRESS, &[&person_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Get account-wide activity feed (progress report)
    ///
    /// `GET /reports/progress.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn progress(
        &self,
        params: &GetProgressReportParams,
    ) -> Result<Page<GetProgressReportResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_PROGRESS_REPORT, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Get upcoming schedule entries and assignable items within a date window.
    /// This endpoint is preserved as the canonical API path on BC5;
    /// the BC5 `/calendar` web view is HTML-only.
    ///
    /// The three arrays carry the report's own reduced projections —
    /// UpcomingScheduleEntry and UpcomingAssignable — not the shared ScheduleEntry
    /// and Todo/Card shapes. BC3 renders this report through
    /// `app/views/api/schedules/calendar/_entry.json.jbuilder` and
    /// `_assignable.json.jbuilder`, which emit a narrower key set than the
    /// per-resource partials, plus keys those partials never emit. See
    /// UpcomingScheduleEntry for the full accounting.
    ///
    /// `GET /reports/schedules/upcoming.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn upcoming(
        &self,
        window_starts_on: &str,
        window_ends_on: &str,
    ) -> Result<GetUpcomingScheduleResponseContent, Error> {
        let mut operation = self.client.operation(&routes::GET_UPCOMING_SCHEDULE, &[]);
        operation.query("window_starts_on", window_starts_on);
        operation.query("window_ends_on", window_ends_on);
        self.client.send(operation).await
    }
}