ruma_client_api/push/set_pushrule_enabled.rs
1//! `PUT /_matrix/client/*/pushrules/global/{kind}/{ruleId}/enabled`
2//!
3//! This endpoint allows clients to enable or disable the specified push rule.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixclientv3pushrulesglobalkindruleidenabled
9
10 use ruma_common::{
11 api::{request, response},
12 metadata,
13 };
14
15 use crate::push::RuleKind;
16
17 metadata! {
18 method: PUT,
19 rate_limited: false,
20 authentication: AccessToken,
21 history: {
22 1.0 => "/_matrix/client/r0/pushrules/global/{kind}/{rule_id}/enabled",
23 1.1 => "/_matrix/client/v3/pushrules/global/{kind}/{rule_id}/enabled",
24 }
25 }
26
27 /// Request type for the `set_pushrule_enabled` endpoint.
28 #[request(error = crate::Error)]
29 pub struct Request {
30 /// The kind of rule
31 #[ruma_api(path)]
32 pub kind: RuleKind,
33
34 /// The identifier for the rule.
35 #[ruma_api(path)]
36 pub rule_id: String,
37
38 /// Whether the push rule is enabled or not.
39 pub enabled: bool,
40 }
41
42 /// Response type for the `set_pushrule_enabled` endpoint.
43 #[response(error = crate::Error)]
44 #[derive(Default)]
45 pub struct Response {}
46
47 impl Request {
48 /// Creates a new `Request` with the given rule kind, rule ID and enabled flag.
49 pub fn new(kind: RuleKind, rule_id: String, enabled: bool) -> Self {
50 Self { kind, rule_id, enabled }
51 }
52
53 /// Creates a new `Request` to enable the given rule.
54 pub fn enable(kind: RuleKind, rule_id: String) -> Self {
55 Self::new(kind, rule_id, true)
56 }
57
58 /// Creates a new `Request` to disable the given rule.
59 pub fn disable(kind: RuleKind, rule_id: String) -> Self {
60 Self::new(kind, rule_id, false)
61 }
62 }
63
64 impl Response {
65 /// Creates an empty `Response`.
66 pub fn new() -> Self {
67 Self {}
68 }
69 }
70}