pub mod v1 {
use std::collections::BTreeMap;
use ruma_common::{
api::{auth_scheme::AccessToken, request, response},
metadata,
thirdparty::{Protocol, ProtocolInstance, ProtocolInstanceInit},
};
use serde::{Deserialize, Serialize};
metadata! {
method: GET,
rate_limited: false,
authentication: AccessToken,
path: "/_matrix/app/v1/thirdparty/protocol/{protocol}",
}
#[request]
pub struct Request {
#[ruma_api(path)]
pub protocol: String,
}
#[response]
pub struct Response {
#[ruma_api(body)]
pub protocol: AppserviceProtocol,
}
impl Request {
pub fn new(protocol: String) -> Self {
Self { protocol }
}
}
impl Response {
pub fn new(protocol: AppserviceProtocol) -> Self {
Self { protocol }
}
}
pub type AppserviceProtocol = Protocol<AppserviceProtocolInstance>;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct AppserviceProtocolInstance {
pub desc: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub icon: Option<String>,
pub fields: BTreeMap<String, String>,
pub network_id: String,
}
impl From<ProtocolInstanceInit> for AppserviceProtocolInstance {
fn from(init: ProtocolInstanceInit) -> Self {
let ProtocolInstanceInit { desc, fields, network_id } = init;
Self { desc, icon: None, fields, network_id }
}
}
impl From<AppserviceProtocolInstance> for ProtocolInstance {
fn from(value: AppserviceProtocolInstance) -> Self {
let AppserviceProtocolInstance { desc, icon, fields, network_id } = value;
let mut instance =
ProtocolInstance::from(ProtocolInstanceInit { desc, fields, network_id });
instance.icon = icon;
instance
}
}
}