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
|
* 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
|
* Remove `push::set_pusher::v3::Pusher` and use the common type instead
|
||||||
* Make `push::PusherKind` contain the pusher's `data`
|
* Make `push::PusherKind` contain the pusher's `data`
|
||||||
|
* Use an enum for the `scope` of the `push` endpoints
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -284,3 +284,16 @@ pub struct CustomPusherData {
|
|||||||
kind: String,
|
kind: String,
|
||||||
data: JsonObject,
|
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 ruma_common::api::ruma_api;
|
||||||
|
|
||||||
use crate::push::RuleKind;
|
use crate::push::{RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,9 +22,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to delete from. 'global' to specify global rules.
|
/// The scope to delete from.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule
|
/// The kind of rule
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -43,7 +43,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, kind and rule ID.
|
/// 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 }
|
Self { scope, kind, rule_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
use ruma_common::api::ruma_api;
|
use ruma_common::api::ruma_api;
|
||||||
|
|
||||||
use crate::push::{PushRule, RuleKind};
|
use crate::push::{PushRule, RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,9 +22,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to fetch rules from. 'global' to specify global rules.
|
/// The scope to fetch rules from.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule.
|
/// The kind of rule.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -46,7 +46,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, rule kind and rule ID.
|
/// 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 }
|
Self { scope, kind, rule_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
use ruma_common::{api::ruma_api, push::Action};
|
use ruma_common::{api::ruma_api, push::Action};
|
||||||
|
|
||||||
use crate::push::RuleKind;
|
use crate::push::{RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,9 +22,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
/// The scope to fetch a rule from.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule
|
/// The kind of rule
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -45,7 +45,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, kind and rule ID.
|
/// 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 }
|
Self { scope, kind, rule_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
use ruma_common::api::ruma_api;
|
use ruma_common::api::ruma_api;
|
||||||
|
|
||||||
use crate::push::RuleKind;
|
use crate::push::{RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,9 +22,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
/// The scope to fetch a rule from.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule
|
/// The kind of rule
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -45,7 +45,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, rule kind and rule ID.
|
/// 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 }
|
Self { scope, kind, rule_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ pub mod v3 {
|
|||||||
push::{Action, PushCondition},
|
push::{Action, PushCondition},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::push::RuleKind;
|
use crate::push::{RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -25,9 +25,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to set the rule in. 'global' to specify global rules.
|
/// The scope to set the rule in.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule
|
/// The kind of rule
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -74,7 +74,7 @@ pub mod v3 {
|
|||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, rule kind, rule ID and actions.
|
/// Creates a new `Request` with the given scope, rule kind, rule ID and actions.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
scope: &'a str,
|
scope: RuleScope,
|
||||||
kind: RuleKind,
|
kind: RuleKind,
|
||||||
rule_id: &'a str,
|
rule_id: &'a str,
|
||||||
actions: &'a [Action],
|
actions: &'a [Action],
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
use ruma_common::{api::ruma_api, push::Action};
|
use ruma_common::{api::ruma_api, push::Action};
|
||||||
|
|
||||||
use crate::push::RuleKind;
|
use crate::push::{RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,9 +22,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
/// The scope to fetch a rule from.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule
|
/// The kind of rule
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -46,7 +46,12 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, rule kind, rule ID and actions.
|
/// 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 }
|
Self { scope, kind, rule_id, actions }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ pub mod v3 {
|
|||||||
|
|
||||||
use ruma_common::api::ruma_api;
|
use ruma_common::api::ruma_api;
|
||||||
|
|
||||||
use crate::push::RuleKind;
|
use crate::push::{RuleKind, RuleScope};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,9 +22,9 @@ pub mod v3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The scope to fetch a rule from. 'global' to specify global rules.
|
/// The scope to fetch a rule from.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub scope: &'a str,
|
pub scope: RuleScope,
|
||||||
|
|
||||||
/// The kind of rule
|
/// The kind of rule
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
@ -46,17 +46,17 @@ pub mod v3 {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given scope, rule kind, rule ID and enabled flag.
|
/// 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 }
|
Self { scope, kind, rule_id, enabled }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `Request` to enable the given rule.
|
/// 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)
|
Self::new(scope, kind, rule_id, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `Request` to disable the given rule.
|
/// 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)
|
Self::new(scope, kind, rule_id, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user