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::{auth_scheme::NoAuthentication, request, response, SupportedVersions},
17    metadata,
18};
19
20metadata! {
21    method: GET,
22    rate_limited: false,
23    authentication: NoAuthentication,
24    path: "/_matrix/identity/versions",
25}
26
27/// Request type for the `versions` endpoint.
28#[request]
29#[derive(Default)]
30pub struct Request {}
31
32/// Response type for the `versions` endpoint.
33#[response]
34pub struct Response {
35    /// A list of Matrix client API protocol versions supported by the endpoint.
36    pub versions: Vec<String>,
37}
38
39impl Request {
40    /// Creates an empty `Request`.
41    pub fn new() -> Self {
42        Self {}
43    }
44}
45
46impl Response {
47    /// Creates a new `Response` with the given `versions`.
48    pub fn new(versions: Vec<String>) -> Self {
49        Self { versions }
50    }
51
52    /// Convert this `Response` into a [`SupportedVersions`] that can be used with
53    /// `OutgoingRequest::try_into_http_request()`.
54    ///
55    /// Matrix versions that can't be parsed to a `MatrixVersion`, and features with the boolean
56    /// value set to `false` are discarded.
57    pub fn as_supported_versions(&self) -> SupportedVersions {
58        SupportedVersions::from_parts(&self.versions, &BTreeMap::new())
59    }
60}