1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
use epp_client_macros::*;
use crate::epp::object::data::{AuthInfo, ContactStatus, Phone, PostalInfo};
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::request::Command;
use crate::epp::response::contact::info::EppContactInfoResponse;
use crate::epp::xml::EPP_CONTACT_XMLNS;
use crate::error;
use serde::{Deserialize, Serialize};
pub type EppContactUpdate = EppObject<Command<ContactUpdate>>;
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactChangeInfo {
#[serde(rename = "postalInfo")]
postal_info: Option<PostalInfo>,
voice: Option<Phone>,
fax: Option<Phone>,
email: Option<StringValue>,
#[serde(rename = "authInfo")]
auth_info: Option<AuthInfo>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct StatusList {
status: Vec<ContactStatus>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactUpdateData {
xmlns: String,
id: StringValue,
#[serde(rename = "add")]
add_statuses: Option<StatusList>,
#[serde(rename = "rem")]
remove_statuses: Option<StatusList>,
#[serde(rename = "chg")]
change_info: Option<ContactChangeInfo>,
}
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "update")]
pub struct ContactUpdate {
#[serde(rename = "update")]
contact: ContactUpdateData,
}
impl EppContactUpdate {
pub fn new(id: &str, client_tr_id: &str) -> EppContactUpdate {
EppObject::build(Command::<ContactUpdate> {
command: ContactUpdate {
contact: ContactUpdateData {
xmlns: EPP_CONTACT_XMLNS.to_string(),
id: id.to_string_value(),
add_statuses: None,
remove_statuses: None,
change_info: None,
},
},
client_tr_id: client_tr_id.to_string_value(),
})
}
pub fn set_info(
&mut self,
email: &str,
postal_info: PostalInfo,
voice: Phone,
auth_password: &str,
) {
self.data.command.contact.change_info = Some(ContactChangeInfo {
email: Some(email.to_string_value()),
postal_info: Some(postal_info),
voice: Some(voice),
auth_info: Some(AuthInfo::new(auth_password)),
fax: None,
});
}
pub fn set_fax(&mut self, fax: Phone) {
match &mut self.data.command.contact.change_info {
Some(ref mut info) => info.fax = Some(fax),
_ => (),
}
}
pub fn add(&mut self, statuses: Vec<ContactStatus>) {
self.data.command.contact.add_statuses = Some(StatusList { status: statuses });
}
pub fn remove(&mut self, statuses: Vec<ContactStatus>) {
self.data.command.contact.remove_statuses = Some(StatusList { status: statuses });
}
pub fn load_from_epp_contact_info(
&mut self,
contact_info: EppContactInfoResponse,
) -> Result<(), error::Error> {
match contact_info.data.res_data {
Some(res_data) => {
self.data.command.contact.change_info = Some(ContactChangeInfo {
email: Some(res_data.info_data.email.clone()),
postal_info: Some(res_data.info_data.postal_info.clone()),
voice: Some(res_data.info_data.voice.clone()),
fax: res_data.info_data.fax.clone(),
auth_info: None,
});
Ok(())
}
None => Err(error::Error::Other(
"No res_data in EppContactInfoResponse object".to_string(),
)),
}
}
}