Refactor domain create models
This commit is contained in:
parent
c082a5e3bf
commit
341e06dc14
|
@ -1 +1,2 @@
|
|||
pub mod check;
|
||||
pub mod create;
|
||||
|
|
|
@ -7,6 +7,7 @@ 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_DOMAIN_XMLNS;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -21,7 +22,7 @@ use serde::{Deserialize, Serialize};
|
|||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||
/// use epp_client::EppClient;
|
||||
/// use epp_client::epp::object::data::DomainContact;
|
||||
/// use epp_client::epp::{EppDomainCreate, EppDomainCreateResponse};
|
||||
/// use epp_client::domain::create::{EppDomainCreate, EppDomainCreateResponse};
|
||||
/// use epp_client::epp::generate_client_tr_id;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
|
@ -76,11 +77,130 @@ use serde::{Deserialize, Serialize};
|
|||
/// client.logout().await.unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
pub type EppDomainCreate = EppObject<Command<DomainCreate>>;
|
||||
pub type EppDomainCreate = EppObject<Command<DomainCreateRequest>>;
|
||||
|
||||
impl EppDomainCreate {
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// with the <ns> tag containing <hostObj> tags
|
||||
pub fn new_with_ns(
|
||||
name: &str,
|
||||
period: u16,
|
||||
ns: &[&str],
|
||||
registrant_id: &str,
|
||||
auth_password: &str,
|
||||
contacts: Vec<DomainContact>,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let ns_list = ns.iter().map(|&n| n.into()).collect();
|
||||
|
||||
let domain_create = DomainCreateRequest {
|
||||
domain: DomainCreateRequestData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: Some(HostList::HostObjList(HostObjList { hosts: ns_list })),
|
||||
registrant: Some(registrant_id.into()),
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: Some(contacts),
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<DomainCreateRequest>::new(
|
||||
domain_create,
|
||||
client_tr_id,
|
||||
))
|
||||
}
|
||||
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// without any nameservers
|
||||
pub fn new(
|
||||
name: &str,
|
||||
period: u16,
|
||||
registrant_id: &str,
|
||||
auth_password: &str,
|
||||
contacts: Vec<DomainContact>,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let domain_create = DomainCreateRequest {
|
||||
domain: DomainCreateRequestData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: None,
|
||||
registrant: Some(registrant_id.into()),
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: Some(contacts),
|
||||
},
|
||||
};
|
||||
EppObject::build(Command::<DomainCreateRequest>::new(
|
||||
domain_create,
|
||||
client_tr_id,
|
||||
))
|
||||
}
|
||||
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// without any contacts
|
||||
pub fn new_without_contacts(
|
||||
name: &str,
|
||||
period: u16,
|
||||
auth_password: &str,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let domain_create = DomainCreateRequest {
|
||||
domain: DomainCreateRequestData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: None,
|
||||
registrant: None,
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: None,
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<DomainCreateRequest>::new(
|
||||
domain_create,
|
||||
client_tr_id,
|
||||
))
|
||||
}
|
||||
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// with the <ns> tag containing <hostAttr> tags
|
||||
pub fn new_with_host_attr(
|
||||
name: &str,
|
||||
period: u16,
|
||||
ns: Vec<HostAttr>,
|
||||
registrant_id: &str,
|
||||
auth_password: &str,
|
||||
contacts: Vec<DomainContact>,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let domain_create = DomainCreateRequest {
|
||||
domain: DomainCreateRequestData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: Some(HostList::HostAttrList(HostAttrList { hosts: ns })),
|
||||
registrant: Some(registrant_id.into()),
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: Some(contacts),
|
||||
},
|
||||
};
|
||||
EppObject::build(Command::<DomainCreateRequest>::new(
|
||||
domain_create,
|
||||
client_tr_id,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that represents the <epp> tag for the EPP XML domain create response
|
||||
pub type EppDomainCreateResponse = EppObject<CommandResponse<DomainCreateResponse>>;
|
||||
|
||||
// Request
|
||||
|
||||
/// Type for elements under the domain <create> tag
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DomainCreateData {
|
||||
pub struct DomainCreateRequestData {
|
||||
/// XML namespace for domain commands
|
||||
#[serde(rename = "xmlns:domain", alias = "xmlns")]
|
||||
xmlns: String,
|
||||
|
@ -108,112 +228,36 @@ pub struct DomainCreateData {
|
|||
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
||||
#[element_name(name = "create")]
|
||||
/// Type for EPP XML <create> command for domains
|
||||
pub struct DomainCreate {
|
||||
pub struct DomainCreateRequest {
|
||||
/// The data for the domain to be created with
|
||||
/// T being the type of nameserver list (`HostObjList` or `HostAttrList`)
|
||||
/// to be supplied
|
||||
#[serde(rename = "domain:create", alias = "create")]
|
||||
domain: DomainCreateData,
|
||||
domain: DomainCreateRequestData,
|
||||
}
|
||||
|
||||
impl EppDomainCreate {
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// with the <ns> tag containing <hostObj> tags
|
||||
pub fn new_with_ns(
|
||||
name: &str,
|
||||
period: u16,
|
||||
ns: &[&str],
|
||||
registrant_id: &str,
|
||||
auth_password: &str,
|
||||
contacts: Vec<DomainContact>,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let ns_list = ns.iter().map(|&n| n.into()).collect();
|
||||
// Response
|
||||
|
||||
let domain_create = DomainCreate {
|
||||
domain: DomainCreateData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: Some(HostList::HostObjList(HostObjList { hosts: ns_list })),
|
||||
registrant: Some(registrant_id.into()),
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: Some(contacts),
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
|
||||
/// Type that represents the <chkData> tag for domain create response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DomainCreateResponseData {
|
||||
/// XML namespace for domain response data
|
||||
#[serde(rename = "xmlns:domain")]
|
||||
xmlns: String,
|
||||
/// The domain name
|
||||
pub name: StringValue,
|
||||
/// The creation date
|
||||
#[serde(rename = "crDate")]
|
||||
pub created_at: StringValue,
|
||||
/// The expiry date
|
||||
#[serde(rename = "exDate")]
|
||||
pub expiring_at: StringValue,
|
||||
}
|
||||
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// without any nameservers
|
||||
pub fn new(
|
||||
name: &str,
|
||||
period: u16,
|
||||
registrant_id: &str,
|
||||
auth_password: &str,
|
||||
contacts: Vec<DomainContact>,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let domain_create = DomainCreate {
|
||||
domain: DomainCreateData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: None,
|
||||
registrant: Some(registrant_id.into()),
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: Some(contacts),
|
||||
},
|
||||
};
|
||||
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
|
||||
}
|
||||
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// without any contacts
|
||||
pub fn new_without_contacts(
|
||||
name: &str,
|
||||
period: u16,
|
||||
auth_password: &str,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let domain_create = DomainCreate {
|
||||
domain: DomainCreateData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: None,
|
||||
registrant: None,
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: None,
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
|
||||
}
|
||||
|
||||
/// Creates a new EppObject for domain create corresponding to the <epp> tag in EPP XML
|
||||
/// with the <ns> tag containing <hostAttr> tags
|
||||
pub fn new_with_host_attr(
|
||||
name: &str,
|
||||
period: u16,
|
||||
ns: Vec<HostAttr>,
|
||||
registrant_id: &str,
|
||||
auth_password: &str,
|
||||
contacts: Vec<DomainContact>,
|
||||
client_tr_id: &str,
|
||||
) -> EppDomainCreate {
|
||||
let domain_create = DomainCreate {
|
||||
domain: DomainCreateData {
|
||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||
name: name.into(),
|
||||
period: Period::new(period),
|
||||
ns: Some(HostList::HostAttrList(HostAttrList { hosts: ns })),
|
||||
registrant: Some(registrant_id.into()),
|
||||
auth_info: DomainAuthInfo::new(auth_password),
|
||||
contacts: Some(contacts),
|
||||
},
|
||||
};
|
||||
EppObject::build(Command::<DomainCreate>::new(domain_create, client_tr_id))
|
||||
}
|
||||
/// Type that represents the <resData> tag for domain create response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DomainCreateResponse {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "creData")]
|
||||
pub create_data: DomainCreateResponseData,
|
||||
}
|
|
@ -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::create::*;
|
||||
pub use request::domain::delete::*;
|
||||
pub use request::domain::info::*;
|
||||
pub use request::domain::renew::*;
|
||||
|
@ -31,7 +30,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::create::*;
|
||||
pub use response::domain::delete::*;
|
||||
pub use response::domain::info::*;
|
||||
pub use response::domain::renew::*;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Types for EPP domain requests
|
||||
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod info;
|
||||
pub mod renew;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Types for EPP domain responses
|
||||
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod info;
|
||||
pub mod renew;
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
//! Types for EPP domain 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 domain create response
|
||||
pub type EppDomainCreateResponse = EppObject<CommandResponse<DomainCreateResult>>;
|
||||
|
||||
/// Type that represents the <chkData> tag for domain create response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DomainCreateData {
|
||||
/// XML namespace for domain response data
|
||||
#[serde(rename = "xmlns:domain")]
|
||||
xmlns: String,
|
||||
/// The domain name
|
||||
pub name: StringValue,
|
||||
/// The creation date
|
||||
#[serde(rename = "crDate")]
|
||||
pub created_at: StringValue,
|
||||
/// The expiry date
|
||||
#[serde(rename = "exDate")]
|
||||
pub expiring_at: StringValue,
|
||||
}
|
||||
|
||||
/// Type that represents the <resData> tag for domain create response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct DomainCreateResult {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "creData")]
|
||||
pub create_data: DomainCreateData,
|
||||
}
|
|
@ -4,6 +4,7 @@ mod response {
|
|||
use super::super::get_xml;
|
||||
use super::super::CLTRID;
|
||||
use crate::domain::check::EppDomainCheckResponse;
|
||||
use crate::domain::create::EppDomainCreateResponse;
|
||||
use crate::epp::response::ExpiryType;
|
||||
use crate::epp::response::Relative;
|
||||
use crate::epp::response::{
|
||||
|
|
|
@ -4,6 +4,7 @@ mod request {
|
|||
use super::super::get_xml;
|
||||
use super::super::CLTRID;
|
||||
use crate::domain::check::EppDomainCheck;
|
||||
use crate::domain::create::EppDomainCreate;
|
||||
use crate::epp::object::data::{
|
||||
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
|
||||
HostStatus, Phone, PostalInfo,
|
||||
|
|
Loading…
Reference in New Issue