jmap_client/blob/
helpers.rs

1/*
2 * Copyright Stalwart Labs Ltd. See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12use crate::{
13    client::Client,
14    core::request::{Arguments, Request},
15    Method,
16};
17
18use super::copy::{CopyBlobRequest, CopyBlobResponse};
19
20impl Client {
21    #[maybe_async::maybe_async]
22    pub async fn blob_copy(
23        &self,
24        from_account_id: impl Into<String>,
25        blob_id: impl Into<String>,
26    ) -> crate::Result<String> {
27        let blob_id = blob_id.into();
28        let mut request = self.build();
29        request.copy_blob(from_account_id).blob_id(&blob_id);
30        request
31            .send_single::<CopyBlobResponse>()
32            .await?
33            .copied(&blob_id)
34    }
35}
36
37impl Request<'_> {
38    #[maybe_async::maybe_async]
39    pub fn copy_blob(&mut self, from_account_id: impl Into<String>) -> &mut CopyBlobRequest {
40        self.add_method_call(
41            Method::CopyBlob,
42            Arguments::blob_copy(self.params(Method::CopyBlob), from_account_id.into()),
43        )
44        .blob_copy_mut()
45    }
46
47    #[maybe_async::maybe_async]
48    pub async fn send_copy_blob(self) -> crate::Result<CopyBlobResponse> {
49        self.send_single().await
50    }
51}