Use ruma-api-macros for the server endpoints.
This commit is contained in:
		
							parent
							
								
									e71760bb65
								
							
						
					
					
						commit
						f94cb9d62a
					
				| @ -37,7 +37,7 @@ pub mod r0 { | ||||
|     pub mod room; | ||||
|     pub mod search; | ||||
|     pub mod send; | ||||
| //     pub mod server;
 | ||||
|     pub mod server; | ||||
|     pub mod session; | ||||
|     pub mod sync; | ||||
| //     pub mod tag;
 | ||||
|  | ||||
| @ -2,9 +2,34 @@ | ||||
| 
 | ||||
| /// [GET /_matrix/client/r0/admin/whois/{userId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-admin-whois-userid)
 | ||||
| pub mod get_user_info { | ||||
|     use std::collections::HashMap; | ||||
| 
 | ||||
|     use ruma_api_macros::ruma_api; | ||||
|     use ruma_identifiers::UserId; | ||||
| 
 | ||||
|     use std::collections::HashMap; | ||||
|     ruma_api! { | ||||
|         metadata { | ||||
|             description: "Get information about a particular user.", | ||||
|             method: Method::Get, | ||||
|             name: "get_user_info", | ||||
|             path: "/_matrix/client/r0/admin/whois/:user_id", | ||||
|             rate_limited: false, | ||||
|             requires_authentication: true, | ||||
|         } | ||||
| 
 | ||||
|         request { | ||||
|             /// The user to look up.
 | ||||
|             #[ruma_api(path)] | ||||
|             pub user_id: UserId, | ||||
|         } | ||||
| 
 | ||||
|         response { | ||||
|             /// The Matrix user ID of the user.
 | ||||
|             pub user_id: UserId, | ||||
|             /// A map of the user's device identifiers to information about that device.
 | ||||
|             pub devices: HashMap<String, DeviceInfo>, | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// Information about a connection in a user session.
 | ||||
|     #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
| @ -24,68 +49,10 @@ pub mod get_user_info { | ||||
|         pub sessions: Vec<SessionInfo>, | ||||
|     } | ||||
| 
 | ||||
|     /// Details about this API endpoint.
 | ||||
|     #[derive(Clone, Copy, Debug)] | ||||
|     pub struct Endpoint; | ||||
| 
 | ||||
|     /// This API endpoint's path parameters.
 | ||||
|     #[derive(Clone, Debug)] | ||||
|     pub struct PathParams { | ||||
|         /// The user to look up.
 | ||||
|         pub user_id: UserId, | ||||
|     } | ||||
| 
 | ||||
|     /// This API endpoint's response.
 | ||||
|     #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
|     pub struct Response { | ||||
|         /// The Matrix user ID of the user.
 | ||||
|         pub user_id: UserId, | ||||
|         /// A map of the user's device identifiers to information about that device.
 | ||||
|         pub devices: HashMap<String, DeviceInfo>, | ||||
|     } | ||||
| 
 | ||||
|     /// Information about a user session.
 | ||||
|     #[derive(Clone, Debug, Deserialize, Serialize)] | ||||
|     pub struct SessionInfo { | ||||
|         /// A list of connections in this session.
 | ||||
|         pub connections: Vec<ConnectionInfo>, | ||||
|     } | ||||
| 
 | ||||
|     impl ::Endpoint for Endpoint { | ||||
|         type BodyParams = (); | ||||
|         type PathParams = PathParams; | ||||
|         type QueryParams = (); | ||||
|         type Response = Response; | ||||
| 
 | ||||
|         fn method() -> ::Method { | ||||
|             ::Method::Get | ||||
|         } | ||||
| 
 | ||||
|         fn request_path(params: Self::PathParams) -> String { | ||||
|             format!( | ||||
|                 "/_matrix/client/r0/admin/whois/{}", | ||||
|                 params.user_id | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         fn router_path() -> &'static str { | ||||
|             "/_matrix/client/r0/admin/whois/:user_id" | ||||
|         } | ||||
| 
 | ||||
|         fn name() -> &'static str { | ||||
|             "get_user_info" | ||||
|         } | ||||
| 
 | ||||
|         fn description() -> &'static str { | ||||
|             "Get information about a particular user." | ||||
|         } | ||||
| 
 | ||||
|         fn requires_authentication() -> bool { | ||||
|             true | ||||
|         } | ||||
| 
 | ||||
|         fn rate_limited() -> bool { | ||||
|             false | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user