ruma_identity_service_api/tos/
get_terms_of_service.rs

1//! `GET /_matrix/identity/*/terms`
2//!
3//! Get the terms of service of an identity server.
4
5pub mod v2 {
6    //! `/v2/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/identity-service-api/#get_matrixidentityv2terms
9
10    use std::collections::BTreeMap;
11
12    use ruma_common::{
13        api::{request, response, Metadata},
14        metadata,
15    };
16    use serde::{Deserialize, Serialize};
17
18    const METADATA: Metadata = metadata! {
19        method: GET,
20        rate_limited: false,
21        authentication: None,
22        history: {
23            1.0 => "/_matrix/identity/v2/terms",
24        }
25    };
26
27    /// Request type for the `get_terms_of_service` endpoint.
28    #[request]
29    #[derive(Default)]
30    pub struct Request {}
31
32    /// Response type for the `get_terms_of_service` endpoint.
33    #[response]
34    pub struct Response {
35        /// The policies the server offers.
36        ///
37        /// Mapped from arbitrary ID (unused in this version of the specification) to a Policy
38        /// Object.
39        pub policies: BTreeMap<String, Policies>,
40    }
41
42    impl Request {
43        /// Creates an empty `Request`.
44        pub fn new() -> Self {
45            Self {}
46        }
47    }
48
49    impl Response {
50        /// Creates a new `Response` with the given `Policies`.
51        pub fn new(policies: BTreeMap<String, Policies>) -> Self {
52            Self { policies }
53        }
54    }
55
56    /// Collection of localized policies.
57    #[derive(Clone, Debug, Serialize, Deserialize)]
58    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
59    pub struct Policies {
60        /// The version for the policy.
61        ///
62        /// There are no requirements on what this might be and could be
63        /// "alpha", semantically versioned, or arbitrary.
64        pub version: String,
65
66        /// Available languages for the policy.
67        ///
68        /// The keys could be the language code corresponding to
69        /// the given `LocalizedPolicy`, for example "en" or "fr".
70        #[serde(flatten)]
71        pub localized: BTreeMap<String, LocalizedPolicy>,
72    }
73
74    impl Policies {
75        /// Create a new `Policies` with the given version and localized map.
76        pub fn new(version: String, localized: BTreeMap<String, LocalizedPolicy>) -> Self {
77            Self { version, localized }
78        }
79    }
80
81    /// A localized policy offered by a server.
82    #[derive(Clone, Debug, Serialize, Deserialize)]
83    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
84    pub struct LocalizedPolicy {
85        /// The localized name of the policy.
86        ///
87        /// Examples are "Terms of Service", "Conditions d'utilisation".
88        pub name: String,
89
90        /// The URL at which the policy is available.
91        ///
92        /// Examples are `https://example.org/somewhere/terms-2.0-en.html`
93        /// and `https://example.org/somewhere/terms-2.0-fr.html`.
94        pub url: String,
95    }
96
97    impl LocalizedPolicy {
98        /// Create a new `LocalizedPolicy` with the given name and url.
99        pub fn new(name: String, url: String) -> Self {
100            Self { name, url }
101        }
102    }
103}