Use ruma-api-macros for the context endpoints.

This commit is contained in:
Jimmy Cuadra 2017-05-19 21:09:58 -07:00
parent a40ec4e07f
commit 4b728514ca
2 changed files with 37 additions and 58 deletions

View File

@ -23,7 +23,7 @@ pub mod r0 {
pub mod alias; pub mod alias;
pub mod config; pub mod config;
pub mod contact; pub mod contact;
// pub mod context; pub mod context;
// pub mod directory; // pub mod directory;
// pub mod filter; // pub mod filter;
// pub mod media; // pub mod media;

View File

@ -4,68 +4,47 @@
pub mod get_context { pub mod get_context {
use ruma_identifiers::{EventId, RoomId}; use ruma_identifiers::{EventId, RoomId};
use ruma_events::collections::only; use ruma_events::collections::only;
use ruma_api_macros::ruma_api;
ruma_api! {
metadata {
description: "Get the events immediately preceding and following a given event.",
method: Method::Get,
path: "/_matrix/client/r0/rooms/:room_id/context/:event_id",
name: "get_context",
rate_limited: false,
requires_authentication: true,
}
/// Details about this API endpoint. request {
#[derive(Clone, Copy, Debug)] /// The event to get context around.
pub struct Endpoint; #[ruma_api(path)]
/// This API endpoint's path parameters.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PathParams {
pub event_id: EventId, pub event_id: EventId,
/// The maximum number of events to return.
///
/// Defaults to 10 if not supplied.
#[ruma_api(query)]
pub limit: u8,
/// The room to get events from.
#[ruma_api(path)]
pub room_id: RoomId, pub room_id: RoomId,
} }
/// This API endpoint's query string parameters. response {
#[derive(Clone, Debug, Deserialize, Serialize)] /// A token that can be used to paginate forwards with.
pub struct QueryParams {
pub limit: u8,
}
/// This API endpoint's response.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Response {
pub end: String, pub end: String,
/// Details of the requested event.
pub event: only::RoomEvent, pub event: only::RoomEvent,
/// A list of room events that happened just after the requested event, in chronological
/// order.
pub events_after: Vec<only::RoomEvent>, pub events_after: Vec<only::RoomEvent>,
/// A list of room events that happened just before the requested event, in
/// reverse-chronological order.
pub events_before: Vec<only::RoomEvent>, pub events_before: Vec<only::RoomEvent>,
/// A token that can be used to paginate backwards with.
pub start: String, pub start: String,
/// The state of the room at the last event returned.
pub state: Vec<only::StateEvent>, pub state: Vec<only::StateEvent>,
} }
impl ::Endpoint for Endpoint {
type BodyParams = ();
type PathParams = PathParams;
type QueryParams = QueryParams;
type Response = Response;
fn method() -> ::Method {
::Method::Get
}
fn request_path(params: Self::PathParams) -> String {
format!("/_matrix/client/r0/rooms/{}/context/{}", params.room_id, params.event_id)
}
fn router_path() -> &'static str {
"/_matrix/client/r0/rooms/:room_id/context/:event_id"
}
fn name() -> &'static str {
"get_context"
}
fn description() -> &'static str {
"Get the events immediately preceding and following a given event."
}
fn requires_authentication() -> bool {
true
}
fn rate_limited() -> bool {
false
}
} }
} }