ruma_client_api/delayed_events/
update_delayed_event.rs1pub mod unstable {
7 use ruma_common::{
12 api::{auth_scheme::AccessToken, request, response},
13 metadata,
14 serde::StringEnum,
15 };
16
17 use crate::PrivOwnedStr;
18
19 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 std::borrow::Cow;
77
78 use ruma_common::api::{
79 auth_scheme::SendAccessToken, MatrixVersion, OutgoingRequest, SupportedVersions,
80 };
81 use serde_json::{json, Value as JsonValue};
82
83 use super::{Request, UpdateAction};
84 #[test]
85 fn serialize_update_delayed_event_request() {
86 let supported = SupportedVersions {
87 versions: [MatrixVersion::V1_1].into(),
88 features: Default::default(),
89 };
90 let request: http::Request<Vec<u8>> =
91 Request::new("1234".to_owned(), UpdateAction::Cancel)
92 .try_into_http_request(
93 "https://homeserver.tld",
94 SendAccessToken::IfRequired("auth_tok"),
95 Cow::Owned(supported),
96 )
97 .unwrap();
98
99 let (parts, body) = request.into_parts();
100
101 assert_eq!(
102 "https://homeserver.tld/_matrix/client/unstable/org.matrix.msc4140/delayed_events/1234",
103 parts.uri.to_string()
104 );
105 assert_eq!("POST", parts.method.to_string());
106 assert_eq!(
107 json!({"action": "cancel"}),
108 serde_json::from_str::<JsonValue>(std::str::from_utf8(&body).unwrap()).unwrap()
109 );
110 }
111 }
112}