diff --git a/epp-client/src/domain.rs b/epp-client/src/domain.rs index 3e8ff0f..3aa3078 100644 --- a/epp-client/src/domain.rs +++ b/epp-client/src/domain.rs @@ -1 +1,2 @@ pub mod check; +pub mod create; diff --git a/epp-client/src/epp/request/domain/create.rs b/epp-client/src/domain/create.rs similarity index 76% rename from epp-client/src/epp/request/domain/create.rs rename to epp-client/src/domain/create.rs index 63f6d04..5f09d00 100644 --- a/epp-client/src/epp/request/domain/create.rs +++ b/epp-client/src/domain/create.rs @@ -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>; +pub type EppDomainCreate = EppObject>; + +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, + 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::::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, + 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::::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::::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, + registrant_id: &str, + auth_password: &str, + contacts: Vec, + 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::::new( + domain_create, + client_tr_id, + )) + } +} + +/// Type that represents the <epp> tag for the EPP XML domain create response +pub type EppDomainCreateResponse = EppObject>; + +// 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, - 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::::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, - 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::::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::::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, - registrant_id: &str, - auth_password: &str, - contacts: Vec, - 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::::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, +} + +/// 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, } diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index 9bba8bd..3512707 100644 --- a/epp-client/src/epp.rs +++ b/epp-client/src/epp.rs @@ -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::*; diff --git a/epp-client/src/epp/request/domain.rs b/epp-client/src/epp/request/domain.rs index 1628907..f3ee577 100644 --- a/epp-client/src/epp/request/domain.rs +++ b/epp-client/src/epp/request/domain.rs @@ -1,6 +1,5 @@ //! Types for EPP domain requests -pub mod create; pub mod delete; pub mod info; pub mod renew; diff --git a/epp-client/src/epp/response/domain.rs b/epp-client/src/epp/response/domain.rs index 1db5412..8d77b0c 100644 --- a/epp-client/src/epp/response/domain.rs +++ b/epp-client/src/epp/response/domain.rs @@ -1,6 +1,5 @@ //! Types for EPP domain responses -pub mod create; pub mod delete; pub mod info; pub mod renew; diff --git a/epp-client/src/epp/response/domain/create.rs b/epp-client/src/epp/response/domain/create.rs deleted file mode 100644 index c6470ba..0000000 --- a/epp-client/src/epp/response/domain/create.rs +++ /dev/null @@ -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>; - -/// 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, -} diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index 3b6995d..6fabc43 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::domain::check::EppDomainCheckResponse; + use crate::domain::create::EppDomainCreateResponse; use crate::epp::response::ExpiryType; use crate::epp::response::Relative; use crate::epp::response::{ diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index d83fd91..58f62be 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::domain::check::EppDomainCheck; + use crate::domain::create::EppDomainCreate; use crate::epp::object::data::{ Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr, HostStatus, Phone, PostalInfo,