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.

//! Embeds 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::*;

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

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

    /// Create an embed for a URL, or return the one Basecamp already has for it.
    ///
    /// Answers `200 OK` with the embed either way. A new embed's status is
    /// `pending`; get it about once a second until its status is `active` or
    /// `not_found`.
    ///
    /// Answers `422` (`{"error": "Basecamp can't embed this URL. Link to it
    /// instead."}`) for a URL no provider embeds. Past 100 new embeds in an hour,
    /// creating another answers `429` (`{"error": "Too many new embeds. Try again
    /// later."}`) with no Retry-After; asking for an embed Basecamp already has
    /// still works. That 429 is a verdict for the rest of the hour, not
    /// throttling, so this operation declares `retryOn: \[503\]` and the 429
    /// surfaces on the first attempt.
    ///
    /// `POST /embeds.json` — idempotent; retries up to 3 attempt(s) on 503.
    pub async fn create(
        &self,
        body: &CreateEmbedRequestContent,
    ) -> Result<CreateEmbedResponseContent, Error> {
        let mut operation = self.client.operation(&routes::CREATE_EMBED, &[]);
        operation.json(body)?;
        self.client.send(operation).await
    }

    /// Get an embed by its sgid.
    ///
    /// Answers `404 Not Found` for an sgid that does not name an embed.
    ///
    /// `GET /embeds/{sgid}` — idempotent; retries up to 3 attempt(s) on 429, 503.
    pub async fn get(&self, sgid: &str) -> Result<GetEmbedResponseContent, Error> {
        let operation = self.client.operation(&routes::GET_EMBED, &[&sgid]);
        self.client.send(operation).await
    }
}