From 964f3a737691ffb73feb89a4ceaee18d006de6ee Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Fri, 26 Nov 2021 10:11:14 -0800 Subject: [PATCH] Refactor contact check models --- epp-client/src/contact.rs | 1 + .../src/{epp/request => }/contact/check.rs | 89 +++++++++++++++---- epp-client/src/epp.rs | 2 - epp-client/src/epp/request/contact.rs | 1 - epp-client/src/epp/response/contact.rs | 1 - epp-client/src/epp/response/contact/check.rs | 49 ---------- epp-client/src/lib.rs | 1 + epp-client/src/tests/de.rs | 1 + epp-client/src/tests/se.rs | 1 + 9 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 epp-client/src/contact.rs rename epp-client/src/{epp/request => }/contact/check.rs (62%) delete mode 100644 epp-client/src/epp/response/contact/check.rs diff --git a/epp-client/src/contact.rs b/epp-client/src/contact.rs new file mode 100644 index 0000000..3e8ff0f --- /dev/null +++ b/epp-client/src/contact.rs @@ -0,0 +1 @@ +pub mod check; diff --git a/epp-client/src/epp/request/contact/check.rs b/epp-client/src/contact/check.rs similarity index 62% rename from epp-client/src/epp/request/contact/check.rs rename to epp-client/src/contact/check.rs index edefbdd..71476b2 100644 --- a/epp-client/src/epp/request/contact/check.rs +++ b/epp-client/src/contact/check.rs @@ -3,6 +3,7 @@ use epp_client_macros::*; use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::request::Command; +use crate::epp::response::CommandResponse; use crate::epp::xml::EPP_CONTACT_XMLNS; use serde::{Deserialize, Serialize}; @@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::epp::{EppContactCheck, EppContactCheckResponse}; +/// use epp_client::contact::check::{EppContactCheck, EppContactCheckResponse}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] @@ -55,7 +56,34 @@ use serde::{Deserialize, Serialize}; /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactCheck = EppObject>; +pub type EppContactCheck = EppObject>; + +impl EppContactCheck { + /// Creates an EppObject corresponding to the <epp> tag with data for a contact check request + pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck { + let contact_ids = contact_ids + .iter() + .map(|&d| d.into()) + .collect::>(); + + let contact_check = ContactCheckRequest { + list: ContactList { + xmlns: EPP_CONTACT_XMLNS.to_string(), + contact_ids, + }, + }; + + EppObject::build(Command::::new( + contact_check, + client_tr_id, + )) + } +} + +/// Type that represents the <epp> tag for the EPP XML contact check response +pub type EppContactCheckResponse = EppObject>; + +// Request /// Type that represents the <check> command for contact transactions #[derive(Serialize, Deserialize, Debug)] @@ -71,27 +99,50 @@ pub struct ContactList { #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "check")] /// The <command> type for contact check command -pub struct ContactCheck { +pub struct ContactCheckRequest { /// The <check> tag for the contact check command #[serde(rename = "contact:check", alias = "check")] list: ContactList, } -impl EppContactCheck { - /// Creates an EppObject corresponding to the <epp> tag with data for a contact check request - pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck { - let contact_ids = contact_ids - .iter() - .map(|&d| d.into()) - .collect::>(); +// Response - let contact_check = ContactCheck { - list: ContactList { - xmlns: EPP_CONTACT_XMLNS.to_string(), - contact_ids, - }, - }; - - EppObject::build(Command::::new(contact_check, client_tr_id)) - } +/// Type that represents the <id> tag for contact check response +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCheck { + /// The text of the <id> tag + #[serde(rename = "$value")] + pub id: StringValue, + /// The avail attr on the <id> tag + #[serde(rename = "avail")] + pub available: u16, +} + +/// Type that represents the <cd> tag for contact check response +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCheckResponseDataItem { + /// Data under the <id> tag + #[serde(rename = "id")] + pub contact: ContactCheck, + /// The reason for (un)availability + pub reason: Option, +} + +/// Type that represents the <chkData> tag for contact check response +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCheckResponseData { + /// XML namespace for contact response data + #[serde(rename = "xmlns:contact")] + xmlns: String, + /// Data under the <cd> tag + #[serde(rename = "cd")] + pub contact_list: Vec, +} + +/// Type that represents the <resData> tag for contact check response +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCheckResponse { + /// Data under the <chkData> tag + #[serde(rename = "chkData")] + pub check_data: ContactCheckResponseData, } diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index 21f7a26..b4a2057 100644 --- a/epp-client/src/epp.rs +++ b/epp-client/src/epp.rs @@ -5,7 +5,6 @@ pub mod request; pub mod response; pub mod xml; -pub use request::contact::check::*; pub use request::contact::create::*; pub use request::contact::delete::*; pub use request::contact::info::*; @@ -18,7 +17,6 @@ pub use request::host::update::*; pub use request::message::ack::*; pub use request::message::poll::*; -pub use response::contact::check::*; pub use response::contact::create::*; pub use response::contact::delete::*; pub use response::contact::info::*; diff --git a/epp-client/src/epp/request/contact.rs b/epp-client/src/epp/request/contact.rs index 50f15e3..8cac739 100644 --- a/epp-client/src/epp/request/contact.rs +++ b/epp-client/src/epp/request/contact.rs @@ -1,6 +1,5 @@ //! Types for EPP contact requests -pub mod check; pub mod create; pub mod delete; pub mod info; diff --git a/epp-client/src/epp/response/contact.rs b/epp-client/src/epp/response/contact.rs index ee8f7f9..6667fdc 100644 --- a/epp-client/src/epp/response/contact.rs +++ b/epp-client/src/epp/response/contact.rs @@ -1,6 +1,5 @@ //! Types for EPP contact responses -pub mod check; pub mod create; pub mod delete; pub mod info; diff --git a/epp-client/src/epp/response/contact/check.rs b/epp-client/src/epp/response/contact/check.rs deleted file mode 100644 index 2963112..0000000 --- a/epp-client/src/epp/response/contact/check.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Types for EPP contact check response - -use serde::{Deserialize, Serialize}; - -use crate::epp::object::{EppObject, StringValue}; -use crate::epp::response::CommandResponse; - -/// Type that represents the <epp> tag for the EPP XML contact check response -pub type EppContactCheckResponse = EppObject>; - -/// Type that represents the <id> tag for contact check response -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactCheck { - /// The text of the <id> tag - #[serde(rename = "$value")] - pub id: StringValue, - /// The avail attr on the <id> tag - #[serde(rename = "avail")] - pub available: u16, -} - -/// Type that represents the <cd> tag for contact check response -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactCheckDataItem { - /// Data under the <id> tag - #[serde(rename = "id")] - pub contact: ContactCheck, - /// The reason for (un)availability - pub reason: Option, -} - -/// Type that represents the <chkData> tag for contact check response -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactCheckData { - /// XML namespace for contact response data - #[serde(rename = "xmlns:contact")] - xmlns: String, - /// Data under the <cd> tag - #[serde(rename = "cd")] - pub contact_list: Vec, -} - -/// Type that represents the <resData> tag for contact check response -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactCheckResult { - /// Data under the <chkData> tag - #[serde(rename = "chkData")] - pub check_data: ContactCheckData, -} diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 68f675e..f61333b 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -102,6 +102,7 @@ extern crate log; pub mod config; pub mod connection; +pub mod contact; pub mod domain; pub mod epp; pub mod error; diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index b3e2f9e..b6d58e4 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -3,6 +3,7 @@ mod response { use super::super::get_xml; use super::super::CLTRID; + use crate::contact::check::EppContactCheckResponse; use crate::domain::check::EppDomainCheckResponse; use crate::domain::create::EppDomainCreateResponse; use crate::domain::delete::EppDomainDeleteResponse; diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index 6a0e6fc..b7597d9 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -3,6 +3,7 @@ mod request { use super::super::get_xml; use super::super::CLTRID; + use crate::contact::check::EppContactCheck; use crate::domain::check::EppDomainCheck; use crate::domain::create::EppDomainCreate; use crate::domain::delete::EppDomainDelete;