diff --git a/src/lib.rs b/src/lib.rs index ca041618..68f7e837 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,8 +31,8 @@ pub mod r0 { pub mod membership; pub mod presence; pub mod profile; -// pub mod push; -// pub mod receipt; + pub mod push; + pub mod receipt; // pub mod redact; pub mod room; // pub mod search; diff --git a/src/r0/receipt.rs b/src/r0/receipt.rs index f5bf20e2..51ec07d9 100644 --- a/src/r0/receipt.rs +++ b/src/r0/receipt.rs @@ -2,76 +2,44 @@ /// [POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-receipt-receipttype-eventid) pub mod create_receipt { - use ruma_identifiers::{EventId, RoomId}; - use std::fmt::{Display, Error as FmtError, Formatter}; - /// Details about this API endpoint. - #[derive(Clone, Copy, Debug)] - pub struct Endpoint; + use ruma_api_macros::ruma_api; + use ruma_identifiers::{EventId, RoomId}; - /// This endpoint's path parameters. - #[derive(Clone, Debug)] - pub struct PathParams { - /// The event ID to acknowledge up to. - pub event_id: EventId, - /// The type of receipt to send. - pub receipt_type: ReceiptType, - /// The room in which to send the event. - pub room_id: RoomId, + ruma_api! { + metadata { + description: "Send a receipt event to a room.", + method: Method::Post, + name: "create_receipt", + path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", + rate_limited: true, + requires_authentication: true, + } + + request { + /// The event ID to acknowledge up to. + #[ruma_api(path)] + pub event_id: EventId, + /// The type of receipt to send. + #[ruma_api(path)] + pub receipt_type: ReceiptType, + /// The room in which to send the event. + #[ruma_api(path)] + pub room_id: RoomId, + } + + response {} } /// The type of receipt. - #[derive(Clone, Copy, Debug)] + #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum ReceiptType { /// m.read + #[serde(rename = "m.read")] Read, } - /// This API endpoint's response. - #[derive(Clone, Copy, Debug, Deserialize, Serialize)] - pub struct Response; - - impl ::Endpoint for Endpoint { - type BodyParams = (); - type PathParams = PathParams; - type QueryParams = (); - type Response = Response; - - fn method() -> ::Method { - ::Method::Post - } - - fn request_path(params: Self::PathParams) -> String { - format!( - "/_matrix/client/r0/rooms/{}/receipt/{}/{}", - params.room_id, - params.receipt_type, - params.event_id - ) - } - - fn router_path() -> &'static str { - "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id" - } - - fn name() -> &'static str { - "create_receipt" - } - - fn description() -> &'static str { - "Send a receipt event to a room." - } - - fn requires_authentication() -> bool { - true - } - - fn rate_limited() -> bool { - true - } - } - impl Display for ReceiptType { fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> { match *self {