Refactor contact create models

This commit is contained in:
Nicholas Rempel 2021-11-26 10:14:15 -08:00 committed by masalachai
parent 964f3a7376
commit feedd6046f
8 changed files with 66 additions and 65 deletions

View File

@ -1 +1,2 @@
pub mod check; pub mod check;
pub mod create;

View File

@ -5,6 +5,7 @@ use epp_client_macros::*;
use crate::epp::object::data; use crate::epp::object::data;
use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command; use crate::epp::request::Command;
use crate::epp::response::CommandResponse;
use crate::epp::xml::EPP_CONTACT_XMLNS; use crate::epp::xml::EPP_CONTACT_XMLNS;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -18,7 +19,7 @@ use serde::{Deserialize, Serialize};
/// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient; /// use epp_client::EppClient;
/// use epp_client::epp::object::data::{Address, Phone, PostalInfo}; /// 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; /// use epp_client::epp::generate_client_tr_id;
/// ///
/// #[tokio::main] /// #[tokio::main]
@ -72,7 +73,46 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppContactCreate = EppObject<Command<ContactCreate>>; pub type EppContactCreate = EppObject<Command<ContactCreateRequest>>;
impl EppContactCreate {
/// Creates a new EppObject for contact create corresponding to the &lt;epp&gt; 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::<ContactCreateRequest>::new(
contact_create,
client_tr_id,
))
}
/// Sets the &lt;fax&gt; data for the request
pub fn set_fax(&mut self, fax: data::Phone) {
self.data.command.contact.fax = Some(fax);
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML contact create response
pub type EppContactCreateResponse = EppObject<CommandResponse<ContactCreateResult>>;
// Request
/// Type for elements under the contact &lt;create&gt; tag /// Type for elements under the contact &lt;create&gt; tag
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -103,39 +143,31 @@ pub struct Contact {
#[derive(Serialize, Deserialize, Debug, ElementName)] #[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "create")] #[element_name(name = "create")]
/// Type for EPP XML &lt;create&gt; command for contacts /// Type for EPP XML &lt;create&gt; command for contacts
pub struct ContactCreate { pub struct ContactCreateRequest {
/// Data for &lt;create&gt; command for contact /// Data for &lt;create&gt; command for contact
#[serde(rename = "contact:create", alias = "create")] #[serde(rename = "contact:create", alias = "create")]
pub contact: Contact, pub contact: Contact,
} }
impl EppContactCreate { // Response
/// Creates a new EppObject for contact create corresponding to the &lt;epp&gt; 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),
},
};
EppObject::build(Command::<ContactCreate>::new(contact_create, client_tr_id)) /// Type that represents the &lt;creData&gt; 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,
} }
/// Sets the &lt;fax&gt; data for the request /// Type that represents the &lt;resData&gt; tag for contact create response
pub fn set_fax(&mut self, fax: data::Phone) { #[derive(Serialize, Deserialize, Debug)]
self.data.command.contact.fax = Some(fax); pub struct ContactCreateResult {
} /// Data under the &lt;creData&gt; tag
#[serde(rename = "creData")]
pub create_data: ContactCreateData,
} }

View File

@ -5,7 +5,6 @@ pub mod request;
pub mod response; pub mod response;
pub mod xml; pub mod xml;
pub use request::contact::create::*;
pub use request::contact::delete::*; pub use request::contact::delete::*;
pub use request::contact::info::*; pub use request::contact::info::*;
pub use request::contact::update::*; pub use request::contact::update::*;
@ -17,7 +16,6 @@ pub use request::host::update::*;
pub use request::message::ack::*; pub use request::message::ack::*;
pub use request::message::poll::*; pub use request::message::poll::*;
pub use response::contact::create::*;
pub use response::contact::delete::*; pub use response::contact::delete::*;
pub use response::contact::info::*; pub use response::contact::info::*;
pub use response::contact::update::*; pub use response::contact::update::*;

View File

@ -1,6 +1,5 @@
//! Types for EPP contact requests //! Types for EPP contact requests
pub mod create;
pub mod delete; pub mod delete;
pub mod info; pub mod info;
pub mod update; pub mod update;

View File

@ -1,6 +1,5 @@
//! Types for EPP contact responses //! Types for EPP contact responses
pub mod create;
pub mod delete; pub mod delete;
pub mod info; pub mod info;
pub mod update; pub mod update;

View File

@ -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 &lt;epp&gt; tag for the EPP XML contact create response
pub type EppContactCreateResponse = EppObject<CommandResponse<ContactCreateResult>>;
/// Type that represents the &lt;creData&gt; 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 &lt;resData&gt; tag for contact create response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCreateResult {
/// Data under the &lt;creData&gt; tag
#[serde(rename = "creData")]
pub create_data: ContactCreateData,
}

View File

@ -4,6 +4,7 @@ mod response {
use super::super::get_xml; use super::super::get_xml;
use super::super::CLTRID; use super::super::CLTRID;
use crate::contact::check::EppContactCheckResponse; use crate::contact::check::EppContactCheckResponse;
use crate::contact::create::EppContactCreateResponse;
use crate::domain::check::EppDomainCheckResponse; use crate::domain::check::EppDomainCheckResponse;
use crate::domain::create::EppDomainCreateResponse; use crate::domain::create::EppDomainCreateResponse;
use crate::domain::delete::EppDomainDeleteResponse; use crate::domain::delete::EppDomainDeleteResponse;

View File

@ -4,6 +4,7 @@ mod request {
use super::super::get_xml; use super::super::get_xml;
use super::super::CLTRID; use super::super::CLTRID;
use crate::contact::check::EppContactCheck; use crate::contact::check::EppContactCheck;
use crate::contact::create::EppContactCreate;
use crate::domain::check::EppDomainCheck; use crate::domain::check::EppDomainCheck;
use crate::domain::create::EppDomainCreate; use crate::domain::create::EppDomainCreate;
use crate::domain::delete::EppDomainDelete; use crate::domain::delete::EppDomainDelete;