instant_epp/contact/
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 ContactCheck<'_> {}
12
13impl Command for ContactCheck<'_> {
14 type Response = CheckData;
15 const COMMAND: &'static str = "check";
16}
17
18#[derive(Debug, ToXml)]
22#[xml(rename = "check", ns(XMLNS))]
23struct ContactList<'a> {
24 id: &'a [&'a str],
26}
27
28fn serialize_contacts<W: fmt::Write + ?Sized>(
29 ids: &[&str],
30 serializer: &mut Serializer<W>,
31) -> Result<(), instant_xml::Error> {
32 ContactList { id: ids }.serialize(None, serializer)
33}
34
35#[derive(Clone, Debug, ToXml)]
37#[xml(rename = "check", ns(EPP_XMLNS))]
38pub struct ContactCheck<'a> {
39 #[xml(serialize_with = "serialize_contacts")]
40 pub contact_ids: &'a [&'a str],
41}
42
43#[derive(Debug, FromXml)]
46#[xml(rename = "id", ns(XMLNS))]
47pub struct ContactId {
48 #[xml(attribute, rename = "avail")]
49 pub available: bool,
50 #[xml(direct)]
51 pub value: String,
52}
53
54#[derive(Debug, FromXml)]
55#[xml(rename = "cd", ns(XMLNS))]
56pub struct CheckedContact {
57 pub id: ContactId,
59 pub reason: Option<Reason>,
61}
62
63#[derive(Debug, FromXml)]
64#[xml(rename = "reason", ns(XMLNS))]
65pub struct Reason {
66 #[xml(attribute)]
67 pub lang: Option<String>,
68 #[xml(direct)]
69 pub value: String,
70}
71
72#[derive(Debug, FromXml)]
74#[xml(rename = "chkData", ns(XMLNS))]
75pub struct CheckData {
76 pub list: Vec<CheckedContact>,
77}
78
79#[cfg(test)]
80mod tests {
81 use super::ContactCheck;
82 use crate::response::ResultCode;
83 use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
84
85 #[test]
86 fn command() {
87 let object = ContactCheck {
88 contact_ids: &["eppdev-contact-1", "eppdev-contact-2"],
89 };
90 assert_serialized("request/contact/check.xml", &object);
91 }
92
93 #[test]
94 fn response() {
95 let object = response_from_file::<ContactCheck>("response/contact/check.xml");
96 let results = object.res_data().unwrap();
97
98 assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
99 assert_eq!(object.result.message, SUCCESS_MSG);
100 assert_eq!(results.list[0].id.value, "eppdev-contact-1");
101 assert!(!results.list[0].id.available);
102 assert_eq!(results.list[1].id.value, "eppdev-contact-2");
103 assert!(results.list[1].id.available);
104 assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
105 assert_eq!(object.tr_ids.server_tr_id, SVTRID);
106 }
107}