diff --git a/src/common.rs b/src/common.rs index 72851c4..738e9dd 100644 --- a/src/common.rs +++ b/src/common.rs @@ -119,78 +119,6 @@ impl HostAddr { } } -/// 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 { @@ -266,14 +194,6 @@ pub struct PostalInfo { 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 { @@ -297,15 +217,6 @@ impl Phone { } } -impl DomainAuthInfo { - /// Creates a DomainAuthInfo instance with the given password - pub fn new(password: &str) -> DomainAuthInfo { - DomainAuthInfo { - password: password.into(), - } - } -} - impl ContactAuthInfo { /// Creates a ContactAuthInfo instance with the given password pub fn new(password: &str) -> ContactAuthInfo { diff --git a/src/domain.rs b/src/domain.rs index 41180bc..f5a9968 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -1,3 +1,7 @@ +use serde::{Deserialize, Serialize}; + +use crate::common::{HostAddr, StringValue}; + pub mod check; pub mod create; pub mod delete; @@ -8,4 +12,91 @@ pub mod update; pub const XMLNS: &str = "urn:ietf:params:xml:ns:domain-1.0"; +/// 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>, +} +/// 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, +} + +/// 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 <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 <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, +} + +impl DomainAuthInfo { + /// Creates a DomainAuthInfo instance with the given password + pub fn new(password: &str) -> DomainAuthInfo { + DomainAuthInfo { + password: password.into(), + } + } +} diff --git a/src/domain/create.rs b/src/domain/create.rs index f09cc6c..e5a80de 100644 --- a/src/domain/create.rs +++ b/src/domain/create.rs @@ -1,8 +1,9 @@ //! Types for EPP domain create request -use super::XMLNS; -use crate::common::{DomainAuthInfo, DomainContact, HostList, NoExtension, Period, StringValue}; +use super::{DomainAuthInfo, DomainContact, HostList, Period, XMLNS}; +use crate::common::{NoExtension, StringValue}; use crate::request::{Command, Transaction}; + use serde::{Deserialize, Serialize}; impl Transaction for DomainCreate {} @@ -102,10 +103,9 @@ pub struct DomainCreateResponse { #[cfg(test)] mod tests { - use super::DomainCreate; - use crate::common::{ - DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList, NoExtension, - }; + use super::{DomainContact, DomainCreate, HostList}; + use crate::common::{HostAddr, NoExtension}; + use crate::domain::{HostAttr, HostAttrList, HostObjList}; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; diff --git a/src/domain/info.rs b/src/domain/info.rs index edc403d..9ba63c8 100644 --- a/src/domain/info.rs +++ b/src/domain/info.rs @@ -1,9 +1,7 @@ //! Types for EPP domain info request -use super::XMLNS; -use crate::common::{ - DomainAuthInfo, DomainContact, DomainStatus, HostAttr, NoExtension, StringValue, -}; +use super::{DomainAuthInfo, DomainContact, HostAttr, XMLNS}; +use crate::common::{DomainStatus, NoExtension, StringValue}; use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; diff --git a/src/domain/renew.rs b/src/domain/renew.rs index 13fdea8..9432841 100644 --- a/src/domain/renew.rs +++ b/src/domain/renew.rs @@ -1,7 +1,7 @@ //! Types for EPP domain renew request -use super::XMLNS; -use crate::common::{NoExtension, Period, StringValue}; +use super::{Period, XMLNS}; +use crate::common::{NoExtension, StringValue}; use crate::request::{Command, Transaction}; use chrono::NaiveDate; use serde::{Deserialize, Serialize}; diff --git a/src/domain/transfer.rs b/src/domain/transfer.rs index 9276a7b..acec24f 100644 --- a/src/domain/transfer.rs +++ b/src/domain/transfer.rs @@ -1,7 +1,7 @@ //! Types for EPP domain transfer request -use super::XMLNS; -use crate::common::{DomainAuthInfo, NoExtension, Period, StringValue}; +use super::{DomainAuthInfo, Period, XMLNS}; +use crate::common::{NoExtension, StringValue}; use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; diff --git a/src/domain/update.rs b/src/domain/update.rs index 719166f..f6fd6b9 100644 --- a/src/domain/update.rs +++ b/src/domain/update.rs @@ -1,12 +1,11 @@ //! Types for EPP domain check request //! +use super::{DomainAuthInfo, DomainContact, HostList, XMLNS}; use crate::{ - common::{DomainAuthInfo, DomainContact, DomainStatus, HostList, NoExtension, StringValue}, + common::{DomainStatus, NoExtension, StringValue}, request::{Command, Transaction}, }; -use super::XMLNS; - use serde::Serialize; impl Transaction for DomainUpdate {} @@ -102,8 +101,8 @@ pub struct DomainUpdate { #[cfg(test)] mod tests { - use super::{DomainAddRemove, DomainChangeInfo, DomainUpdate}; - use crate::common::{DomainAuthInfo, DomainContact, DomainStatus, NoExtension}; + use super::{DomainAddRemove, DomainAuthInfo, DomainChangeInfo, DomainContact, DomainUpdate}; + use crate::common::{DomainStatus, NoExtension}; use crate::request::Transaction; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};