From c082a5e3bfb02c99ccf64582d8567bdc4e517130 Mon Sep 17 00:00:00 2001 From: Nick Rempel Date: Wed, 24 Nov 2021 21:36:05 -0800 Subject: [PATCH] Refactor domain check models --- epp-client/src/connection/client.rs | 2 +- epp-client/src/domain.rs | 1 + .../src/{epp/request => }/domain/check.rs | 83 +++++++++++++++---- epp-client/src/epp.rs | 2 - epp-client/src/epp/request/domain.rs | 1 - epp-client/src/epp/response/domain.rs | 1 - epp-client/src/epp/response/domain/check.rs | 49 ----------- epp-client/src/lib.rs | 3 +- epp-client/src/tests/de.rs | 1 + epp-client/src/tests/se.rs | 1 + 10 files changed, 73 insertions(+), 71 deletions(-) create mode 100644 epp-client/src/domain.rs rename epp-client/src/{epp/request => }/domain/check.rs (61%) delete mode 100644 epp-client/src/epp/response/domain/check.rs diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index 8cf3bb9..9aa34bc 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -7,7 +7,7 @@ //! //! use epp_client::config::{EppClientConfig, EppClientConnection}; //! use epp_client::EppClient; -//! use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse}; +//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse}; //! use epp_client::epp::generate_client_tr_id; //! //! #[tokio::main] diff --git a/epp-client/src/domain.rs b/epp-client/src/domain.rs new file mode 100644 index 0000000..3e8ff0f --- /dev/null +++ b/epp-client/src/domain.rs @@ -0,0 +1 @@ +pub mod check; diff --git a/epp-client/src/epp/request/domain/check.rs b/epp-client/src/domain/check.rs similarity index 61% rename from epp-client/src/epp/request/domain/check.rs rename to epp-client/src/domain/check.rs index 902785b..d788b00 100644 --- a/epp-client/src/epp/request/domain/check.rs +++ b/epp-client/src/domain/check.rs @@ -4,6 +4,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_DOMAIN_XMLNS; use serde::{Deserialize, Serialize}; @@ -16,7 +17,7 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse}; +/// use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] @@ -56,7 +57,31 @@ use serde::{Deserialize, Serialize}; /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainCheck = EppObject>; +pub type EppDomainCheck = EppObject>; + +impl EppDomainCheck { + /// Creates a new EppObject for domain check corresponding to the <epp> tag in EPP XML + pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck { + let domains = domains.into_iter().map(|d| d.into()).collect(); + + let domain_check = DomainCheckRequest { + list: DomainList { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + domains, + }, + }; + + EppObject::build(Command::::new( + domain_check, + client_tr_id, + )) + } +} + +/// Type that represents the <epp> tag for the EPP XML domain check response +pub type EppDomainCheckResponse = EppObject>; + +// Request /// Type for <name> elements under the domain <check> tag #[derive(Serialize, Deserialize, Debug)] @@ -72,24 +97,50 @@ pub struct DomainList { #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "check")] /// Type for EPP XML <check> command for domains -pub struct DomainCheck { +pub struct DomainCheckRequest { /// The object holding the list of domains to be checked #[serde(rename = "domain:check", alias = "check")] list: DomainList, } -impl EppDomainCheck { - /// Creates a new EppObject for domain check corresponding to the <epp> tag in EPP XML - pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck { - let domains = domains.into_iter().map(|d| d.into()).collect(); +// Response - let domain_check = DomainCheck { - list: DomainList { - xmlns: EPP_DOMAIN_XMLNS.to_string(), - domains, - }, - }; - - EppObject::build(Command::::new(domain_check, client_tr_id)) - } +/// Type that represents the <name> tag for domain check response +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainAvailable { + /// The domain name + #[serde(rename = "$value")] + pub name: StringValue, + /// The domain (un)availability + #[serde(rename = "avail")] + pub available: u16, +} + +/// Type that represents the <cd> tag for domain check response +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainCheckResponseDataItem { + /// Data under the <name> tag + #[serde(rename = "name")] + pub domain: DomainAvailable, + /// The reason for (un)availability + pub reason: Option, +} + +/// Type that represents the <chkData> tag for domain check response +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainCheckResponseData { + /// XML namespace for domain response data + #[serde(rename = "xmlns:domain")] + xmlns: String, + /// Data under the <cd> tag + #[serde(rename = "cd")] + pub domain_list: Vec, +} + +/// Type that represents the <resData> tag for domain check response +#[derive(Serialize, Deserialize, Debug)] +pub struct DomainCheckResponse { + /// Data under the <chkData> tag + #[serde(rename = "chkData")] + pub check_data: DomainCheckResponseData, } diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index 63b7046..9bba8bd 100644 --- a/epp-client/src/epp.rs +++ b/epp-client/src/epp.rs @@ -10,7 +10,6 @@ pub use request::contact::create::*; pub use request::contact::delete::*; pub use request::contact::info::*; pub use request::contact::update::*; -pub use request::domain::check::*; pub use request::domain::create::*; pub use request::domain::delete::*; pub use request::domain::info::*; @@ -32,7 +31,6 @@ pub use response::contact::create::*; pub use response::contact::delete::*; pub use response::contact::info::*; pub use response::contact::update::*; -pub use response::domain::check::*; pub use response::domain::create::*; pub use response::domain::delete::*; pub use response::domain::info::*; diff --git a/epp-client/src/epp/request/domain.rs b/epp-client/src/epp/request/domain.rs index 18462b3..1628907 100644 --- a/epp-client/src/epp/request/domain.rs +++ b/epp-client/src/epp/request/domain.rs @@ -1,6 +1,5 @@ //! Types for EPP domain requests -pub mod check; pub mod create; pub mod delete; pub mod info; diff --git a/epp-client/src/epp/response/domain.rs b/epp-client/src/epp/response/domain.rs index b3a8323..1db5412 100644 --- a/epp-client/src/epp/response/domain.rs +++ b/epp-client/src/epp/response/domain.rs @@ -1,6 +1,5 @@ //! Types for EPP domain responses -pub mod check; pub mod create; pub mod delete; pub mod info; diff --git a/epp-client/src/epp/response/domain/check.rs b/epp-client/src/epp/response/domain/check.rs deleted file mode 100644 index 7fda652..0000000 --- a/epp-client/src/epp/response/domain/check.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Types for EPP domain 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 domain check response -pub type EppDomainCheckResponse = EppObject>; - -/// Type that represents the <name> tag for domain check response -#[derive(Serialize, Deserialize, Debug)] -pub struct DomainCheck { - /// The domain name - #[serde(rename = "$value")] - pub name: StringValue, - /// The domain (un)availability - #[serde(rename = "avail")] - pub available: u16, -} - -/// Type that represents the <cd> tag for domain check response -#[derive(Serialize, Deserialize, Debug)] -pub struct DomainCheckDataItem { - /// Data under the <name> tag - #[serde(rename = "name")] - pub domain: DomainCheck, - /// The reason for (un)availability - pub reason: Option, -} - -/// Type that represents the <chkData> tag for domain check response -#[derive(Serialize, Deserialize, Debug)] -pub struct DomainCheckData { - /// XML namespace for domain response data - #[serde(rename = "xmlns:domain")] - xmlns: String, - /// Data under the <cd> tag - #[serde(rename = "cd")] - pub domain_list: Vec, -} - -/// Type that represents the <resData> tag for domain check response -#[derive(Serialize, Deserialize, Debug)] -pub struct DomainCheckResult { - /// Data under the <chkData> tag - #[serde(rename = "chkData")] - pub check_data: DomainCheckData, -} diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 39e64be..68f675e 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -43,7 +43,7 @@ //! //! use epp_client::config::{EppClientConfig, EppClientConnection}; //! use epp_client::EppClient; -//! use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse}; +//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse}; //! use epp_client::epp::generate_client_tr_id; //! //! #[tokio::main] @@ -102,6 +102,7 @@ extern crate log; pub mod config; pub mod connection; +pub mod domain; pub mod epp; pub mod error; pub use connection::client::EppClient; diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index 6f1a2c7..3b6995d 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::domain::check::EppDomainCheckResponse; use crate::epp::response::ExpiryType; use crate::epp::response::Relative; use crate::epp::response::{ diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index 3be9da9..d83fd91 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::domain::check::EppDomainCheck; use crate::epp::object::data::{ Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr, HostStatus, Phone, PostalInfo,