instant_epp/host/
check.rs1use std::fmt::{self, Debug};
4
5use instant_xml::{FromXml, Serializer, ToXml};
6
7use super::XMLNS;
8use crate::common::{NoExtension, EPP_XMLNS};
9use crate::request::{Command, Transaction};
10
11impl Transaction<NoExtension> for HostCheck<'_> {}
12
13impl Command for HostCheck<'_> {
14 type Response = CheckData;
15 const COMMAND: &'static str = "check";
16}
17
18#[derive(Debug, ToXml)]
22#[xml(rename = "check", ns(XMLNS))]
23struct HostCheckData<'a> {
24 name: &'a [&'a str],
26}
27
28fn serialize_hosts<W: fmt::Write + ?Sized>(
29 hosts: &[&str],
30 serializer: &mut Serializer<W>,
31) -> Result<(), instant_xml::Error> {
32 HostCheckData { name: hosts }.serialize(None, serializer)
33}
34
35#[derive(Clone, Debug, ToXml)]
37#[xml(rename = "check", ns(EPP_XMLNS))]
38pub struct HostCheck<'a> {
39 #[xml(serialize_with = "serialize_hosts")]
41 pub hosts: &'a [&'a str],
42}
43
44#[derive(Debug, FromXml)]
47#[xml(rename = "name", ns(XMLNS))]
48pub struct Name {
49 #[xml(attribute, rename = "avail")]
50 pub available: bool,
51
52 #[xml(direct)]
53 pub value: String,
54}
55
56#[derive(Debug, FromXml)]
57#[xml(rename = "cd", ns(XMLNS))]
58pub struct CheckedHost {
59 pub name: Name,
61 pub reason: Option<Reason>,
63}
64
65#[derive(Debug, FromXml)]
66#[xml(rename = "reason", ns(XMLNS))]
67pub struct Reason {
68 #[xml(attribute)]
69 pub lang: Option<String>,
70 #[xml(direct)]
71 pub value: String,
72}
73
74#[derive(Debug, FromXml)]
76#[xml(rename = "chkData", ns(XMLNS))]
77pub struct CheckData {
78 pub list: Vec<CheckedHost>,
79}
80
81#[cfg(test)]
82mod tests {
83 use super::HostCheck;
84 use crate::response::ResultCode;
85 use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
86
87 #[test]
88 fn command() {
89 let object = HostCheck {
90 hosts: &["ns1.eppdev-1.com", "host1.eppdev-1.com"],
91 };
92 assert_serialized("request/host/check.xml", &object);
93 }
94
95 #[test]
96 fn response() {
97 let object = response_from_file::<HostCheck>("response/host/check.xml");
98 let result = object.res_data().unwrap();
99
100 assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
101 assert_eq!(object.result.message, SUCCESS_MSG);
102 assert_eq!(result.list[0].name.value, "host1.eppdev-1.com");
103 assert!(result.list[0].name.available);
104 assert_eq!(result.list[1].name.value, "ns1.testing.com");
105 assert!(!result.list[1].name.available);
106 assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
107 assert_eq!(object.tr_ids.server_tr_id, SVTRID);
108 }
109}