Add generic query endpoint

This commit is contained in:
Amanda Graven 2020-10-10 01:12:53 +02:00 committed by GitHub
parent 524782e992
commit 6a1c452ac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 0 deletions

View File

@ -25,6 +25,7 @@ Improvements:
create_leave_event::{v1, v2}, create_leave_event::{v1, v2},
get_leave_event::v1, get_leave_event::v1,
}, },
query::get_custom_information::v1,
thirdparty::{ thirdparty::{
bind_callback::v1, bind_callback::v1,
exchange_invite::v1, exchange_invite::v1,

View File

@ -1,4 +1,5 @@
//! Endpoints to retrieve information from a homeserver about a resource. //! Endpoints to retrieve information from a homeserver about a resource.
pub mod get_custom_information;
pub mod get_profile_information; pub mod get_profile_information;
pub mod get_room_information; pub mod get_room_information;

View File

@ -0,0 +1,3 @@
//! Generic query endpoint for performing custom queries.
pub mod v1;

View File

@ -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<String, String>,
}
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<String, String>) -> Self {
Self { query_type, params }
}
}
impl Response {
/// Creates a new response with the given body.
pub fn new(body: JsonValue) -> Self {
Self { body }
}
}