ruma_client_api/delayed_events/
update_delayed_event.rs1pub mod unstable {
7 use ruma_common::{
12 api::{request, response, Metadata},
13 metadata,
14 serde::StringEnum,
15 };
16
17 use crate::PrivOwnedStr;
18
19 const METADATA: Metadata = metadata! {
20 method: POST,
21 rate_limited: true,
22 authentication: AccessToken,
23 history: {
24 unstable("org.matrix.msc4140") => "/_matrix/client/unstable/org.matrix.msc4140/delayed_events/{delay_id}",
25 }
26 };
27
28 #[derive(Clone, StringEnum)]
30 #[ruma_enum(rename_all = "lowercase")]
31 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
32 pub enum UpdateAction {
33 Restart,
35 Send,
38 Cancel,
40
41 #[doc(hidden)]
42 _Custom(PrivOwnedStr),
43 }
44 #[request(error = crate::Error)]
47 pub struct Request {
48 #[ruma_api(path)]
50 pub delay_id: String,
51 pub action: UpdateAction,
53 }
54
55 impl Request {
56 pub fn new(delay_id: String, action: UpdateAction) -> Self {
58 Self { delay_id, action }
59 }
60 }
61
62 #[response(error = crate::Error)]
65 pub struct Response {}
66 impl Response {
67 pub fn new() -> Self {
70 Self {}
71 }
72 }
73
74 #[cfg(all(test, feature = "client"))]
75 mod tests {
76 use ruma_common::api::{
77 MatrixVersion, OutgoingRequest, SendAccessToken, SupportedVersions,
78 };
79 use serde_json::{json, Value as JsonValue};
80
81 use super::{Request, UpdateAction};
82 #[test]
83 fn serialize_update_delayed_event_request() {
84 let supported = SupportedVersions {
85 versions: [MatrixVersion::V1_1].into(),
86 features: Default::default(),
87 };
88 let request: http::Request<Vec<u8>> =
89 Request::new("1234".to_owned(), UpdateAction::Cancel)
90 .try_into_http_request(
91 "https://homeserver.tld",
92 SendAccessToken::IfRequired("auth_tok"),
93 &supported,
94 )
95 .unwrap();
96
97 let (parts, body) = request.into_parts();
98
99 assert_eq!(
100 "https://homeserver.tld/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234",
101 parts.uri.to_string()
102 );
103 assert_eq!("POST", parts.method.to_string());
104 assert_eq!(
105 json!({"action": "cancel"}),
106 serde_json::from_str::<JsonValue>(std::str::from_utf8(&body).unwrap()).unwrap()
107 );
108 }
109 }
110}