misskey_api/endpoint/admin/emoji/
add.rs1#[cfg(feature = "12-9-0")]
2use crate::model::drive::DriveFile;
3use crate::model::{emoji::Emoji, id::Id};
4
5use serde::{Deserialize, Serialize};
6use typed_builder::TypedBuilder;
7#[cfg(any(docsrs, not(feature = "12-9-0")))]
8use url::Url;
9
10#[derive(Serialize, Debug, Clone, TypedBuilder)]
11#[serde(rename_all = "camelCase")]
12#[builder(doc)]
13pub struct Request {
14 #[cfg(feature = "12-9-0")]
15 #[cfg_attr(docsrs, doc(cfg(feature = "12-9-0")))]
16 pub file_id: Id<DriveFile>,
17 #[cfg(any(docsrs, not(feature = "12-9-0")))]
18 #[cfg_attr(docsrs, doc(cfg(not(feature = "12-9-0"))))]
19 #[builder(setter(into))]
20 pub name: String,
21 #[cfg(any(docsrs, not(feature = "12-9-0")))]
22 #[cfg_attr(docsrs, doc(cfg(not(feature = "12-9-0"))))]
23 pub url: Url,
24 #[cfg(any(docsrs, not(feature = "12-9-0")))]
25 #[cfg_attr(docsrs, doc(cfg(not(feature = "12-9-0"))))]
26 #[serde(skip_serializing_if = "Option::is_none")]
27 #[builder(default, setter(strip_option, into))]
28 pub category: Option<String>,
29 #[cfg(any(docsrs, not(feature = "12-9-0")))]
30 #[cfg_attr(docsrs, doc(cfg(not(feature = "12-9-0"))))]
31 #[serde(skip_serializing_if = "Option::is_none")]
32 #[builder(default, setter(strip_option))]
33 pub aliases: Option<Vec<String>>,
34}
35
36#[derive(Deserialize, Debug, Clone)]
37#[serde(rename_all = "camelCase")]
38pub struct Response {
39 pub id: Id<Emoji>,
40}
41
42impl misskey_core::Request for Request {
43 type Response = Response;
44 const ENDPOINT: &'static str = "admin/emoji/add";
45}
46
47#[cfg(test)]
48mod tests {
49 use super::Request;
50 use crate::test::{ClientExt, TestClient};
51
52 #[cfg(not(feature = "12-9-0"))]
53 use ulid_crate::Ulid;
54
55 #[tokio::test]
56 #[cfg(feature = "12-9-0")]
57 async fn request() {
58 let client = TestClient::new();
59 let image_url = client.avatar_url().await;
60 let file = client.upload_from_url(image_url).await;
61 client.admin.test(Request { file_id: file.id }).await;
62 }
63
64 #[tokio::test]
65 #[cfg(not(feature = "12-9-0"))]
66 async fn request() {
67 let client = TestClient::new();
68 let image_url = client.avatar_url().await;
69 let name = Ulid::new().to_string();
70
71 client
72 .admin
73 .test(Request {
74 name,
75 url: image_url,
76 category: None,
77 aliases: None,
78 })
79 .await;
80 }
81
82 #[tokio::test]
83 #[cfg(not(feature = "12-9-0"))]
84 async fn request_with_options() {
85 let client = TestClient::new();
86 let image_url = client.avatar_url().await;
87 let name = Ulid::new().to_string();
88
89 client
90 .admin
91 .test(Request {
92 name,
93 url: image_url,
94 category: Some("nice".to_string()),
95 aliases: Some(vec!["test2".to_string()]),
96 })
97 .await;
98 }
99}