misskey_util/builder/
clip.rs

1use crate::Error;
2
3use misskey_api::endpoint;
4use misskey_api::model::clip::Clip;
5use misskey_core::Client;
6
7/// Builder for the [`build_clip`][`crate::ClientExt::build_clip`] method.
8pub struct ClipBuilder<C> {
9    client: C,
10    request: endpoint::clips::create::Request,
11}
12
13#[cfg(feature = "12-57-0")]
14#[cfg_attr(docsrs, doc(cfg(feature = "12-57-0")))]
15impl<C> ClipBuilder<C> {
16    /// Creates a builder with the client.
17    pub fn new(client: C) -> Self {
18        let request = endpoint::clips::create::Request {
19            name: String::default(),
20            is_public: Some(false),
21            description: None,
22        };
23        ClipBuilder { client, request }
24    }
25
26    /// Gets the request object for reuse.
27    pub fn as_request(&self) -> &endpoint::clips::create::Request {
28        &self.request
29    }
30
31    /// Sets the name of the clip.
32    pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
33        self.request.name = name.into();
34        self
35    }
36
37    /// Sets whether the clip is public or not.
38    pub fn public(&mut self, public: bool) -> &mut Self {
39        self.request.is_public.replace(public);
40        self
41    }
42
43    /// Sets the description of the clip.
44    pub fn description(&mut self, description: impl Into<String>) -> &mut Self {
45        self.request.description.replace(description.into());
46        self
47    }
48}
49
50impl<C: Client> ClipBuilder<C> {
51    /// Creates the clip.
52    pub async fn create(&self) -> Result<Clip, Error<C::Error>> {
53        let clip = self
54            .client
55            .request(&self.request)
56            .await
57            .map_err(Error::Client)?
58            .into_result()?;
59        Ok(clip)
60    }
61}
62
63/// Builder for the [`update_clip`][`crate::ClientExt::update_clip`] method.
64pub struct ClipUpdateBuilder<C> {
65    client: C,
66    request: endpoint::clips::update::Request,
67}
68
69#[cfg(feature = "12-57-0")]
70#[cfg_attr(docsrs, doc(cfg(feature = "12-57-0")))]
71impl<C> ClipUpdateBuilder<C> {
72    /// Creates a builder with the client and the clip you are going to update.
73    pub fn new(client: C, clip: Clip) -> Self {
74        let Clip {
75            id,
76            name,
77            is_public,
78            description,
79            ..
80        } = clip;
81        let request = endpoint::clips::update::Request {
82            clip_id: id,
83            name,
84            is_public,
85            description,
86        };
87        ClipUpdateBuilder { client, request }
88    }
89
90    /// Gets the request object for reuse.
91    pub fn as_request(&self) -> &endpoint::clips::update::Request {
92        &self.request
93    }
94
95    /// Sets the name of the clip.
96    pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
97        self.request.name = name.into();
98        self
99    }
100
101    /// Sets whether the clip is public or not.
102    pub fn public(&mut self, public: bool) -> &mut Self {
103        self.request.is_public = public;
104        self
105    }
106
107    /// Sets the description of the clip.
108    pub fn description(&mut self, description: impl Into<String>) -> &mut Self {
109        self.request.description.replace(description.into());
110        self
111    }
112}
113
114impl<C: Client> ClipUpdateBuilder<C> {
115    /// Updates the clip.
116    pub async fn update(&self) -> Result<Clip, Error<C::Error>> {
117        let clip = self
118            .client
119            .request(&self.request)
120            .await
121            .map_err(Error::Client)?
122            .into_result()?;
123        Ok(clip)
124    }
125}