Refactor contact create models
This commit is contained in:
parent
964f3a7376
commit
feedd6046f
|
@ -1 +1,2 @@
|
||||||
pub mod check;
|
pub mod check;
|
||||||
|
pub mod create;
|
||||||
|
|
|
@ -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 <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::<ContactCreateRequest>::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<CommandResponse<ContactCreateResult>>;
|
||||||
|
|
||||||
|
// Request
|
||||||
|
|
||||||
/// Type for elements under the contact <create> tag
|
/// Type for elements under the contact <create> 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 <create> command for contacts
|
/// Type for EPP XML <create> command for contacts
|
||||||
pub struct ContactCreate {
|
pub struct ContactCreateRequest {
|
||||||
/// Data for <create> command for contact
|
/// Data for <create> 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 <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),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
EppObject::build(Command::<ContactCreate>::new(contact_create, client_tr_id))
|
/// 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the <fax> data for the request
|
/// Type that represents the <resData> 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 <creData> tag
|
||||||
|
#[serde(rename = "creData")]
|
||||||
|
pub create_data: ContactCreateData,
|
||||||
}
|
}
|
|
@ -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::*;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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<CommandResponse<ContactCreateResult>>;
|
|
||||||
|
|
||||||
/// 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,
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue