From 6a1c452ac93ca8c31ce361847dc6514c5d5c2178 Mon Sep 17 00:00:00 2001 From: Amanda Graven Date: Sat, 10 Oct 2020 01:12:53 +0200 Subject: [PATCH] Add generic query endpoint --- ruma-federation-api/CHANGELOG.md | 1 + ruma-federation-api/src/query.rs | 1 + .../src/query/get_custom_information.rs | 3 ++ .../src/query/get_custom_information/v1.rs | 47 +++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 ruma-federation-api/src/query/get_custom_information.rs create mode 100644 ruma-federation-api/src/query/get_custom_information/v1.rs diff --git a/ruma-federation-api/CHANGELOG.md b/ruma-federation-api/CHANGELOG.md index fc2b8253..9c14ffc2 100644 --- a/ruma-federation-api/CHANGELOG.md +++ b/ruma-federation-api/CHANGELOG.md @@ -25,6 +25,7 @@ Improvements: create_leave_event::{v1, v2}, get_leave_event::v1, }, + query::get_custom_information::v1, thirdparty::{ bind_callback::v1, exchange_invite::v1, diff --git a/ruma-federation-api/src/query.rs b/ruma-federation-api/src/query.rs index 1987c091..4fafd173 100644 --- a/ruma-federation-api/src/query.rs +++ b/ruma-federation-api/src/query.rs @@ -1,4 +1,5 @@ //! Endpoints to retrieve information from a homeserver about a resource. +pub mod get_custom_information; pub mod get_profile_information; pub mod get_room_information; diff --git a/ruma-federation-api/src/query/get_custom_information.rs b/ruma-federation-api/src/query/get_custom_information.rs new file mode 100644 index 00000000..b52ed1ef --- /dev/null +++ b/ruma-federation-api/src/query/get_custom_information.rs @@ -0,0 +1,3 @@ +//! Generic query endpoint for performing custom queries. + +pub mod v1; diff --git a/ruma-federation-api/src/query/get_custom_information/v1.rs b/ruma-federation-api/src/query/get_custom_information/v1.rs new file mode 100644 index 00000000..87a53944 --- /dev/null +++ b/ruma-federation-api/src/query/get_custom_information/v1.rs @@ -0,0 +1,47 @@ +//! [GET /_matrix/federation/v1/query/{queryType}](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-federation-v1-query-querytype) + +use ruma_api::ruma_api; +use serde_json::Value as JsonValue; + +use std::collections::BTreeMap; + +ruma_api! { + metadata: { + description: "Performs a single query request on the receiving homeserver. The query string arguments are dependent on which type of query is being made.", + method: GET, + name: "get_custom_information", + path: "/_matrix/federation/v1/query/:query_type", + rate_limited: false, + authentication: AccessToken, + } + + request: { + /// The type of query to make. + #[ruma_api(path)] + pub query_type: &'a str, + + /// The query parameters. + #[ruma_api(query_map)] + pub params: BTreeMap, + } + + response: { + /// The body of the response. + #[ruma_api(body)] + pub body: JsonValue, + } +} + +impl<'a> Request<'a> { + /// Creates a new request with the given type and query parameters. + pub fn new(query_type: &'a str, params: BTreeMap) -> Self { + Self { query_type, params } + } +} + +impl Response { + /// Creates a new response with the given body. + pub fn new(body: JsonValue) -> Self { + Self { body } + } +}