//! Common data types included in EPP Requests and Responses use crate::epp::object::{StringValue, StringValueTrait}; use serde::{Deserialize, Serialize}; /// The <status> attribute on EPP XML for domain transactions pub type DomainStatus = ContactStatus; /// The <status> attribute on EPP XML for host transactions pub type HostStatus = ContactStatus; /// The <hostAddr> types domain or host transactions #[derive(Serialize, Deserialize, Debug)] pub struct HostAddr { #[serde(rename = "ip")] pub ip_version: Option, #[serde(rename = "$value")] pub address: String, } impl HostAddr { /// Creates a 'v4' type HostAddr (mostly useful when you don't want to include an 'ip' attr in the XML) pub fn new(ip_version: &str, address: &str) -> HostAddr { HostAddr { ip_version: Some(ip_version.to_string()), address: address.to_string(), } } /// Creates a 'v4' type HostAddr pub fn new_v4(address: &str) -> HostAddr { HostAddr { ip_version: Some("v4".to_string()), address: address.to_string(), } } /// Creates a 'v6' type HostAddr pub fn new_v6(address: &str) -> HostAddr { HostAddr { ip_version: Some("v6".to_string()), address: address.to_string(), } } } /// The <host> type for host transactions #[derive(Serialize, Deserialize, Debug)] pub struct Host { /// The <hostName> tag #[serde(rename = "host:name", alias = "name")] pub name: StringValue, /// The <hostAddr> tags #[serde(rename = "host:addr", alias = "addr")] pub addresses: Option>, } /// The <hostAttr> type for domain transactions #[derive(Serialize, Deserialize, Debug)] pub struct HostAttr { /// The <hostName> tag #[serde(rename = "domain:hostName", alias = "hostName")] pub name: StringValue, /// The <hostAddr> tags #[serde(rename = "domain:hostAddr", alias = "hostAddr")] pub addresses: Option>, } /// Enum that can accept one type which corresponds to either the <hostObj> or <hostAttr> /// list of tags #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum HostList { HostObjList(HostObjList), HostAttrList(HostAttrList), } /// The list of <hostAttr> types for domain transactions. Typically under an <ns> tag #[derive(Serialize, Deserialize, Debug)] pub struct HostAttrList { /// The list of <hostAttr> tags #[serde(rename = "domain:hostAttr", alias = "hostAttr")] pub hosts: Vec, } /// The list of <hostObj> types for domain transactions. Typically under an <ns> tag #[derive(Serialize, Deserialize, Debug)] pub struct HostObjList { /// The list of <hostObj> tags #[serde(rename = "domain:hostObj", alias = "hostObj")] pub hosts: Vec, } /// The <contact> type on domain creation and update requests #[derive(Serialize, Deserialize, Debug)] pub struct DomainContact { /// The contact id #[serde(rename = "$value")] pub id: String, /// The contact type attr (usually admin, billing, or tech in most registries) #[serde(rename = "type")] pub contact_type: String, } /// The <period> type for registration, renewal or transfer on domain transactions #[derive(Serialize, Deserialize, Debug)] pub struct Period { /// The interval (usually 'y' indicating years) unit: String, /// The length of the registration, renewal or transfer period (usually in years) #[serde(rename = "$value")] length: u16, } impl Period { /// Creates a new period in years pub fn new(length: u16) -> Period { Period { unit: "y".to_string(), length, } } /// Sets the period unit ('y' for years, most commonly) pub fn set_unit(&mut self, unit: &str) { self.unit = unit.to_string(); } } /// The <status> type on contact transactions #[derive(Serialize, Deserialize, Debug)] pub struct ContactStatus { /// The status name, represented by the 's' attr on <status> tags #[serde(rename = "s")] pub status: String, } /// The data for <voice> and <fax> types on domain transactions #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Phone { /// The inner text on the <voice> and <fax> tags #[serde(rename = "$value")] pub number: String, /// The value of the 'x' attr on <voice> and <fax> tags #[serde(rename = "x")] pub extension: Option, } /// The <addr> type on contact transactions #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Address { /// The <street> tags under <addr> #[serde(rename = "contact:street", alias = "street")] pub street: Vec, /// The <city> tag under <addr> #[serde(rename = "contact:city", alias = "city")] pub city: StringValue, /// The <sp> tag under <addr> #[serde(rename = "contact:sp", alias = "sp")] pub province: StringValue, /// The <pc> tag under <addr> #[serde(rename = "contact:pc", alias = "pc")] pub postal_code: StringValue, /// The <cc> tag under <addr> #[serde(rename = "contact:cc", alias = "cc")] pub country_code: StringValue, } /// The <postalInfo> type on contact transactions #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PostalInfo { /// The 'type' attr on <postalInfo> #[serde(rename = "type")] pub info_type: String, /// The <name> tag under <postalInfo> #[serde(rename = "contact:name", alias = "name")] pub name: StringValue, /// The <org> tag under <postalInfo> #[serde(rename = "contact:org", alias = "org")] pub organization: StringValue, /// The <addr> tag under <postalInfo> #[serde(rename = "contact:addr", alias = "addr")] pub address: Address, } /// The <authInfo> tag for domain and contact transactions #[derive(Serialize, Deserialize, Debug, Clone)] pub struct DomainAuthInfo { /// The <pw> tag under <authInfo> #[serde(rename = "domain:pw", alias = "pw")] pub password: StringValue, } /// The <authInfo> tag for domain and contact transactions #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ContactAuthInfo { /// The <pw> tag under <authInfo> #[serde(rename = "contact:pw", alias = "pw")] pub password: StringValue, } impl Phone { /// Creates a new Phone instance with a given phone number pub fn new(number: &str) -> Phone { Phone { extension: None, number: number.to_string(), } } /// Sets the extension value of the Phone type pub fn set_extension(&mut self, ext: &str) { self.extension = Some(ext.to_string()); } } impl DomainAuthInfo { /// Creates a DomainAuthInfo instance with the given password pub fn new(password: &str) -> DomainAuthInfo { DomainAuthInfo { password: password.to_string_value(), } } } impl ContactAuthInfo { /// Creates a ContactAuthInfo instance with the given password pub fn new(password: &str) -> ContactAuthInfo { ContactAuthInfo { password: password.to_string_value(), } } } impl Address { /// Creates a new Address instance pub fn new( street: Vec<&str>, city: &str, province: &str, postal_code: &str, country_code: &str, ) -> Address { let street = street .iter() .map(|s| s.to_string_value()) .collect::>(); Address { street, city: city.to_string_value(), province: province.to_string_value(), postal_code: postal_code.to_string_value(), country_code: country_code.to_string_value(), } } } impl PostalInfo { /// Creates a new PostalInfo instance pub fn new(info_type: &str, name: &str, organization: &str, address: Address) -> PostalInfo { PostalInfo { info_type: info_type.to_string(), name: name.to_string_value(), organization: organization.to_string_value(), address, } } }