From 63c5aae4a91f0adbde88a9a96da05909ad723e1a Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Fri, 26 Nov 2021 10:30:07 -0800 Subject: [PATCH] Refactor host create models --- epp-client/src/epp.rs | 2 - epp-client/src/epp/request/host.rs | 1 - epp-client/src/epp/response/host.rs | 1 - epp-client/src/epp/response/host/create.rs | 30 --------- epp-client/src/host.rs | 1 + .../src/{epp/request => }/host/create.rs | 63 ++++++++++++++----- epp-client/src/tests/de.rs | 1 + epp-client/src/tests/se.rs | 1 + 8 files changed, 49 insertions(+), 51 deletions(-) delete mode 100644 epp-client/src/epp/response/host/create.rs rename epp-client/src/{epp/request => }/host/create.rs (72%) diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index bdc3f80..41af5e4 100644 --- a/epp-client/src/epp.rs +++ b/epp-client/src/epp.rs @@ -5,14 +5,12 @@ pub mod request; pub mod response; pub mod xml; -pub use request::host::create::*; pub use request::host::delete::*; pub use request::host::info::*; pub use request::host::update::*; pub use request::message::ack::*; pub use request::message::poll::*; -pub use response::host::create::*; pub use response::host::delete::*; pub use response::host::info::*; pub use response::host::update::*; diff --git a/epp-client/src/epp/request/host.rs b/epp-client/src/epp/request/host.rs index e2c1847..3e46c3c 100644 --- a/epp-client/src/epp/request/host.rs +++ b/epp-client/src/epp/request/host.rs @@ -1,6 +1,5 @@ //! Types for EPP host requests -pub mod create; pub mod delete; pub mod info; pub mod update; diff --git a/epp-client/src/epp/response/host.rs b/epp-client/src/epp/response/host.rs index 2852dbb..86b58b9 100644 --- a/epp-client/src/epp/response/host.rs +++ b/epp-client/src/epp/response/host.rs @@ -1,6 +1,5 @@ //! Types for EPP host responses -pub mod create; pub mod delete; pub mod info; pub mod update; diff --git a/epp-client/src/epp/response/host/create.rs b/epp-client/src/epp/response/host/create.rs deleted file mode 100644 index 75c609c..0000000 --- a/epp-client/src/epp/response/host/create.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Types for EPP host create 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 host create response -pub type EppHostCreateResponse = EppObject>; - -/// Type that represents the <creData> tag for host create response -#[derive(Serialize, Deserialize, Debug)] -pub struct HostCreateData { - /// XML namespace for host response data - #[serde(rename = "xmlns:host")] - xmlns: String, - /// The host name - pub name: StringValue, - /// The host creation date - #[serde(rename = "crDate")] - pub created_at: StringValue, -} - -/// Type that represents the <resData> tag for host check response -#[derive(Serialize, Deserialize, Debug)] -pub struct HostCreateResult { - /// Data under the <creData> tag - #[serde(rename = "creData")] - pub create_data: HostCreateData, -} diff --git a/epp-client/src/host.rs b/epp-client/src/host.rs index 3e8ff0f..3aa3078 100644 --- a/epp-client/src/host.rs +++ b/epp-client/src/host.rs @@ -1 +1,2 @@ pub mod check; +pub mod create; diff --git a/epp-client/src/epp/request/host/create.rs b/epp-client/src/host/create.rs similarity index 72% rename from epp-client/src/epp/request/host/create.rs rename to epp-client/src/host/create.rs index 4e20167..17a410b 100644 --- a/epp-client/src/epp/request/host/create.rs +++ b/epp-client/src/host/create.rs @@ -5,6 +5,7 @@ use epp_client_macros::*; use crate::epp::object::data::HostAddr; use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::request::Command; +use crate::epp::response::CommandResponse; use crate::epp::xml::EPP_HOST_XMLNS; use serde::{Deserialize, Serialize}; @@ -18,7 +19,7 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::epp::object::data::HostAddr; -/// use epp_client::epp::{EppHostCreate, EppHostCreateResponse}; +/// use epp_client::host::create::{EppHostCreate, EppHostCreateResponse}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] @@ -61,11 +62,31 @@ use serde::{Deserialize, Serialize}; /// client.logout().await.unwrap(); /// } /// ``` -pub type EppHostCreate = EppObject>; +pub type EppHostCreate = EppObject>; + +impl EppHostCreate { + /// Creates a new EppObject for host create corresponding to the <epp> tag in EPP XML + pub fn new(host: &str, addresses: Vec, client_tr_id: &str) -> EppHostCreate { + let host_create = HostCreateRequest { + host: HostCreateRequestData { + xmlns: EPP_HOST_XMLNS.to_string(), + name: host.into(), + addresses: Some(addresses), + }, + }; + + EppObject::build(Command::::new(host_create, client_tr_id)) + } +} + +/// Type that represents the <epp> tag for the EPP XML host create response +pub type EppHostCreateResponse = EppObject>; + +// Request /// Type for data under the host <create> tag #[derive(Serialize, Deserialize, Debug)] -pub struct HostCreateData { +pub struct HostCreateRequestData { /// XML namespace for host commands #[serde(rename = "xmlns:host", alias = "xmlns")] xmlns: String, @@ -80,23 +101,31 @@ pub struct HostCreateData { #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "create")] /// Type for EPP XML <create> command for hosts -pub struct HostCreate { +pub struct HostCreateRequest { /// The instance holding the data for the host to be created #[serde(rename = "host:create", alias = "create")] - host: HostCreateData, + host: HostCreateRequestData, } -impl EppHostCreate { - /// Creates a new EppObject for host create corresponding to the <epp> tag in EPP XML - pub fn new(host: &str, addresses: Vec, client_tr_id: &str) -> EppHostCreate { - let host_create = HostCreate { - host: HostCreateData { - xmlns: EPP_HOST_XMLNS.to_string(), - name: host.into(), - addresses: Some(addresses), - }, - }; +// Response - EppObject::build(Command::::new(host_create, client_tr_id)) - } +/// Type that represents the <creData> tag for host create response +#[derive(Serialize, Deserialize, Debug)] +pub struct HostCreateData { + /// XML namespace for host response data + #[serde(rename = "xmlns:host")] + xmlns: String, + /// The host name + pub name: StringValue, + /// The host creation date + #[serde(rename = "crDate")] + pub created_at: StringValue, +} + +/// Type that represents the <resData> tag for host check response +#[derive(Serialize, Deserialize, Debug)] +pub struct HostCreateResponse { + /// Data under the <creData> tag + #[serde(rename = "creData")] + pub create_data: HostCreateData, } diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index d06a6b8..92e75cc 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -28,6 +28,7 @@ mod response { use crate::epp::xml::EppXml; use crate::epp::*; use crate::host::check::EppHostCheckResponse; + use crate::host::create::EppHostCreateResponse; const SVTRID: &str = "RO-6879-1627224678242975"; const SUCCESS_MSG: &str = "Command completed successfully"; diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index 4cd3418..73f83c4 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -31,6 +31,7 @@ mod request { use crate::epp::xml::EppXml; use crate::epp::*; use crate::host::check::EppHostCheck; + use crate::host::create::EppHostCreate; use chrono::{DateTime, NaiveDate}; use std::str::FromStr;