ruma_identity_service_api/discovery/get_supported_versions.rs
1//! `GET /_matrix/identity/versions` ([spec])
2//!
3//! Get the versions of the identity service API supported by this endpoint.
4//!
5//! Note: This endpoint was only implemented in/after 1.1, so a 404 could indicate the server only
6//! supports 1.0 endpoints. Please use [`server_status`](super::get_server_status) to
7//! double-check.
8//!
9//! Note: This endpoint does not contain an unstable variant for 1.0.
10//!
11//! [spec]: https://spec.matrix.org/latest/identity-service-api/#get_matrixidentityversions
12
13use std::collections::BTreeMap;
14
15use ruma_common::{
16 api::{request, response, Metadata, SupportedVersions},
17 metadata,
18};
19
20const METADATA: Metadata = metadata! {
21 method: GET,
22 rate_limited: false,
23 authentication: None,
24 history: {
25 1.1 => "/_matrix/identity/versions",
26 }
27};
28
29/// Request type for the `versions` endpoint.
30#[request]
31#[derive(Default)]
32pub struct Request {}
33
34/// Response type for the `versions` endpoint.
35#[response]
36pub struct Response {
37 /// A list of Matrix client API protocol versions supported by the endpoint.
38 pub versions: Vec<String>,
39}
40
41impl Request {
42 /// Creates an empty `Request`.
43 pub fn new() -> Self {
44 Self {}
45 }
46}
47
48impl Response {
49 /// Creates a new `Response` with the given `versions`.
50 pub fn new(versions: Vec<String>) -> Self {
51 Self { versions }
52 }
53
54 /// Convert this `Response` into a [`SupportedVersions`] that can be used with
55 /// `OutgoingRequest::try_into_http_request()`.
56 ///
57 /// Matrix versions that can't be parsed to a `MatrixVersion`, and features with the boolean
58 /// value set to `false` are discarded.
59 pub fn as_supported_versions(&self) -> SupportedVersions {
60 SupportedVersions::from_parts(&self.versions, &BTreeMap::new())
61 }
62}