client-api: Use an enum for the scope of the push rule endpoints
This commit is contained in:
parent
b2d52680af
commit
f31530e02c
@ -11,6 +11,7 @@ Breaking changes:
|
||||
* Move `push::get_pushers::v3::Pusher` to `push` and make it use the new `PusherIds` type
|
||||
* Remove `push::set_pusher::v3::Pusher` and use the common type instead
|
||||
* Make `push::PusherKind` contain the pusher's `data`
|
||||
* Use an enum for the `scope` of the `push` endpoints
|
||||
|
||||
Improvements:
|
||||
|
||||
|
@ -284,3 +284,16 @@ pub struct CustomPusherData {
|
||||
kind: String,
|
||||
data: JsonObject,
|
||||
}
|
||||
|
||||
/// The scope of a push rule.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||
#[ruma_enum(rename_all = "lowercase")]
|
||||
#[non_exhaustive]
|
||||
pub enum RuleScope {
|
||||
/// The global rules.
|
||||
Global,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
||||
|
||||
use ruma_common::api::ruma_api;
|
||||
|
||||
use crate::push::RuleKind;
|
||||
use crate::push::{RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,9 +22,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to delete from. 'global' to specify global rules.
|
||||
/// The scope to delete from.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule
|
||||
#[ruma_api(path)]
|
||||
@ -43,7 +43,7 @@ pub mod v3 {
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, kind and rule ID.
|
||||
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
Self { scope, kind, rule_id }
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
||||
|
||||
use ruma_common::api::ruma_api;
|
||||
|
||||
use crate::push::{PushRule, RuleKind};
|
||||
use crate::push::{PushRule, RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,9 +22,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to fetch rules from. 'global' to specify global rules.
|
||||
/// The scope to fetch rules from.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule.
|
||||
#[ruma_api(path)]
|
||||
@ -46,7 +46,7 @@ pub mod v3 {
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, rule kind and rule ID.
|
||||
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
Self { scope, kind, rule_id }
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
||||
|
||||
use ruma_common::{api::ruma_api, push::Action};
|
||||
|
||||
use crate::push::RuleKind;
|
||||
use crate::push::{RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,9 +22,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
||||
/// The scope to fetch a rule from.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule
|
||||
#[ruma_api(path)]
|
||||
@ -45,7 +45,7 @@ pub mod v3 {
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, kind and rule ID.
|
||||
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
Self { scope, kind, rule_id }
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
||||
|
||||
use ruma_common::api::ruma_api;
|
||||
|
||||
use crate::push::RuleKind;
|
||||
use crate::push::{RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,9 +22,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
||||
/// The scope to fetch a rule from.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule
|
||||
#[ruma_api(path)]
|
||||
@ -45,7 +45,7 @@ pub mod v3 {
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, rule kind and rule ID.
|
||||
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
Self { scope, kind, rule_id }
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ pub mod v3 {
|
||||
push::{Action, PushCondition},
|
||||
};
|
||||
|
||||
use crate::push::RuleKind;
|
||||
use crate::push::{RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -25,9 +25,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to set the rule in. 'global' to specify global rules.
|
||||
/// The scope to set the rule in.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule
|
||||
#[ruma_api(path)]
|
||||
@ -74,7 +74,7 @@ pub mod v3 {
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, rule kind, rule ID and actions.
|
||||
pub fn new(
|
||||
scope: &'a str,
|
||||
scope: RuleScope,
|
||||
kind: RuleKind,
|
||||
rule_id: &'a str,
|
||||
actions: &'a [Action],
|
||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
||||
|
||||
use ruma_common::{api::ruma_api, push::Action};
|
||||
|
||||
use crate::push::RuleKind;
|
||||
use crate::push::{RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,9 +22,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
||||
/// The scope to fetch a rule from.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule
|
||||
#[ruma_api(path)]
|
||||
@ -46,7 +46,12 @@ pub mod v3 {
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, rule kind, rule ID and actions.
|
||||
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str, actions: Vec<Action>) -> Self {
|
||||
pub fn new(
|
||||
scope: RuleScope,
|
||||
kind: RuleKind,
|
||||
rule_id: &'a str,
|
||||
actions: Vec<Action>,
|
||||
) -> Self {
|
||||
Self { scope, kind, rule_id, actions }
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
||||
|
||||
use ruma_common::api::ruma_api;
|
||||
|
||||
use crate::push::RuleKind;
|
||||
use crate::push::{RuleKind, RuleScope};
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
@ -22,9 +22,9 @@ pub mod v3 {
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
||||
/// The scope to fetch a rule from.
|
||||
#[ruma_api(path)]
|
||||
pub scope: &'a str,
|
||||
pub scope: RuleScope,
|
||||
|
||||
/// The kind of rule
|
||||
#[ruma_api(path)]
|
||||
@ -46,17 +46,17 @@ pub mod v3 {
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Creates a new `Request` with the given scope, rule kind, rule ID and enabled flag.
|
||||
pub fn new(scope: &'a str, kind: RuleKind, rule_id: &'a str, enabled: bool) -> Self {
|
||||
pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str, enabled: bool) -> Self {
|
||||
Self { scope, kind, rule_id, enabled }
|
||||
}
|
||||
|
||||
/// Creates a new `Request` to enable the given rule.
|
||||
pub fn enable(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
pub fn enable(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
Self::new(scope, kind, rule_id, true)
|
||||
}
|
||||
|
||||
/// Creates a new `Request` to disable the given rule.
|
||||
pub fn disable(scope: &'a str, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
pub fn disable(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self {
|
||||
Self::new(scope, kind, rule_id, false)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user