instant_epp/contact/
update.rs1use instant_xml::ToXml;
4
5use super::{ContactAuthInfo, Fax, PostalInfo, Status, Voice, XMLNS};
6use crate::common::{NoExtension, EPP_XMLNS};
7use crate::request::{Command, Transaction};
8
9impl Transaction<NoExtension> for ContactUpdate<'_> {}
10
11impl Command for ContactUpdate<'_> {
12 type Response = ();
13 const COMMAND: &'static str = "update";
14}
15
16impl<'a> ContactUpdate<'a> {
17 pub fn new(id: &'a str) -> Self {
18 Self {
19 contact: ContactUpdateRequest {
20 id,
21 add_statuses: None,
22 remove_statuses: None,
23 change_info: None,
24 },
25 }
26 }
27
28 pub fn set_info(
30 &mut self,
31 email: &'a str,
32 postal_info: PostalInfo<'a>,
33 voice: Voice<'a>,
34 auth_password: &'a str,
35 ) {
36 self.contact.change_info = Some(ContactChangeInfo {
37 email: Some(email),
38 postal_info: Some(postal_info),
39 voice: Some(voice),
40 auth_info: Some(ContactAuthInfo::new(auth_password)),
41 fax: None,
42 });
43 }
44
45 pub fn set_fax(&mut self, fax: Fax<'a>) {
47 if let Some(info) = &mut self.contact.change_info {
48 info.fax = Some(fax)
49 }
50 }
51
52 pub fn add(&mut self, statuses: &'a [Status]) {
54 self.contact.add_statuses = Some(AddStatuses { statuses });
55 }
56
57 pub fn remove(&mut self, statuses: &'a [Status]) {
59 self.contact.remove_statuses = Some(RemoveStatuses { statuses });
60 }
61}
62
63#[derive(Debug, ToXml)]
65#[xml(rename = "chg", ns(XMLNS))]
66pub struct ContactChangeInfo<'a> {
67 postal_info: Option<PostalInfo<'a>>,
68 voice: Option<Voice<'a>>,
69 fax: Option<Fax<'a>>,
70 email: Option<&'a str>,
71 auth_info: Option<ContactAuthInfo<'a>>,
72}
73
74#[derive(Debug, ToXml)]
75#[xml(rename = "add", ns(XMLNS))]
76struct AddStatuses<'a> {
77 statuses: &'a [Status],
78}
79
80#[derive(Debug, ToXml)]
81#[xml(rename = "rem", ns(XMLNS))]
82struct RemoveStatuses<'a> {
83 statuses: &'a [Status],
84}
85
86#[derive(Debug, ToXml)]
88#[xml(rename = "update", ns(XMLNS))]
89pub struct ContactUpdateRequest<'a> {
90 id: &'a str,
91 add_statuses: Option<AddStatuses<'a>>,
92 #[xml(rename = "rem")]
93 remove_statuses: Option<RemoveStatuses<'a>>,
94 change_info: Option<ContactChangeInfo<'a>>,
95}
96
97#[derive(Debug, ToXml)]
99#[xml(rename = "update", ns(EPP_XMLNS))]
100pub struct ContactUpdate<'a> {
101 contact: ContactUpdateRequest<'a>,
103}
104
105#[cfg(test)]
106mod tests {
107 use super::{ContactUpdate, PostalInfo, Status, Voice};
108 use crate::contact::{Address, InfoType};
109 use crate::response::ResultCode;
110 use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
111
112 #[test]
113 fn command() {
114 let mut object = ContactUpdate::new("eppdev-contact-3");
115
116 let street = &["58", "Orchid Road"];
117 let address = Address::new(
118 street,
119 "Paris",
120 Some("Paris"),
121 Some("392374"),
122 "FR".parse().unwrap(),
123 );
124 let postal_info =
125 PostalInfo::new(InfoType::Local, "John Doe", Some("Acme Widgets"), address);
126 let voice = Voice::new("+33.47237942");
127
128 object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323");
129 object.add(&[Status::ClientTransferProhibited]);
130 object.remove(&[Status::ClientDeleteProhibited]);
131
132 assert_serialized("request/contact/update.xml", &object);
133 }
134
135 #[test]
136 fn contact_update() {
137 let object = response_from_file::<ContactUpdate>("response/contact/update.xml");
138 assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
139 assert_eq!(object.result.message, SUCCESS_MSG);
140 assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
141 assert_eq!(object.tr_ids.server_tr_id, SVTRID);
142 }
143}