diff --git a/epp-client/src/contact.rs b/epp-client/src/contact.rs index 3e8ff0f..3aa3078 100644 --- a/epp-client/src/contact.rs +++ b/epp-client/src/contact.rs @@ -1 +1,2 @@ pub mod check; +pub mod create; diff --git a/epp-client/src/epp/request/contact/create.rs b/epp-client/src/contact/create.rs similarity index 78% rename from epp-client/src/epp/request/contact/create.rs rename to epp-client/src/contact/create.rs index 3f31f71..038fe65 100644 --- a/epp-client/src/epp/request/contact/create.rs +++ b/epp-client/src/contact/create.rs @@ -5,6 +5,7 @@ use epp_client_macros::*; use crate::epp::object::data; 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}; @@ -18,7 +19,7 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::epp::object::data::{Address, Phone, PostalInfo}; -/// use epp_client::epp::{EppContactCreate, EppContactCreateResponse}; +/// use epp_client::contact::create::{EppContactCreate, EppContactCreateResponse}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] @@ -72,7 +73,46 @@ use serde::{Deserialize, Serialize}; /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactCreate = EppObject>; +pub type EppContactCreate = EppObject>; + +impl EppContactCreate { + /// Creates a new EppObject for contact create corresponding to the <epp> tag in EPP XML + pub fn new( + id: &str, + email: &str, + postal_info: data::PostalInfo, + voice: data::Phone, + auth_password: &str, + client_tr_id: &str, + ) -> EppContactCreate { + let contact_create = ContactCreateRequest { + contact: Contact { + xmlns: EPP_CONTACT_XMLNS.to_string(), + id: id.into(), + postal_info, + voice, + fax: None, + email: email.into(), + auth_info: data::ContactAuthInfo::new(auth_password), + }, + }; + + EppObject::build(Command::::new( + contact_create, + client_tr_id, + )) + } + + /// Sets the <fax> data for the request + pub fn set_fax(&mut self, fax: data::Phone) { + self.data.command.contact.fax = Some(fax); + } +} + +/// Type that represents the <epp> tag for the EPP XML contact create response +pub type EppContactCreateResponse = EppObject>; + +// Request /// Type for elements under the contact <create> tag #[derive(Serialize, Deserialize, Debug)] @@ -103,39 +143,31 @@ pub struct Contact { #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "create")] /// Type for EPP XML <create> command for contacts -pub struct ContactCreate { +pub struct ContactCreateRequest { /// Data for <create> command for contact #[serde(rename = "contact:create", alias = "create")] pub contact: Contact, } -impl EppContactCreate { - /// Creates a new EppObject for contact create corresponding to the <epp> tag in EPP XML - pub fn new( - id: &str, - email: &str, - postal_info: data::PostalInfo, - voice: data::Phone, - auth_password: &str, - client_tr_id: &str, - ) -> EppContactCreate { - let contact_create = ContactCreate { - contact: Contact { - xmlns: EPP_CONTACT_XMLNS.to_string(), - id: id.into(), - postal_info, - voice, - fax: None, - email: email.into(), - auth_info: data::ContactAuthInfo::new(auth_password), - }, - }; +// Response - EppObject::build(Command::::new(contact_create, client_tr_id)) - } - - /// Sets the <fax> data for the request - pub fn set_fax(&mut self, fax: data::Phone) { - self.data.command.contact.fax = Some(fax); - } +/// Type that represents the <creData> tag for contact create response +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCreateData { + /// XML namespace for contact response data + #[serde(rename = "xmlns:contact")] + xmlns: String, + /// The contact id + pub id: StringValue, + #[serde(rename = "crDate")] + /// The contact creation date + pub created_at: StringValue, +} + +/// Type that represents the <resData> tag for contact create response +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCreateResult { + /// Data under the <creData> tag + #[serde(rename = "creData")] + pub create_data: ContactCreateData, } diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index b4a2057..88485d2 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::create::*; pub use request::contact::delete::*; pub use request::contact::info::*; pub use request::contact::update::*; @@ -17,7 +16,6 @@ pub use request::host::update::*; pub use request::message::ack::*; pub use request::message::poll::*; -pub use response::contact::create::*; pub use response::contact::delete::*; pub use response::contact::info::*; pub use response::contact::update::*; diff --git a/epp-client/src/epp/request/contact.rs b/epp-client/src/epp/request/contact.rs index 8cac739..bc3a47b 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 create; pub mod delete; pub mod info; pub mod update; diff --git a/epp-client/src/epp/response/contact.rs b/epp-client/src/epp/response/contact.rs index 6667fdc..98cf10e 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 create; pub mod delete; pub mod info; pub mod update; diff --git a/epp-client/src/epp/response/contact/create.rs b/epp-client/src/epp/response/contact/create.rs deleted file mode 100644 index a03fefc..0000000 --- a/epp-client/src/epp/response/contact/create.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Types for EPP contact 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 contact create response -pub type EppContactCreateResponse = EppObject>; - -/// Type that represents the <creData> tag for contact create response -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactCreateData { - /// XML namespace for contact response data - #[serde(rename = "xmlns:contact")] - xmlns: String, - /// The contact id - pub id: StringValue, - #[serde(rename = "crDate")] - /// The contact creation date - pub created_at: StringValue, -} - -/// Type that represents the <resData> tag for contact create response -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactCreateResult { - /// Data under the <creData> tag - #[serde(rename = "creData")] - pub create_data: ContactCreateData, -} diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index b6d58e4..24e6f71 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -4,6 +4,7 @@ mod response { use super::super::get_xml; use super::super::CLTRID; use crate::contact::check::EppContactCheckResponse; + use crate::contact::create::EppContactCreateResponse; 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 b7597d9..fa5a447 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -4,6 +4,7 @@ mod request { use super::super::get_xml; use super::super::CLTRID; use crate::contact::check::EppContactCheck; + use crate::contact::create::EppContactCreate; use crate::domain::check::EppDomainCheck; use crate::domain::create::EppDomainCreate; use crate::domain::delete::EppDomainDelete;