diff --git a/src/client.rs b/src/client.rs index 1cc84b7..ca4159a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -26,7 +26,7 @@ //! println!("{:?}", greeting); //! //! // Execute an EPP Command against the registry with distinct request and response objects -//! let domain_check = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]); +//! let domain_check = DomainCheck { domains: &["eppdev.com", "eppdev.net"] }; //! let response = client.transact(&domain_check, "transaction-id").await.unwrap(); //! println!("{:?}", response); //! diff --git a/src/contact/check.rs b/src/contact/check.rs index ebfede2..c1289d0 100644 --- a/src/contact/check.rs +++ b/src/contact/check.rs @@ -17,34 +17,41 @@ impl<'a> Command for ContactCheck<'a> { /// Type that represents the <check> command for contact transactions #[derive(Serialize, Debug)] -pub struct ContactList<'a> { +struct ContactList<'a> { /// The XML namespace for the contact <check> #[serde(rename = "xmlns:contact")] xmlns: &'a str, /// The list of contact ids to check for availability #[serde(rename = "contact:id")] - pub contact_ids: Vec>, + contact_ids: Vec>, } #[derive(Serialize, Debug)] -/// The <command> type for contact check command -pub struct ContactCheck<'a> { +struct SerializeContactCheck<'a> { /// The <check> tag for the contact check command #[serde(rename = "contact:check")] list: ContactList<'a>, } -impl<'a> ContactCheck<'a> { - pub fn new(contact_ids: &'a [&'a str]) -> Self { +impl<'a> From> for SerializeContactCheck<'a> { + fn from(check: ContactCheck<'a>) -> Self { Self { list: ContactList { xmlns: XMLNS, - contact_ids: contact_ids.iter().map(|&id| id.into()).collect(), + contact_ids: check.contact_ids.iter().map(|&id| id.into()).collect(), }, } } } +/// The EPP `check` command for contacts +#[derive(Clone, Debug, Serialize)] +#[serde(into = "SerializeContactCheck")] +pub struct ContactCheck<'a> { + /// The list of contact IDs to be checked + pub contact_ids: &'a [&'a str], +} + #[cfg(test)] mod tests { use super::ContactCheck; @@ -56,7 +63,9 @@ mod tests { #[test] fn command() { let xml = get_xml("request/contact/check.xml").unwrap(); - let object = ContactCheck::new(&["eppdev-contact-1", "eppdev-contact-2"]); + let object = ContactCheck { + contact_ids: &["eppdev-contact-1", "eppdev-contact-2"], + }; let serialized = >::serialize_request(&object, None, CLTRID) .unwrap(); diff --git a/src/domain/check.rs b/src/domain/check.rs index 1a7d142..2bc9430 100644 --- a/src/domain/check.rs +++ b/src/domain/check.rs @@ -12,36 +12,42 @@ impl<'a> Command for DomainCheck<'a> { const COMMAND: &'static str = "check"; } -impl<'a> DomainCheck<'a> { - pub fn new(domains: Vec<&'a str>) -> Self { +// Request + +/// Type for <name> elements under the domain <check> tag +#[derive(Serialize, Debug)] +struct DomainList<'a> { + #[serde(rename = "xmlns:domain")] + /// XML namespace for domain commands + xmlns: &'a str, + #[serde(rename = "domain:name")] + /// List of domains to be checked for availability + domains: Vec>, +} + +#[derive(Serialize, Debug)] +struct SerializeDomainCheck<'a> { + #[serde(rename = "domain:check")] + list: DomainList<'a>, +} + +impl<'a> From> for SerializeDomainCheck<'a> { + fn from(check: DomainCheck<'a>) -> Self { Self { list: DomainList { xmlns: XMLNS, - domains: domains.into_iter().map(|d| d.into()).collect(), + domains: check.domains.iter().map(|&d| d.into()).collect(), }, } } } -// Request - -/// Type for <name> elements under the domain <check> tag -#[derive(Serialize, Debug)] -pub struct DomainList<'a> { - #[serde(rename = "xmlns:domain")] - /// XML namespace for domain commands - pub xmlns: &'a str, - #[serde(rename = "domain:name")] - /// List of domains to be checked for availability - pub domains: Vec>, -} - -#[derive(Serialize, Debug)] -/// Type for EPP XML <check> command for domains +/// The EPP `check` command for domains +#[derive(Clone, Debug, Serialize)] +#[serde(into = "SerializeDomainCheck")] pub struct DomainCheck<'a> { - /// The object holding the list of domains to be checked - #[serde(rename = "domain:check")] - list: DomainList<'a>, + /// The list of domains to be checked + pub domains: &'a [&'a str], } #[cfg(test)] @@ -56,7 +62,9 @@ mod tests { fn command() { let xml = get_xml("request/domain/check.xml").unwrap(); - let object = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]); + let object = DomainCheck { + domains: &["eppdev.com", "eppdev.net"], + }; let serialized = >::serialize_request(&object, None, CLTRID) diff --git a/src/extensions/namestore.rs b/src/extensions/namestore.rs index dd19816..d3eb7eb 100644 --- a/src/extensions/namestore.rs +++ b/src/extensions/namestore.rs @@ -106,7 +106,9 @@ mod tests { let namestore_ext = NameStore::new("com"); - let object = DomainCheck::new(vec!["example1.com", "example2.com", "example3.com"]); + let object = DomainCheck { + domains: &["example1.com", "example2.com", "example3.com"], + }; let serialized = >::serialize_request( &object, diff --git a/src/host/check.rs b/src/host/check.rs index ea00076..ab24cbd 100644 --- a/src/host/check.rs +++ b/src/host/check.rs @@ -14,40 +14,46 @@ impl<'a> Command for HostCheck<'a> { const COMMAND: &'static str = "check"; } -impl<'a> HostCheck<'a> { - pub fn new(hosts: &[&'a str]) -> Self { - let hosts = hosts.iter().map(|&d| d.into()).collect(); - - Self { - list: HostList { - xmlns: XMLNS, - hosts, - }, - } - } -} - // Request /// Type for data under the host <check> tag #[derive(Serialize, Debug)] -pub struct HostList<'a> { +struct HostList<'a> { /// XML namespace for host commands #[serde(rename = "xmlns:host")] xmlns: &'a str, /// List of hosts to be checked for availability #[serde(rename = "host:name")] - pub hosts: Vec>, + hosts: Vec>, } #[derive(Serialize, Debug)] /// Type for EPP XML <check> command for hosts -pub struct HostCheck<'a> { +struct SerializeHostCheck<'a> { /// The instance holding the list of hosts to be checked #[serde(rename = "host:check")] list: HostList<'a>, } +impl<'a> From> for SerializeHostCheck<'a> { + fn from(check: HostCheck<'a>) -> Self { + Self { + list: HostList { + xmlns: XMLNS, + hosts: check.hosts.iter().map(|&id| id.into()).collect(), + }, + } + } +} + +/// The EPP `check` command for hosts +#[derive(Clone, Debug, Serialize)] +#[serde(into = "SerializeHostCheck")] +pub struct HostCheck<'a> { + /// The list of hosts to be checked + pub hosts: &'a [&'a str], +} + #[cfg(test)] mod tests { use super::HostCheck; @@ -60,7 +66,9 @@ mod tests { fn command() { let xml = get_xml("request/host/check.xml").unwrap(); - let object = HostCheck::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"]); + let object = HostCheck { + hosts: &["ns1.eppdev-1.com", "host1.eppdev-1.com"], + }; let serialized = >::serialize_request(&object, None, CLTRID) diff --git a/src/lib.rs b/src/lib.rs index 1c2f897..859e166 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,9 +64,9 @@ //! //! // Make a domain check call, which returns an object of type EppDomainCheckResponse //! // that contains the result of the call -//! let domain_check = DomainCheck::new( -//! vec!["eppdev.com", "eppdev.net"], -//! ); +//! let domain_check = DomainCheck { +//! domains: &["eppdev.com", "eppdev.net"], +//! }; //! //! let response = client.transact(&domain_check, "transaction-id").await.unwrap(); //! diff --git a/tests/basic.rs b/tests/basic.rs index ca90f49..11e17c8 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -101,7 +101,12 @@ async fn client() { .unwrap(); let rsp = client - .transact(&DomainCheck::new(vec!["eppdev.com", "eppdev.net"]), CLTRID) + .transact( + &DomainCheck { + domains: &["eppdev.com", "eppdev.net"], + }, + CLTRID, + ) .await .unwrap(); assert_eq!(rsp.result.code, ResultCode::CommandCompletedSuccessfully);