Skip to main content

hey_sdk/services/
clips.rs

1//! Saving and throwing away clips, on top of the generated clip route.
2//!
3//! Clips have no JSON surface for writes: a write answers with a Turbo Stream rather than a
4//! record, so both of them are browser form posts.
5
6use crate::error::Error;
7use crate::http::Method;
8use crate::services::write_info;
9
10pub use crate::generated::services::clips::*;
11
12impl Clips<'_> {
13    /// Clips a piece of an entry, so it can be found again without the thread.
14    pub async fn create(&self, entry_id: i64, content: &str) -> Result<(), Error> {
15        let entry = entry_id.to_string();
16        let mut operation = self.client().form(Method::POST, "/clips")?;
17        operation.info(write_info("Clips", "CreateClip", "clip", Some(entry_id)));
18        operation.form(&[
19            ("clip[entry_id]", entry.as_str()),
20            ("clip[content]", content),
21        ]);
22        self.client().send_unit(operation).await
23    }
24
25    /// Throws a clip away.
26    pub async fn delete(&self, clip_id: i64) -> Result<(), Error> {
27        let mut operation = self
28            .client()
29            .form(Method::DELETE, &format!("/clips/{clip_id}"))?;
30        operation.info(write_info("Clips", "DeleteClip", "clip", Some(clip_id)));
31        self.client().send_unit(operation).await
32    }
33}