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.

//! Checkins 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 `GetAnswersByPerson`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetAnswersByPersonParams {
    /// 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 `ListAnswers`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListAnswersParams {
    /// 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 `ListQuestions`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListQuestionsParams {
    /// 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 `GetQuestionReminders`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetQuestionRemindersParams {
    /// 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>,
}

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

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

    /// List all people who have answered a question (answerers)
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages.
    ///
    /// `GET /questions/{questionId}/answers/by.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn answerers(
        &self,
        question_id: i64,
    ) -> Result<Page<ListQuestionAnswerersResponseContent>, Error> {
        let operation = self
            .client
            .operation(&routes::LIST_QUESTION_ANSWERERS, &[&question_id]);
        self.client.send_page(operation).await
    }

    /// Get all answers from a specific person for a question
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages.
    ///
    /// `GET /questions/{questionId}/answers/by/{personId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn by_person(
        &self,
        question_id: i64,
        person_id: i64,
        params: &GetAnswersByPersonParams,
    ) -> Result<Page<GetAnswersByPersonResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_ANSWERS_BY_PERSON, &[&question_id, &person_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Create a new answer for a question
    ///
    /// `POST /questions/{questionId}/answers.json` — not idempotent, sent exactly once.
    pub async fn create_answer(
        &self,
        question_id: i64,
        body: &QuestionAnswerPayload,
    ) -> Result<CreateAnswerResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_ANSWER, &[&question_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Create a new question in a questionnaire
    ///
    /// `POST /questionnaires/{questionnaireId}/questions.json` — not idempotent, sent exactly once.
    pub async fn create_question(
        &self,
        questionnaire_id: i64,
        body: &CreateQuestionRequestContent,
    ) -> Result<CreateQuestionResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_QUESTION, &[&questionnaire_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Get a single answer by id
    ///
    /// `GET /question_answers/{answerId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_answer(&self, answer_id: i64) -> Result<GetAnswerResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_ANSWER, &[&answer_id]);
        self.client.send(operation).await
    }

    /// Get a single question by id
    ///
    /// `GET /questions/{questionId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_question(
        &self,
        question_id: i64,
    ) -> Result<GetQuestionResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_QUESTION, &[&question_id]);
        self.client.send(operation).await
    }

    /// Get a questionnaire (automatic check-ins container) by id
    ///
    /// `GET /questionnaires/{questionnaireId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get_questionnaire(
        &self,
        questionnaire_id: i64,
    ) -> Result<GetQuestionnaireResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::GET_QUESTIONNAIRE, &[&questionnaire_id]);
        self.client.send(operation).await
    }

    /// List all answers for a question
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /questions/{questionId}/answers.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_answers(
        &self,
        question_id: i64,
        params: &ListAnswersParams,
    ) -> Result<Page<ListAnswersResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_ANSWERS, &[&question_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// List all questions in a questionnaire
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages. X-Total-Count header provides total count.
    ///
    /// `GET /questionnaires/{questionnaireId}/questions.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn list_questions(
        &self,
        questionnaire_id: i64,
        params: &ListQuestionsParams,
    ) -> Result<Page<ListQuestionsResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::LIST_QUESTIONS, &[&questionnaire_id]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Pause a check-in question (stops sending reminders)
    ///
    /// `POST /questions/{questionId}/pause.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn pause(&self, question_id: i64) -> Result<PauseQuestionResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::PAUSE_QUESTION, &[&question_id]);
        self.client.send(operation).await
    }

    /// Get pending check-in reminders for the current user
    ///
    /// Returns questions that are pending a response from the authenticated user.
    ///
    /// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
    /// to fetch additional pages.
    ///
    /// `GET /my/question_reminders.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn reminders(
        &self,
        params: &GetQuestionRemindersParams,
    ) -> Result<Page<GetQuestionRemindersResponseContent>, Error> {
        let mut operation = self.client.operation(&routes::GET_QUESTION_REMINDERS, &[]);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Resume a paused check-in question (resumes sending reminders)
    ///
    /// `DELETE /questions/{questionId}/pause.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn resume(&self, question_id: i64) -> Result<ResumeQuestionResponseContent, Error> {
        let operation = self
            .client
            .operation(&routes::RESUME_QUESTION, &[&question_id]);
        self.client.send(operation).await
    }

    /// Update an existing answer
    ///
    /// `PUT /question_answers/{answerId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_answer(
        &self,
        answer_id: i64,
        body: &QuestionAnswerUpdatePayload,
    ) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::UPDATE_ANSWER, &[&answer_id]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Update notification settings for a check-in question
    ///
    /// `PUT /questions/{questionId}/notification_settings.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_notification_settings(
        &self,
        question_id: i64,
        body: &UpdateQuestionNotificationSettingsRequestContent,
    ) -> Result<UpdateQuestionNotificationSettingsResponseContent, Error> {
        let mut operation = self.client.operation(
            &routes::UPDATE_QUESTION_NOTIFICATION_SETTINGS,
            &[&question_id],
        );
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Update an existing question's title, schedule or both. A schedule replaces the whole schedule, so send every part of it: one without frequency or time_of_day is refused, and one without start_date re-anchors the recurrence on today. Pausing and resuming are PauseQuestion and ResumeQuestion.
    ///
    /// `PUT /questions/{questionId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn update_question(
        &self,
        question_id: i64,
        body: &UpdateQuestionRequestContent,
    ) -> Result<UpdateQuestionResponseContent, Error> {
        let mut operation = self
            .client
            .operation(&routes::UPDATE_QUESTION, &[&question_id]);
        operation.json(body)?;
        self.client.send(operation).await
    }
}