hey-sdk 0.30.0

Rust client for the HEY API, generated from a Smithy model of the API
Documentation
// Generated by hey-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.

#![allow(clippy::too_many_arguments)]

use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
use crate::pagination::Page;

/// Optional query parameters for `GetBoxPostingChanges`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetBoxPostingChangesParams {
    pub v: Option<String>,
    pub page: Option<String>,
    pub per_page: Option<String>,
}

/// Optional query parameters for `GetBundleUnseenPostings`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct GetBundleUnseenPostingsParams {
    pub page: Option<String>,
}

/// Optional query parameters for `UnfilePostings`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct UnfilePostingsParams {
    pub folder_id: Option<i64>,
}

pub struct Postings<'a> {
    client: &'a Client,
}

impl<'a> Postings<'a> {
    pub(crate) fn new(client: &'a Client) -> Self {
        Self { client }
    }

    /// The client this service sends through.
    pub fn client(&self) -> &'a Client {
        self.client
    }

    /// Add a selection of postings to a Set Aside group
    pub async fn add_to_box_group(
        &self,
        body: &AddPostingsToBoxGroupRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::ADD_POSTINGS_TO_BOX_GROUP, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Bubble a selection of postings up right now
    pub async fn bubble_up_now(&self, body: &MarkPostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::BUBBLE_UP_POSTINGS_NOW, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Cancel a scheduled bubble up for a selection of postings
    pub async fn cancel_bubble_up(&self, posting_ids: &str) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::CANCEL_POSTINGS_BUBBLE_UP, &[]);
        operation.query("posting_ids", posting_ids);
        self.client.send_unit(operation).await
    }

    /// Create a folder (label) and file a selection of postings into it
    pub async fn create_folder(
        &self,
        body: &CreateFolderForPostingsRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::CREATE_FOLDER_FOR_POSTINGS, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// File a selection of postings into an existing folder (label)
    pub async fn file(&self, body: &FilePostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::FILE_POSTINGS, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Read what changed among a box's postings since a point in time.
    ///
    /// This is the incremental sync feed the mail clients follow rather than re-reading a
    /// box. `since` is an ISO 8601 timestamp with milliseconds and is exclusive, and `v` is
    /// the client's contract version — the server answers 409 when the caller is too far
    /// behind for an increment to carry the difference, which means read the box in full
    /// instead. A box's own `posting_changes_url` carries the `since` and `v` to start from,
    /// and the `Link` header names the next page while one remains and the next `since`
    /// cursor on the last page.
    pub async fn get_box_changes(
        &self,
        box_id: i64,
        since: &str,
        params: &GetBoxPostingChangesParams,
    ) -> Result<Page<GetBoxPostingChangesResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_BOX_POSTING_CHANGES, &[&box_id]);
        operation.resource_id(box_id);
        operation.query("since", since);
        operation.query_optional("v", params.v.as_ref());
        operation.query_optional("page", params.page.as_ref());
        operation.query_optional("per_page", params.per_page.as_ref());
        self.client.send_page(operation).await
    }

    /// List the unseen postings inside a bundle posting.
    ///
    /// A bundle posting groups one contact's unseen mail; this is its contents — the member
    /// postings, newest first, paged by cursor like a box. The posting must be a bundle.
    pub async fn get_bundle_unseen(
        &self,
        posting_id: i64,
        params: &GetBundleUnseenPostingsParams,
    ) -> Result<Page<GetBundleUnseenPostingsResponseContent>, Error> {
        let mut operation = self
            .client
            .operation(&routes::GET_BUNDLE_UNSEEN_POSTINGS, &[&posting_id]);
        operation.resource_id(posting_id);
        operation.query_optional("page", params.page.as_ref());
        self.client.send_page(operation).await
    }

    /// Mark postings as seen
    pub async fn mark_seen(&self, body: &MarkPostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MARK_POSTINGS_SEEN, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Mark a selection of postings as spam.
    ///
    /// Over ten postings the server hands the work to a background job, so the effect is
    /// eventually consistent.
    pub async fn mark_spam(&self, body: &MarkPostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MARK_POSTINGS_SPAM, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Mark postings as unseen
    pub async fn mark_unseen(&self, body: &MarkPostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MARK_POSTINGS_UNSEEN, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Move postings to a box (bulk).
    /// Mirrors HEY's Postings::MovesController: `posting_ids` plus the target `box_id`
    /// (an ID from ListBoxes; the box `kind` field identifies imbox, feedbox, asidebox,
    /// laterbox, trailbox). Responds 204 No Content.
    pub async fn move_postings(&self, body: &MovePostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MOVE_POSTINGS, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Mute postings (bulk) — stop notifications for their threads.
    /// Mirrors HEY's Postings::MutingsController#create. Responds 201 Created.
    pub async fn mute(&self, body: &MarkPostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::MUTE_POSTINGS, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Remove a selection of postings from their Set Aside group
    pub async fn remove_from_box_group(&self, posting_ids: &str) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::REMOVE_POSTINGS_FROM_BOX_GROUP, &[]);
        operation.query("posting_ids", posting_ids);
        self.client.send_unit(operation).await
    }

    /// Schedule a selection of postings to bubble up.
    ///
    /// HEY's scheduler takes a `slot` — today, tomorrow, weekend, next_week, surprise_me
    /// or custom — and a custom slot also carries the `date` (YYYY-MM-DD) to bubble up on,
    /// at HEY's morning hour. The today slot lands at HEY's evening hour of the current
    /// day instead, and both hours are UTC over JSON. An unknown slot, or a custom slot
    /// without a date, is a server error rather than a validation response, so callers
    /// check both first. Responds 201 Created.
    pub async fn schedule_bubble_up(
        &self,
        body: &SchedulePostingsBubbleUpRequestContent,
    ) -> Result<(), Error> {
        let mut operation = self
            .client
            .operation(&routes::SCHEDULE_POSTINGS_BUBBLE_UP, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Move postings to the trash (bulk).
    /// Mirrors HEY's Postings::TrashController. For JSON requests the server treats
    /// the removal decision as made (shared topics: your access is removed).
    /// Responds 204 No Content.
    pub async fn trash(&self, body: &TrashPostingsRequestContent) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::TRASH_POSTINGS, &[]);
        operation.json(body)?;
        self.client.send_unit(operation).await
    }

    /// Remove a selection of postings from a folder, or from every folder when folder_id is omitted
    pub async fn unfile(
        &self,
        posting_ids: &str,
        params: &UnfilePostingsParams,
    ) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::UNFILE_POSTINGS, &[]);
        operation.query("posting_ids", posting_ids);
        operation.query_optional("folder_id", params.folder_id.as_ref());
        self.client.send_unit(operation).await
    }

    /// Unmute postings (bulk).
    /// Mirrors HEY's Postings::MutingsController#destroy. `posting_ids` is sent as a
    /// comma-separated query string because DELETE carries no body. Responds 201 Created.
    pub async fn unmute(&self, posting_ids: &str) -> Result<(), Error> {
        let mut operation = self.client.operation(&routes::UNMUTE_POSTINGS, &[]);
        operation.query("posting_ids", posting_ids);
        self.client.send_unit(operation).await
    }
}