//! Types for EPP domain check request use epp_client_macros::*; use crate::epp::object::data::{AuthInfo, DomainContact, DomainStatus, HostAttrList, HostObjList}; use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait}; use crate::epp::request::Command; use crate::epp::xml::EPP_DOMAIN_XMLNS; use serde::{Deserialize, Serialize}; /// Type that represents the <epp> request for domain <update> command /// with <hostObj> elements in the request for <ns> list /// /// ## Usage /// /// ```ignore /// use epp_client::EppClient; /// use epp_client::epp::object::data::{DomainStatus, DomainContact}; /// use epp_client::epp::{EppDomainUpdate, EppDomainUpdateResponse, DomainAddRemove}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] /// async fn main() { /// // Create an instance of EppClient, specifying the name of the registry as in /// // the config file /// let mut client = match EppClient::new("verisign").await { /// Ok(client) => client, /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// /// // Create an EppDomainUpdate instance /// let mut domain_update = EppDomainUpdate::new("eppdev-100.com", generate_client_tr_id(&client).as_str()); /// /// let add = DomainAddRemove { /// ns: None, /// contacts: None, /// statuses: Some(vec![ /// DomainStatus { /// status: "clientUpdateProhibited".to_string() /// } /// ]) /// }; /// /// let remove = DomainAddRemove { /// ns: None, /// contacts: Some(vec![ /// DomainContact { /// contact_type: "billing".to_string(), /// id: "eppdev-contact-2".to_string() /// } /// ]), /// statuses: None, /// }; /// /// domain_update.add(add); /// domain_update.remove(remove); /// /// // send it to the registry and receive a response of type EppDomainUpdateResponse /// let response = client.transact::<_, EppDomainUpdateResponse>(&domain_update).await.unwrap(); /// /// println!("{:?}", response); /// } /// ``` pub type EppDomainUpdate = EppObject>>; /// Type that represents the <epp> request for domain <update> command /// with <hostAttr> elements in the request for <ns> list pub type EppDomainUpdateWithHostAttr = EppObject>>; /// Type for elements under the <chg> tag for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainChangeInfo { /// The new registrant contact for the domain pub registrant: Option, /// The new auth info for the domain #[serde(rename = "authInfo")] pub auth_info: Option, } /// Type for elements under the <add> and <rem> tags for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainAddRemove { /// The list of nameservers to add or remove /// Type T can be either a `HostObjList` or `HostAttrList` #[serde(rename = "ns")] pub ns: Option, /// The list of contacts to add to or remove from the domain #[serde(rename = "contact")] pub contacts: Option>, /// The list of statuses to add to or remove from the domain #[serde(rename = "status")] pub statuses: Option>, } /// Type for elements under the <update> tag for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainUpdateData { /// XML namespace for domain commands pub xmlns: String, /// The name of the domain to update pub name: StringValue, /// `DomainAddRemove` Object containing the list of elements to be added /// to the domain pub add: Option>, /// `DomainAddRemove` Object containing the list of elements to be removed /// from the domain #[serde(rename = "rem")] pub remove: Option>, /// The data under the <chg> tag for domain update #[serde(rename = "chg")] pub change_info: Option, } #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "update")] /// Type for EPP XML <update> command for domains pub struct DomainUpdate { #[serde(rename = "update")] pub domain: DomainUpdateData, } impl EppDomainUpdate { /// Creates a new EppObject for domain update corresponding to the <epp> tag in EPP XML /// with the <ns> tag containing <hostObj> tags pub fn new(name: &str, client_tr_id: &str) -> EppDomainUpdate { EppObject::build(Command::>::new( DomainUpdate { domain: DomainUpdateData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.to_string_value(), add: None, remove: None, change_info: None, }, }, client_tr_id, )) } /// Sets the data for the <chg> tag pub fn info(&mut self, info: DomainChangeInfo) { self.data.command.domain.change_info = Some(info); } /// Sets the data for the <add> tag pub fn add(&mut self, add: DomainAddRemove) { self.data.command.domain.add = Some(add); } /// Sets the data for the <rem> tag pub fn remove(&mut self, remove: DomainAddRemove) { self.data.command.domain.remove = Some(remove); } } impl EppDomainUpdateWithHostAttr { /// Creates a new EppObject for domain update corresponding to the <epp> tag in EPP XML /// with the <ns> tag containing <hostAttr> tags pub fn new(name: &str, client_tr_id: &str) -> EppDomainUpdateWithHostAttr { EppObject::build(Command::>::new( DomainUpdate { domain: DomainUpdateData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.to_string_value(), add: None, remove: None, change_info: None, }, }, client_tr_id, )) } /// Sets the data for the <chg> tag pub fn info(&mut self, info: DomainChangeInfo) { self.data.command.domain.change_info = Some(info); } /// Sets the data for the <add> tag pub fn add(&mut self, add: DomainAddRemove) { self.data.command.domain.add = Some(add); } /// Sets the data for the <rem> tag pub fn remove(&mut self, remove: DomainAddRemove) { self.data.command.domain.remove = Some(remove); } }