ruma_client_api/appservice/
request_ping.rs

1//! `POST /_matrix/client/*/appservice/{appserviceId}/ping}`
2//!
3//! Ask the homeserver to ping the application service to ensure the connection works.
4
5pub mod v1 {
6    //! `/v1/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/application-service-api/#post_matrixclientv1appserviceappserviceidping
9
10    use std::time::Duration;
11
12    use ruma_common::{
13        OwnedTransactionId,
14        api::{auth_scheme::AppserviceToken, request, response},
15        metadata,
16    };
17
18    metadata! {
19        method: POST,
20        rate_limited: false,
21        authentication: AppserviceToken,
22        history: {
23            unstable("fi.mau.msc2659") => "/_matrix/client/unstable/fi.mau.msc2659/appservice/{appservice_id}/ping",
24            1.7 | stable("fi.mau.msc2659.stable") => "/_matrix/client/v1/appservice/{appservice_id}/ping",
25        }
26    }
27
28    /// Request type for the `request_ping` endpoint.
29    #[request(error = crate::Error)]
30    pub struct Request {
31        /// The appservice ID of the appservice to ping.
32        ///
33        /// This must be the same as the appservice whose `as_token` is being used to authenticate
34        /// the request.
35        #[ruma_api(path)]
36        pub appservice_id: String,
37
38        /// Transaction ID that is passed through to the `POST /_matrix/app/v1/ping` call.
39        #[serde(skip_serializing_if = "Option::is_none")]
40        pub transaction_id: Option<OwnedTransactionId>,
41    }
42
43    /// Response type for the `request_ping` endpoint.
44    #[response(error = crate::Error)]
45    pub struct Response {
46        /// The duration in milliseconds that the `POST /_matrix/app/v1/ping` request took from the
47        /// homeserver's point of view.
48        #[serde(with = "ruma_common::serde::duration::ms", rename = "duration_ms")]
49        pub duration: Duration,
50    }
51
52    impl Request {
53        /// Creates a new `Request` with the given appservice ID.
54        pub fn new(appservice_id: String) -> Self {
55            Self { appservice_id, transaction_id: None }
56        }
57    }
58
59    impl Response {
60        /// Creates an `Response` with the given duration.
61        pub fn new(duration: Duration) -> Self {
62            Self { duration }
63        }
64    }
65}