diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index 5bd2885..18ba96f 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -7,8 +7,9 @@ //! //! use epp_client::config::{EppClientConfig, EppClientConnection}; //! use epp_client::EppClient; -//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse}; +//! use epp_client::domain::check::DomainCheck; //! use epp_client::generate_client_tr_id; +//! use epp_client::common::NoExtension; //! //! #[tokio::main] //! async fn main() { @@ -39,8 +40,8 @@ //! println!("{:?}", greeting); //! //! // Execute an EPP Command against the registry with distinct request and response objects -//! let domain_check = EppDomainCheck::new(vec!["eppdev.com", "eppdev.net"], generate_client_tr_id(&client).as_str()); -//! let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap(); +//! let domain_check = DomainCheck::::new(vec!["eppdev.com", "eppdev.net"]); +//! let response = client.transact_new(domain_check, generate_client_tr_id(&client).as_str()).await.unwrap(); //! println!("{:?}", response); //! //! } @@ -49,14 +50,18 @@ use std::time::SystemTime; use std::{error::Error, fmt::Debug}; +use crate::common::{EppObject, NoExtension}; use crate::config::EppClientConfig; use crate::connection::registry::{epp_connect, EppConnection}; use crate::error; use crate::hello::{EppGreeting, EppHello}; -use crate::login::{EppLogin, EppLoginResponse}; -use crate::logout::{EppLogout, EppLogoutResponse}; +use crate::login::Login; +use crate::logout::Logout; use crate::request::{generate_client_tr_id, EppExtension, EppRequest}; -use crate::response::{CommandResponseWithExtension, EppCommandResponse, EppCommandResponseError}; +use crate::response::{ + CommandResponseStatus, CommandResponseWithExtension, EppCommandResponse, + EppCommandResponseError, +}; use crate::xml::EppXml; /// Instances of the EppClient type are used to transact with the registry. /// Once initialized, the EppClient instance can serialize EPP requests to XML and send them @@ -110,19 +115,17 @@ impl EppClient { connection, credentials, ext_uris, - // client_tr_id_fn: Arc::new(default_client_tr_id_fn), }; let client_tr_id = generate_client_tr_id(&client.credentials.0)?; - let login_request = EppLogin::new( + let login_request = Login::::new( &client.credentials.0, &client.credentials.1, &client.ext_uris, - client_tr_id.as_str(), ); client - .transact::<_, EppLoginResponse>(&login_request) + .transact_new(login_request, client_tr_id.as_str()) .await?; Ok(client) @@ -197,11 +200,16 @@ impl EppClient { } /// Sends the EPP Logout command to log out of the EPP session - pub async fn logout(&mut self) -> Result { + pub async fn logout( + &mut self, + ) -> Result< + CommandResponseWithExtension, NoExtension>, + error::Error, + > { let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap(); - let epp_logout = EppLogout::new(client_tr_id.as_str()); + let epp_logout = Logout::::new(); - let response = self.transact::<_, EppLogoutResponse>(&epp_logout).await?; + let response = self.transact_new(epp_logout, client_tr_id.as_str()).await?; self.connection.shutdown().await?; diff --git a/epp-client/src/contact/check.rs b/epp-client/src/contact/check.rs index b769dc0..b6afcb9 100644 --- a/epp-client/src/contact/check.rs +++ b/epp-client/src/contact/check.rs @@ -1,12 +1,28 @@ +use std::fmt::Debug; + /// Types for EPP contact check request use epp_client_macros::*; -use crate::common::{ElementName, EppObject, StringValue}; +use crate::common::{ElementName, NoExtension, StringValue}; use crate::contact::EPP_CONTACT_XMLNS; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct ContactCheck { + request: ContactCheckRequest, + extension: Option, +} + +impl EppRequest for ContactCheck { + type Input = ContactCheckRequest; + type Output = ContactCheckResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for contact <check> command /// /// ## Usage @@ -16,8 +32,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::contact::check::{EppContactCheck, EppContactCheckResponse}; +/// use epp_client::contact::check::ContactCheck; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -42,47 +59,45 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppContactCheck instance -/// let contact_check = EppContactCheck::new( -/// &["epp-client-c1", "epp-client-c2"], -/// generate_client_tr_id(&client).as_str() +/// // Create an ContactCheck instance +/// let contact_check = ContactCheck::::new( +/// &["epp-client-c1", "epp-client-c2"] /// ); /// -/// // send it to the registry and receive a response of type EppContactCheckResponse -/// let response = client.transact::<_, EppContactCheckResponse>(&contact_check).await.unwrap(); +/// // send it to the registry and receive a response of type ContactCheckResponse /// +/// let response = client.transact_new(contact_check, generate_client_tr_id(&client).as_str()).await.unwrap(); /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactCheck = EppObject>; - -impl EppContactCheck { - /// Creates an EppObject corresponding to the <epp> tag with data for a contact check request - pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck { +impl ContactCheck { + pub fn new(contact_ids: &[&str]) -> ContactCheck { let contact_ids = contact_ids .iter() .map(|&d| d.into()) .collect::>(); - let contact_check = ContactCheckRequest { - list: ContactList { - xmlns: EPP_CONTACT_XMLNS.to_string(), - contact_ids, + ContactCheck { + request: ContactCheckRequest { + list: ContactList { + xmlns: EPP_CONTACT_XMLNS.to_string(), + contact_ids, + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new( - contact_check, - client_tr_id, - )) + pub fn with_extension(self, extension: F) -> ContactCheck { + ContactCheck { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML contact check response -pub type EppContactCheckResponse = EppObject>; - // Request /// Type that represents the <check> command for contact transactions @@ -109,7 +124,7 @@ pub struct ContactCheckRequest { /// Type that represents the <id> tag for contact check response #[derive(Serialize, Deserialize, Debug)] -pub struct ContactCheck { +pub struct ContactAvailable { /// The text of the <id> tag #[serde(rename = "$value")] pub id: StringValue, @@ -123,7 +138,7 @@ pub struct ContactCheck { pub struct ContactCheckResponseDataItem { /// Data under the <id> tag #[serde(rename = "id")] - pub contact: ContactCheck, + pub contact: ContactAvailable, /// The reason for (un)availability pub reason: Option, } diff --git a/epp-client/src/contact/create.rs b/epp-client/src/contact/create.rs index 861421c..9139b8e 100644 --- a/epp-client/src/contact/create.rs +++ b/epp-client/src/contact/create.rs @@ -2,12 +2,26 @@ use epp_client_macros::*; -use crate::common::{ContactAuthInfo, ElementName, EppObject, Phone, PostalInfo, StringValue}; +use crate::common::{ContactAuthInfo, ElementName, NoExtension, Phone, PostalInfo, StringValue}; use crate::contact::EPP_CONTACT_XMLNS; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct ContactCreate { + request: ContactCreateRequest, + extension: Option, +} + +impl EppRequest for ContactCreate { + type Input = ContactCreateRequest; + type Output = ContactCreateResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for contact <create> command /// /// ## Usage @@ -18,8 +32,9 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::common::{Address, Phone, PostalInfo}; -/// use epp_client::contact::create::{EppContactCreate, EppContactCreateResponse}; +/// use epp_client::contact::create::ContactCreate; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -53,64 +68,61 @@ use serde::{Deserialize, Serialize}; /// let mut fax = Phone::new("+1.86698799"); /// fax.set_extension("677"); /// -/// // Create an EppContactCreate instance -/// let mut contact_create = EppContactCreate::new( +/// // Create an ContactCreate instance +/// let mut contact_create = ContactCreate::::new( /// "eppdev-contact-100", /// "contact@eppdev.net", /// postal_info, /// voice, -/// "epP4uthd#v", -/// generate_client_tr_id(&client).as_str() +/// "epP4uthd#v" /// ); /// contact_create.set_fax(fax); /// -/// // send it to the registry and receive a response of type EppContactCreateResponse -/// let response = client.transact::<_, EppContactCreateResponse>(&contact_create).await.unwrap(); +/// // send it to the registry and receive a response of type ContactCreateResponse +/// let response = client.transact_new(contact_create, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactCreate = EppObject>; - -impl EppContactCreate { - /// Creates a new EppObject for contact create corresponding to the <epp> tag in EPP XML +impl ContactCreate { pub fn new( id: &str, email: &str, postal_info: PostalInfo, voice: 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: ContactAuthInfo::new(auth_password), + ) -> ContactCreate { + ContactCreate { + request: ContactCreateRequest { + contact: Contact { + xmlns: EPP_CONTACT_XMLNS.to_string(), + id: id.into(), + postal_info, + voice, + fax: None, + email: email.into(), + auth_info: ContactAuthInfo::new(auth_password), + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new( - contact_create, - client_tr_id, - )) + pub fn with_extension(self, extension: F) -> ContactCreate { + ContactCreate { + request: self.request, + extension: Some(extension), + } } /// Sets the <fax> data for the request pub fn set_fax(&mut self, fax: Phone) { - self.data.command.contact.fax = Some(fax); + self.request.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 @@ -165,7 +177,7 @@ pub struct ContactCreateData { /// Type that represents the <resData> tag for contact create response #[derive(Serialize, Deserialize, Debug)] -pub struct ContactCreateResult { +pub struct ContactCreateResponse { /// Data under the <creData> tag #[serde(rename = "creData")] pub create_data: ContactCreateData, diff --git a/epp-client/src/contact/delete.rs b/epp-client/src/contact/delete.rs index 37af308..12bb81e 100644 --- a/epp-client/src/contact/delete.rs +++ b/epp-client/src/contact/delete.rs @@ -2,12 +2,27 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject, StringValue}; +use crate::common::{ElementName, NoExtension, StringValue}; use crate::contact::EPP_CONTACT_XMLNS; -use crate::request::Command; +use crate::request::{EppExtension, EppRequest}; use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct ContactDelete { + request: ContactDeleteRequest, + extension: Option, +} + +impl EppRequest for ContactDelete { + type Input = ContactDeleteRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type for the <epp> request for contact <delete> command /// /// ## Usage @@ -17,8 +32,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::contact::delete::{EppContactDelete, EppContactDeleteResponse}; +/// use epp_client::contact::delete::ContactDelete; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,42 +59,40 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppContactDelete instance -/// let contact_delete = EppContactDelete::new( -/// "eppdev-contact-100", -/// generate_client_tr_id(&client).as_str() +/// // Create an ContactDelete instance +/// let contact_delete = ContactDelete::::new( +/// "eppdev-contact-100" /// ); /// -/// // send it to the registry and receive a response of type EppContactDeleteResponse -/// let response = client.transact::<_, EppContactDeleteResponse>(&contact_delete).await.unwrap(); +/// // send it to the registry and receive a response of type ContactDeleteResponse +/// let response = client.transact_new(contact_delete, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactDelete = EppObject>; - -impl EppContactDelete { - /// Creates a new EppObject for contact delete corresponding to the <epp> tag in EPP XML - pub fn new(id: &str, client_tr_id: &str) -> EppContactDelete { - let contact_delete = ContactDeleteRequest { - contact: ContactDeleteRequestData { - xmlns: EPP_CONTACT_XMLNS.to_string(), - id: id.into(), +impl ContactDelete { + pub fn new(id: &str) -> ContactDelete { + ContactDelete { + request: ContactDeleteRequest { + contact: ContactDeleteRequestData { + xmlns: EPP_CONTACT_XMLNS.to_string(), + id: id.into(), + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new( - contact_delete, - client_tr_id, - )) + pub fn with_extension(self, extension: F) -> ContactDelete { + ContactDelete { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML contact delete response -pub type EppContactDeleteResponse = EppCommandResponse; - /// Type containing the data for the <delete> tag for contacts #[derive(Serialize, Deserialize, Debug)] pub struct ContactDeleteRequestData { diff --git a/epp-client/src/contact/info.rs b/epp-client/src/contact/info.rs index 555e144..6b10d15 100644 --- a/epp-client/src/contact/info.rs +++ b/epp-client/src/contact/info.rs @@ -3,13 +3,27 @@ use epp_client_macros::*; use crate::common::{ - ContactAuthInfo, ContactStatus, ElementName, EppObject, Phone, PostalInfo, StringValue, + ContactAuthInfo, ContactStatus, ElementName, NoExtension, Phone, PostalInfo, StringValue, }; use crate::contact::EPP_CONTACT_XMLNS; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct ContactInfo { + request: ContactInfoRequest, + extension: Option, +} + +impl EppRequest for ContactInfo { + type Input = ContactInfoRequest; + type Output = ContactInfoResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type for the <epp> request for contact <info> command /// /// ## Usage @@ -19,8 +33,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::contact::info::{EppContactInfo, EppContactInfoResponse}; +/// use epp_client::contact::info::ContactInfo; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -45,44 +60,42 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppContactInfo instance -/// let contact_info = EppContactInfo::new( +/// // Create an ContactInfo instance +/// let contact_info = ContactInfo::::new( /// "eppdev-contact-100", -/// "epP4uthd#v", -/// generate_client_tr_id(&client).as_str() +/// "epP4uthd#v" /// ); /// -/// // send it to the registry and receive a response of type EppContactInfoResponse -/// let response = client.transact::<_, EppContactInfoResponse>(&contact_info).await.unwrap(); +/// // send it to the registry and receive a response of type ContactInfoResponse +/// let response = client.transact_new(contact_info, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactInfo = EppObject>; - -impl EppContactInfo { - /// Creates a new EppObject for contact info corresponding to the <epp> tag in EPP XML - pub fn new(id: &str, auth_password: &str, client_tr_id: &str) -> EppContactInfo { - let contact_info = ContactInfoRequest { - info: ContactInfoRequestData { - xmlns: EPP_CONTACT_XMLNS.to_string(), - id: id.into(), - auth_info: ContactAuthInfo::new(auth_password), +impl ContactInfo { + pub fn new(id: &str, auth_password: &str) -> ContactInfo { + ContactInfo { + request: ContactInfoRequest { + info: ContactInfoRequestData { + xmlns: EPP_CONTACT_XMLNS.to_string(), + id: id.into(), + auth_info: ContactAuthInfo::new(auth_password), + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new( - contact_info, - client_tr_id, - )) + pub fn with_extension(self, extension: F) -> ContactInfo { + ContactInfo { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML contact info response -pub type EppContactInfoResponse = EppObject>; - // Request /// Type for elements under the contact <info> tag diff --git a/epp-client/src/contact/update.rs b/epp-client/src/contact/update.rs index 219584a..89a4980 100644 --- a/epp-client/src/contact/update.rs +++ b/epp-client/src/contact/update.rs @@ -3,15 +3,28 @@ use epp_client_macros::*; use crate::common::{ - ContactAuthInfo, ContactStatus, ElementName, EppObject, Phone, PostalInfo, StringValue, + ContactAuthInfo, ContactStatus, ElementName, NoExtension, Phone, PostalInfo, StringValue, }; -use crate::contact::info::EppContactInfoResponse; use crate::contact::EPP_CONTACT_XMLNS; -use crate::error; -use crate::request::Command; +use crate::request::{EppExtension, EppRequest}; use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct ContactUpdate { + request: ContactUpdateRequest, + extension: Option, +} + +impl EppRequest for ContactUpdate { + type Input = ContactUpdateRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for contact <update> command /// /// ## Usage @@ -21,9 +34,10 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::contact::update::{EppContactUpdate, EppContactUpdateResponse}; +/// use epp_client::contact::update::ContactUpdate; /// use epp_client::generate_client_tr_id; /// use epp_client::common::ContactStatus; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -48,10 +62,9 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppContactUpdate instance -/// let mut contact_update = EppContactUpdate::new( -/// "eppdev-contact-100", -/// generate_client_tr_id(&client).as_str() +/// // Create an ContactUpdate instance +/// let mut contact_update = ContactUpdate::::new( +/// "eppdev-contact-100" /// ); /// /// let add_statuses = vec![ @@ -62,32 +75,35 @@ use serde::{Deserialize, Serialize}; /// /// contact_update.add(add_statuses); /// -/// // send it to the registry and receive a response of type EppContactUpdateResponse -/// let response = client.transact::<_, EppContactUpdateResponse>(&contact_update).await.unwrap(); +/// // send it to the registry and receive a response of type ContactUpdateResponse +/// let response = client.transact_new(contact_update, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactUpdate = EppObject>; - -impl EppContactUpdate { - /// Creates a new EppObject for contact update corresponding to the <epp> tag in EPP XML - pub fn new(id: &str, client_tr_id: &str) -> EppContactUpdate { - let contact_update = ContactUpdateRequest { - contact: ContactUpdateRequestData { - xmlns: EPP_CONTACT_XMLNS.to_string(), - id: id.into(), - add_statuses: None, - remove_statuses: None, - change_info: None, +impl ContactUpdate { + pub fn new(id: &str) -> ContactUpdate { + ContactUpdate { + request: ContactUpdateRequest { + contact: ContactUpdateRequestData { + xmlns: EPP_CONTACT_XMLNS.to_string(), + id: id.into(), + add_statuses: None, + remove_statuses: None, + change_info: None, + }, }, - }; - EppObject::build(Command::::new( - contact_update, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> ContactUpdate { + ContactUpdate { + request: self.request, + extension: Some(extension), + } } /// Sets the data for the <chg> tag for the contact update request @@ -98,7 +114,7 @@ impl EppContactUpdate { voice: Phone, auth_password: &str, ) { - self.data.command.contact.change_info = Some(ContactChangeInfo { + self.request.contact.change_info = Some(ContactChangeInfo { email: Some(email.into()), postal_info: Some(postal_info), voice: Some(voice), @@ -109,47 +125,22 @@ impl EppContactUpdate { /// Sets the data for the <fax> tag under <chg> for the contact update request pub fn set_fax(&mut self, fax: Phone) { - if let Some(info) = &mut self.data.command.contact.change_info { + if let Some(info) = &mut self.request.contact.change_info { info.fax = Some(fax) } } /// Sets the data for the <add> tag for the contact update request pub fn add(&mut self, statuses: Vec) { - self.data.command.contact.add_statuses = Some(StatusList { status: statuses }); + self.request.contact.add_statuses = Some(StatusList { status: statuses }); } /// Sets the data for the <rem> tag for the contact update request pub fn remove(&mut self, statuses: Vec) { - self.data.command.contact.remove_statuses = Some(StatusList { status: statuses }); - } - - /// Loads data into the <chg> tag from an existing EppContactInfoResponse object - pub fn load_from_epp_contact_info( - &mut self, - contact_info: EppContactInfoResponse, - ) -> Result<(), error::Error> { - match contact_info.data.res_data { - Some(res_data) => { - self.data.command.contact.change_info = Some(ContactChangeInfo { - email: Some(res_data.info_data.email.clone()), - postal_info: Some(res_data.info_data.postal_info.clone()), - voice: Some(res_data.info_data.voice.clone()), - fax: res_data.info_data.fax, - auth_info: None, - }); - Ok(()) - } - None => Err(error::Error::Other( - "No res_data in EppContactInfoResponse object".to_string(), - )), - } + self.request.contact.remove_statuses = Some(StatusList { status: statuses }); } } -/// Type that represents the <epp> tag for the EPP XML contact update response -pub type EppContactUpdateResponse = EppCommandResponse; - /// Type for elements under the <chg> tag for contact update request #[derive(Serialize, Deserialize, Debug)] pub struct ContactChangeInfo { diff --git a/epp-client/src/domain/check.rs b/epp-client/src/domain/check.rs index 9719bed..f39fd15 100644 --- a/epp-client/src/domain/check.rs +++ b/epp-client/src/domain/check.rs @@ -3,11 +3,25 @@ use epp_client_macros::*; use super::EPP_DOMAIN_XMLNS; -use crate::common::{ElementName, EppObject, StringValue}; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::common::{ElementName, NoExtension, StringValue}; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainCheck { + request: DomainCheckRequest, + extension: Option, +} + +impl EppRequest for DomainCheck { + type Input = DomainCheckRequest; + type Output = DomainCheckResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for domain <check> command /// /// ## Usage @@ -17,8 +31,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse}; +/// use epp_client::domain::check::DomainCheck; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,44 +58,43 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainCheck instance -/// let domain_check = EppDomainCheck::new( +/// // Create an DomainCheck instance +/// let domain_check = DomainCheck::::new( /// vec!["eppdev-100.com", "eppdev-100.net"], -/// generate_client_tr_id(&client).as_str() /// ); /// /// // send it to the registry and receive a response of type EppDomainCheckResponse -/// let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap(); +/// let response = client.transact_new(domain_check, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainCheck = EppObject>; - -impl EppDomainCheck { - /// Creates a new EppObject for domain check corresponding to the <epp> tag in EPP XML - pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck { - let domains = domains.into_iter().map(|d| d.into()).collect(); - - let domain_check = DomainCheckRequest { - list: DomainList { - xmlns: EPP_DOMAIN_XMLNS.to_string(), - domains, +impl DomainCheck { + pub fn new(domains: Vec<&str>) -> DomainCheck { + DomainCheck { + request: DomainCheckRequest { + list: DomainList { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + domains: domains + .into_iter() + .map(|d| d.into()) + .collect::>(), + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new( - domain_check, - client_tr_id, - )) + pub fn with_extension(self, extension: F) -> DomainCheck { + DomainCheck { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML domain check response -pub type EppDomainCheckResponse = EppObject>; - // Request /// Type for <name> elements under the domain <check> tag diff --git a/epp-client/src/domain/create.rs b/epp-client/src/domain/create.rs index 4d8bf73..95b9d22 100644 --- a/epp-client/src/domain/create.rs +++ b/epp-client/src/domain/create.rs @@ -4,13 +4,26 @@ use epp_client_macros::*; use super::EPP_DOMAIN_XMLNS; use crate::common::{ - DomainAuthInfo, DomainContact, ElementName, EppObject, HostAttr, HostAttrList, HostList, - HostObjList, Period, StringValue, + DomainAuthInfo, DomainContact, ElementName, HostList, NoExtension, Period, StringValue, }; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainCreate { + request: DomainCreateRequest, + extension: Option, +} + +impl EppRequest for DomainCreate { + type Input = DomainCreateRequest; + type Output = DomainCreateResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for domain <create> command /// with <hostObj> elements in the request for <ns> list /// @@ -22,9 +35,13 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::common::DomainContact; -/// use epp_client::domain::create::{EppDomainCreate, EppDomainCreateResponse}; +/// use epp_client::domain::create::DomainCreate; /// use epp_client::generate_client_tr_id; -/// +/// use epp_client::common::NoExtension; +/// use epp_client::common::HostAttrList; +/// use epp_client::common::HostList; +/// use epp_client::common::HostObjList; + /// #[tokio::main] /// async fn main() { /// // Create a config @@ -48,154 +65,78 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// /// Create a vector of existing domain contact IDs /// let contacts = vec![ /// DomainContact { /// contact_type: "admin".to_string(), -/// id: "eppdev-contact-2".to_string() +/// id: "eppdev-contact-3".to_string(), /// }, /// DomainContact { /// contact_type: "tech".to_string(), -/// id: "eppdev-contact-2".to_string() +/// id: "eppdev-contact-3".to_string(), /// }, /// DomainContact { /// contact_type: "billing".to_string(), -/// id: "eppdev-contact-2".to_string() -/// } +/// id: "eppdev-contact-3".to_string(), +/// }, /// ]; -/// -/// // Create an EppDomainCreate instance -/// let domain_create = EppDomainCreate::new( -/// "eppdev-100.com", 1, "eppdev-contact-2", "epP4uthd#v", contacts, generate_client_tr_id(&client).as_str() + +/// let ns = Some(HostList::HostObjList(HostObjList { +/// hosts: vec!["ns1.test.com".into(), "ns2.test.com".into()], +/// })); + +/// let domain_create = DomainCreate::::new( +/// "eppdev-1.com", +/// 1, +/// ns, +/// Some("eppdev-contact-3"), +/// "epP4uthd#v", +/// Some(contacts), /// ); /// /// // send it to the registry and receive a response of type EppDomainCreateResponse -/// let response = client.transact::<_, EppDomainCreateResponse>(&domain_create).await.unwrap(); +/// let response = client.transact_new(domain_create, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -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 +impl DomainCreate { pub fn new( name: &str, period: u16, - registrant_id: &str, + ns: Option, + registrant_id: Option<&str>, auth_password: &str, - contacts: Vec, - client_tr_id: &str, - ) -> EppDomainCreate { + contacts: Option>, + ) -> DomainCreate { + let registrant = registrant_id.map(|id| id.into()); 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()), + ns, + registrant, auth_info: DomainAuthInfo::new(auth_password), - contacts: Some(contacts), + contacts, }, }; - EppObject::build(Command::::new( - domain_create, - client_tr_id, - )) + + DomainCreate { + request: domain_create, + extension: None, + } } - /// 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, - )) + pub fn with_extension(self, extension: F) -> DomainCreate { + DomainCreate { + request: self.request, + extension: Some(extension), + } } } -/// 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 @@ -203,26 +144,26 @@ pub type EppDomainCreateResponse = EppObject, + pub ns: Option, /// The domain registrant #[serde(rename = "domain:registrant", alias = "registrant")] - registrant: Option, + pub registrant: Option, /// The list of contacts for the domain #[serde(rename = "domain:contact", alias = "contact")] - contacts: Option>, + pub contacts: Option>, /// The auth info for the domain #[serde(rename = "domain:authInfo", alias = "authInfo")] - auth_info: DomainAuthInfo, + pub auth_info: DomainAuthInfo, } #[derive(Serialize, Deserialize, Debug, ElementName)] @@ -233,7 +174,7 @@ pub struct DomainCreateRequest { /// T being the type of nameserver list (`HostObjList` or `HostAttrList`) /// to be supplied #[serde(rename = "domain:create", alias = "create")] - domain: DomainCreateRequestData, + pub domain: DomainCreateRequestData, } // Response @@ -243,7 +184,7 @@ pub struct DomainCreateRequest { pub struct DomainCreateResponseData { /// XML namespace for domain response data #[serde(rename = "xmlns:domain")] - xmlns: String, + pub xmlns: String, /// The domain name pub name: StringValue, /// The creation date diff --git a/epp-client/src/domain/delete.rs b/epp-client/src/domain/delete.rs index f665d64..5bdb414 100644 --- a/epp-client/src/domain/delete.rs +++ b/epp-client/src/domain/delete.rs @@ -3,11 +3,26 @@ use epp_client_macros::*; use super::EPP_DOMAIN_XMLNS; -use crate::common::{ElementName, EppObject, StringValue}; -use crate::request::Command; +use crate::common::{ElementName, NoExtension, StringValue}; +use crate::request::{EppExtension, EppRequest}; use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainDelete { + request: DomainDeleteRequest, + extension: Option, +} + +impl EppRequest for DomainDelete { + type Input = DomainDeleteRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for domain <delete> command /// /// ## Usage @@ -17,8 +32,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::delete::{EppDomainDelete, EppDomainDeleteResponse}; +/// use epp_client::domain::delete::DomainDelete; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,37 +59,38 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainDelete instance -/// let mut domain_delete = EppDomainDelete::new("eppdev-100.com", generate_client_tr_id(&client).as_str()); +/// // Create an DomainDelete instance +/// let mut domain_delete = DomainDelete::::new("eppdev-100.com"); /// -/// // send it to the registry and receive a response of type EppDomainDeleteResponse -/// let response = client.transact::<_, EppDomainDeleteResponse>(&domain_delete).await.unwrap(); +/// // send it to the registry and receive a response of type DomainDeleteResponse +/// let response = client.transact_new(domain_delete, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainDelete = EppObject>; - -impl EppDomainDelete { - /// Creates a new EppObject for domain delete corresponding to the <epp> tag in EPP XML - pub fn new(name: &str, client_tr_id: &str) -> EppDomainDelete { - EppObject::build(Command::::new( - DomainDeleteRequest { +impl DomainDelete { + pub fn new(name: &str) -> DomainDelete { + DomainDelete { + request: DomainDeleteRequest { domain: DomainDeleteRequestData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.into(), }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainDelete { + DomainDelete { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML domain delete response -pub type EppDomainDeleteResponse = EppCommandResponse; - /// Type for <name> element under the domain <delete> tag #[derive(Serialize, Deserialize, Debug)] pub struct DomainDeleteRequestData { diff --git a/epp-client/src/domain/info.rs b/epp-client/src/domain/info.rs index 0546abe..8f7c984 100644 --- a/epp-client/src/domain/info.rs +++ b/epp-client/src/domain/info.rs @@ -4,13 +4,26 @@ use epp_client_macros::*; use super::EPP_DOMAIN_XMLNS; use crate::common::{ - DomainAuthInfo, DomainContact, DomainStatus, ElementName, EppObject, HostAttr, StringValue, + DomainAuthInfo, DomainContact, DomainStatus, ElementName, HostAttr, NoExtension, StringValue, }; -use crate::domain::rgp::request::RgpRequestResponse; -use crate::request::Command; -use crate::response::CommandResponseWithExtension; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainInfo { + request: DomainInfoRequest, + extension: Option, +} + +impl EppRequest for DomainInfo { + type Input = DomainInfoRequest; + type Output = DomainInfoResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for domain <info> command /// /// ## Usage @@ -20,8 +33,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::info::{EppDomainInfo, EppDomainInfoResponse}; +/// use epp_client::domain::info::DomainInfo; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -46,24 +60,21 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainInfo instance -/// let domain_info = EppDomainInfo::new("eppdev-100.com", generate_client_tr_id(&client).as_str()); +/// // Create an DomainInfo instance +/// let domain_info = DomainInfo::::new("eppdev-100.com"); /// -/// // send it to the registry and receive a response of type EppDomainInfoResponse -/// let response = client.transact::<_, EppDomainInfoResponse>(&domain_info).await.unwrap(); +/// // send it to the registry and receive a response of type DomainInfoResponse +/// let response = client.transact_new(domain_info, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainInfo = EppObject>; - -impl EppDomainInfo { - /// Creates a new EppObject for domain info corresponding to the <epp> tag in EPP XML - pub fn new(name: &str, client_tr_id: &str) -> EppDomainInfo { - EppObject::build(Command::::new( - DomainInfoRequest { +impl DomainInfo { + pub fn new(name: &str) -> DomainInfo { + DomainInfo { + request: DomainInfoRequest { info: DomainInfoRequestData { xmlns: EPP_DOMAIN_XMLNS.to_string(), domain: Domain { @@ -72,15 +83,18 @@ impl EppDomainInfo { }, }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainInfo { + DomainInfo { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML domain info response -pub type EppDomainInfoResponse = - EppObject>; - // Request /// Type for data under the <name> element tag for the domain <info> tag diff --git a/epp-client/src/domain/renew.rs b/epp-client/src/domain/renew.rs index 333edb9..7973381 100644 --- a/epp-client/src/domain/renew.rs +++ b/epp-client/src/domain/renew.rs @@ -3,12 +3,26 @@ use epp_client_macros::*; use super::EPP_DOMAIN_XMLNS; -use crate::common::{ElementName, EppObject, Period, StringValue}; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::common::{ElementName, NoExtension, Period, StringValue}; +use crate::request::{EppExtension, EppRequest}; use chrono::NaiveDate; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainRenew { + request: DomainRenewRequest, + extension: Option, +} + +impl EppRequest for DomainRenew { + type Input = DomainRenewRequest; + type Output = DomainRenewResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for domain <renew> command /// /// ## Usage @@ -20,8 +34,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::renew::{EppDomainRenew, EppDomainRenewResponse}; +/// use epp_client::domain::renew::DomainRenew; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -49,31 +64,22 @@ use serde::{Deserialize, Serialize}; /// // Create a date object to set the current expiry date /// let exp_date = NaiveDate::from_ymd(2022, 7, 27); /// -/// // Create an EppDomainRenew instance -/// let domain_renew = EppDomainRenew::new("eppdev-100.com", exp_date, 1, generate_client_tr_id(&client).as_str()); +/// // Create an DomainRenew instance +/// let domain_renew = DomainRenew::::new("eppdev-100.com", exp_date, 1); /// -/// // send it to the registry and receive a response of type EppDomainRenewResponse -/// let response = client.transact::<_, EppDomainRenewResponse>(&domain_renew).await.unwrap(); +/// // send it to the registry and receive a response of type DomainRenewResponse +/// let response = client.transact_new(domain_renew, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainRenew = EppObject>; - -impl EppDomainRenew { - /// Creates a new EppObject for domain renew corresponding to the <epp> tag in EPP XML - pub fn new( - name: &str, - current_expiry_date: NaiveDate, - years: u16, - client_tr_id: &str, - ) -> EppDomainRenew { +impl DomainRenew { + pub fn new(name: &str, current_expiry_date: NaiveDate, years: u16) -> DomainRenew { let exp_date_str = current_expiry_date.format("%Y-%m-%d").to_string().into(); - - EppObject::build(Command::::new( - DomainRenewRequest { + DomainRenew { + request: DomainRenewRequest { domain: DomainRenewRequestData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.into(), @@ -81,18 +87,18 @@ impl EppDomainRenew { period: Period::new(years), }, }, - client_tr_id, - )) + extension: None, + } } - pub fn set_period(&mut self, period: Period) { - self.data.command.domain.period = period; + pub fn with_extension(self, extension: F) -> DomainRenew { + DomainRenew { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML domain renew response -pub type EppDomainRenewResponse = EppObject>; - // Request /// Type for data under the domain <renew> tag diff --git a/epp-client/src/domain/transfer.rs b/epp-client/src/domain/transfer.rs index 51e87f7..b1f07fb 100644 --- a/epp-client/src/domain/transfer.rs +++ b/epp-client/src/domain/transfer.rs @@ -3,11 +3,86 @@ use epp_client_macros::*; use super::EPP_DOMAIN_XMLNS; -use crate::common::{DomainAuthInfo, ElementName, EppObject, Period, StringValue}; -use crate::request::Command; -use crate::response::{CommandResponse, EppCommandResponse}; +use crate::common::{DomainAuthInfo, ElementName, NoExtension, Period, StringValue}; +use crate::request::{EppExtension, EppRequest}; +use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainTransferRequest { + request: DomainTransferReq, + extension: Option, +} + +impl EppRequest for DomainTransferRequest { + type Input = DomainTransferReq; + type Output = DomainTransferResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + +#[derive(Debug)] +pub struct DomainTransferApprove { + request: DomainTransferReq, + extension: Option, +} + +impl EppRequest for DomainTransferApprove { + type Input = DomainTransferReq; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + +#[derive(Debug)] +pub struct DomainTransferReject { + request: DomainTransferReq, + extension: Option, +} + +impl EppRequest for DomainTransferReject { + type Input = DomainTransferReq; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + +#[derive(Debug)] +pub struct DomainTransferCancel { + request: DomainTransferReq, + extension: Option, +} + +impl EppRequest for DomainTransferCancel { + type Input = DomainTransferReq; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + +#[derive(Debug)] +pub struct DomainTransferQuery { + request: DomainTransferReq, + extension: Option, +} + +impl EppRequest for DomainTransferQuery { + type Input = DomainTransferReq; + type Output = DomainTransferResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for transfer request for domain /// /// ## Usage @@ -17,8 +92,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::transfer::{EppDomainTransferRequest, EppDomainTransferRequestResponse}; +/// use epp_client::domain::transfer::DomainTransferRequest; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,20 +119,42 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainTransferRequest instance -/// let domain_transfer_request = EppDomainTransferRequest::request( -/// "eppdev-100.net", 1, "epP4uthd#v", generate_client_tr_id(&client).as_str() +/// // Create an DomainTransferRequest instance +/// let domain_transfer_request = DomainTransferRequest::::new( +/// "eppdev-100.net", 1, "epP4uthd#v" /// ); /// -/// // send it to the registry and receive a response of type EppDomainTransferRequestResponse -/// let response = client.transact::<_, EppDomainTransferRequestResponse>(&domain_transfer_request).await.unwrap(); +/// // send it to the registry and receive a response of type DomainTransferRequestResponse +/// let response = client.transact_new(domain_transfer_request, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainTransferRequest = EppObject>; +impl DomainTransferRequest { + pub fn new(name: &str, years: u16, auth_password: &str) -> DomainTransferRequest { + DomainTransferRequest { + request: DomainTransferReq { + operation: "request".to_string(), + domain: DomainTransferReqData { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + name: name.into(), + period: Some(Period::new(years)), + auth_info: Some(DomainAuthInfo::new(auth_password)), + }, + }, + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainTransferRequest { + DomainTransferRequest { + request: self.request, + extension: Some(extension), + } + } +} /// Type that represents the <epp> request for transfer approval for domains /// @@ -67,8 +165,9 @@ pub type EppDomainTransferRequest = EppObject>; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::transfer::{EppDomainTransferApprove, EppDomainTransferApproveResponse}; +/// use epp_client::domain::transfer::DomainTransferApprove; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -93,20 +192,42 @@ pub type EppDomainTransferRequest = EppObject>; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainTransferApprove instance -/// let domain_transfer_approve = EppDomainTransferApprove::approve( -/// "eppdev-100.net", generate_client_tr_id(&client).as_str() +/// // Create an DomainTransferApprove instance +/// let domain_transfer_approve = DomainTransferApprove::::new( +/// "eppdev-100.net" /// ); /// -/// // send it to the registry and receive a response of type EppDomainTransferApproveResponse -/// let response = client.transact::<_, EppDomainTransferApproveResponse>(&domain_transfer_approve).await.unwrap(); +/// // send it to the registry and receive a response of type DomainTransferApproveResponse +/// let response = client.transact_new(domain_transfer_approve, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainTransferApprove = EppObject>; +impl DomainTransferApprove { + pub fn new(name: &str) -> DomainTransferApprove { + DomainTransferApprove { + request: DomainTransferReq { + operation: "approve".to_string(), + domain: DomainTransferReqData { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + name: name.into(), + period: None, + auth_info: None, + }, + }, + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainTransferApprove { + DomainTransferApprove { + request: self.request, + extension: Some(extension), + } + } +} /// Type that represents the <epp> request for transfer rejection for domains /// @@ -117,8 +238,9 @@ pub type EppDomainTransferApprove = EppObject>; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::transfer::{EppDomainTransferReject, EppDomainTransferRejectResponse}; +/// use epp_client::domain::transfer::DomainTransferReject; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -143,20 +265,42 @@ pub type EppDomainTransferApprove = EppObject>; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainTransferReject instance -/// let domain_transfer_reject = EppDomainTransferReject::reject( -/// "eppdev-100.net", generate_client_tr_id(&client).as_str() +/// // Create an DomainTransferReject instance +/// let domain_transfer_reject = DomainTransferReject::::new( +/// "eppdev-100.net" /// ); /// -/// // send it to the registry and receive a response of type EppDomainTransferRejectResponse -/// let response = client.transact::<_, EppDomainTransferRejectResponse>(&domain_transfer_reject).await.unwrap(); +/// // send it to the registry and receive a response of type DomainTransferRejectResponse +/// let response = client.transact_new(domain_transfer_reject, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainTransferReject = EppObject>; +impl DomainTransferReject { + pub fn new(name: &str) -> DomainTransferReject { + DomainTransferReject { + request: DomainTransferReq { + operation: "reject".to_string(), + domain: DomainTransferReqData { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + name: name.into(), + period: None, + auth_info: None, + }, + }, + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainTransferReject { + DomainTransferReject { + request: self.request, + extension: Some(extension), + } + } +} /// Type that represents the <epp> request for transfer request cancellation for domains /// @@ -167,8 +311,9 @@ pub type EppDomainTransferReject = EppObject>; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::transfer::{EppDomainTransferCancel, EppDomainTransferCancelResponse}; +/// use epp_client::domain::transfer::DomainTransferCancel; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -193,20 +338,42 @@ pub type EppDomainTransferReject = EppObject>; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainTransferCancel instance -/// let domain_transfer_cancel = EppDomainTransferCancel::cancel( -/// "eppdev-100.net", generate_client_tr_id(&client).as_str() +/// // Create an DomainTransferCancel instance +/// let domain_transfer_cancel = DomainTransferCancel::::new( +/// "eppdev-100.net" /// ); /// -/// // send it to the registry and receive a response of type EppDomainTransferCancelResponse -/// let response = client.transact::<_, EppDomainTransferCancelResponse>(&domain_transfer_cancel).await.unwrap(); +/// // send it to the registry and receive a response of type DomainTransferCancelResponse +/// let response = client.transact_new(domain_transfer_cancel, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainTransferCancel = EppObject>; +impl DomainTransferCancel { + pub fn new(name: &str) -> DomainTransferCancel { + DomainTransferCancel { + request: DomainTransferReq { + operation: "cancel".to_string(), + domain: DomainTransferReqData { + xmlns: EPP_DOMAIN_XMLNS.to_string(), + name: name.into(), + period: None, + auth_info: None, + }, + }, + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainTransferCancel { + DomainTransferCancel { + request: self.request, + extension: Some(extension), + } + } +} /// Type that represents the <epp> request for transfer request query for domains /// @@ -217,8 +384,9 @@ pub type EppDomainTransferCancel = EppObject>; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::domain::transfer::{EppDomainTransferQuery, EppDomainTransferQueryResponse}; +/// use epp_client::domain::transfer::DomainTransferQuery; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -243,137 +411,48 @@ pub type EppDomainTransferCancel = EppObject>; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainTransferQuery instance -/// let domain_transfer_query = EppDomainTransferQuery::query( -/// "eppdev-100.net", "epP4uthd#v", generate_client_tr_id(&client).as_str() +/// // Create an DomainTransferQuery instance +/// let domain_transfer_query = DomainTransferQuery::::new( +/// "eppdev-100.net", "epP4uthd#v" /// ); /// -/// // send it to the registry and receive a response of type EppDomainTransferQueryResponse -/// let response = client.transact::<_, EppDomainTransferQueryResponse>(&domain_transfer_query).await.unwrap(); +/// // send it to the registry and receive a response of type DomainTransferQueryResponse +/// let response = client.transact_new(domain_transfer_query, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainTransferQuery = EppObject>; - -impl EppDomainTransferRequest { - /// Creates a new EppObject for domain transfer request corresponding to the <epp> tag in EPP XML - pub fn request( - name: &str, - years: u16, - auth_password: &str, - client_tr_id: &str, - ) -> EppDomainTransferRequest { - EppObject::build(Command::::new( - DomainTransferRequest { - operation: "request".to_string(), - domain: DomainTransferRequestData { - xmlns: EPP_DOMAIN_XMLNS.to_string(), - name: name.into(), - period: Some(Period::new(years)), - auth_info: Some(DomainAuthInfo::new(auth_password)), - }, - }, - client_tr_id, - )) - } - - /// Sets the period for renewal in case of a successful transfer - pub fn set_period(&mut self, period: Period) { - self.data.command.domain.period = Some(period); - } -} - -impl EppDomainTransferApprove { - /// Creates a new EppObject for domain transfer approval corresponding to the <epp> tag in EPP XML - pub fn approve(name: &str, client_tr_id: &str) -> EppDomainTransferApprove { - EppObject::build(Command::::new( - DomainTransferRequest { - operation: "approve".to_string(), - domain: DomainTransferRequestData { - xmlns: EPP_DOMAIN_XMLNS.to_string(), - name: name.into(), - period: None, - auth_info: None, - }, - }, - client_tr_id, - )) - } -} - -impl EppDomainTransferCancel { - /// Creates a new EppObject for domain transfer request cancellation corresponding to the <epp> tag in EPP XML - pub fn cancel(name: &str, client_tr_id: &str) -> EppDomainTransferCancel { - EppObject::build(Command::::new( - DomainTransferRequest { - operation: "cancel".to_string(), - domain: DomainTransferRequestData { - xmlns: EPP_DOMAIN_XMLNS.to_string(), - name: name.into(), - period: None, - auth_info: None, - }, - }, - client_tr_id, - )) - } -} - -impl EppDomainTransferReject { - /// Creates a new EppObject for domain transfer rejection corresponding to the <epp> tag in EPP XML - pub fn reject(name: &str, client_tr_id: &str) -> EppDomainTransferReject { - EppObject::build(Command::::new( - DomainTransferRequest { - operation: "reject".to_string(), - domain: DomainTransferRequestData { - xmlns: EPP_DOMAIN_XMLNS.to_string(), - name: name.into(), - period: None, - auth_info: None, - }, - }, - client_tr_id, - )) - } -} - -impl EppDomainTransferQuery { - /// Creates a new EppObject for domain transfer request query corresponding to the <epp> tag in EPP XML - pub fn query(name: &str, auth_password: &str, client_tr_id: &str) -> EppDomainTransferQuery { - EppObject::build(Command::::new( - DomainTransferRequest { +impl DomainTransferQuery { + pub fn new(name: &str, auth_password: &str) -> DomainTransferQuery { + DomainTransferQuery { + request: DomainTransferReq { operation: "query".to_string(), - domain: DomainTransferRequestData { + domain: DomainTransferReqData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.into(), period: None, auth_info: Some(DomainAuthInfo::new(auth_password)), }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainTransferQuery { + DomainTransferQuery { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML domain transfer request response -pub type EppDomainTransferRequestResponse = EppObject>; -/// Type that represents the <epp> tag for the EPP XML domain transfer approval response -pub type EppDomainTransferApproveResponse = EppCommandResponse; -/// Type that represents the <epp> tag for the EPP XML domain transfer rejection response -pub type EppDomainTransferRejectResponse = EppCommandResponse; -/// Type that represents the <epp> tag for the EPP XML domain transfer cancellation response -pub type EppDomainTransferCancelResponse = EppCommandResponse; -/// Type that represents the <epp> tag for the EPP XML domain transfer query response -pub type EppDomainTransferQueryResponse = EppObject>; - // Request /// Type for elements under the domain <transfer> tag #[derive(Serialize, Deserialize, Debug)] -pub struct DomainTransferRequestData { +pub struct DomainTransferReqData { /// XML namespace for domain commands #[serde(rename = "xmlns:domain")] xmlns: String, @@ -393,14 +472,14 @@ pub struct DomainTransferRequestData { #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "transfer")] /// Type for EPP XML <transfer> command for domains -pub struct DomainTransferRequest { +pub struct DomainTransferReq { /// The transfer operation to perform indicated by the 'op' attr /// The values are one of transfer, approve, reject, cancel, or query #[serde(rename = "op")] operation: String, /// The data under the <transfer> tag in the transfer request #[serde(rename = "domain:transfer")] - domain: DomainTransferRequestData, + domain: DomainTransferReqData, } // Response diff --git a/epp-client/src/domain/update.rs b/epp-client/src/domain/update.rs index 1ecc70c..7974090 100644 --- a/epp-client/src/domain/update.rs +++ b/epp-client/src/domain/update.rs @@ -2,15 +2,34 @@ use epp_client_macros::*; -use crate::common::{ - DomainAuthInfo, DomainContact, DomainStatus, ElementName, EppObject, HostList, StringValue, +use crate::{ + common::{ + DomainAuthInfo, DomainContact, DomainStatus, ElementName, HostList, NoExtension, + StringValue, + }, + request::{EppExtension, EppRequest}, }; use super::EPP_DOMAIN_XMLNS; -use crate::request::Command; + use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct DomainUpdate { + request: DomainUpdateRequest, + extension: Option, +} + +impl EppRequest for DomainUpdate { + type Input = DomainUpdateRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for domain <update> command /// with <hostObj> elements in the request for <ns> list /// @@ -22,8 +41,9 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::common::{DomainStatus, DomainContact}; -/// use epp_client::domain::update::{EppDomainUpdate, EppDomainUpdateResponse, DomainAddRemove}; +/// use epp_client::domain::update::{DomainUpdate, DomainAddRemove}; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -48,8 +68,8 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppDomainUpdate instance -/// let mut domain_update = EppDomainUpdate::new("eppdev-100.com", generate_client_tr_id(&client).as_str()); +/// // Create an DomainUpdate instance +/// let mut domain_update = DomainUpdate::::new("eppdev-100.com"); /// /// let add = DomainAddRemove { /// ns: None, @@ -76,21 +96,17 @@ use serde::{Deserialize, Serialize}; /// domain_update.remove(remove); /// /// // send it to the registry and receive a response of type EppDomainUpdateResponse -/// let response = client.transact::<_, EppDomainUpdateResponse>(&domain_update).await.unwrap(); +/// let response = client.transact_new(domain_update, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppDomainUpdate = EppObject>; - -impl EppDomainUpdate { - /// Creates a new EppObject for domain update corresponding to the <epp> tag in EPP XML - /// with the <ns> tag containing <hostObj> tags - pub fn new(name: &str, client_tr_id: &str) -> EppDomainUpdate { - EppObject::build(Command::::new( - DomainUpdateRequest { +impl DomainUpdate { + pub fn new(name: &str) -> DomainUpdate { + DomainUpdate { + request: DomainUpdateRequest { domain: DomainUpdateRequestData { xmlns: EPP_DOMAIN_XMLNS.to_string(), name: name.into(), @@ -99,29 +115,33 @@ impl EppDomainUpdate { change_info: None, }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> DomainUpdate { + DomainUpdate { + request: self.request, + extension: Some(extension), + } } /// Sets the data for the <chg> tag pub fn info(&mut self, info: DomainChangeInfo) { - self.data.command.domain.change_info = Some(info); + self.request.domain.change_info = Some(info); } /// Sets the data for the <add> tag pub fn add(&mut self, add: DomainAddRemove) { - self.data.command.domain.add = Some(add); + self.request.domain.add = Some(add); } /// Sets the data for the <rem> tag pub fn remove(&mut self, remove: DomainAddRemove) { - self.data.command.domain.remove = Some(remove); + self.request.domain.remove = Some(remove); } } -/// Type that represents the <epp> tag for the EPP XML domain update response -pub type EppDomainUpdateResponse = EppCommandResponse; - /// Type for elements under the <chg> tag for domain update #[derive(Serialize, Deserialize, Debug)] pub struct DomainChangeInfo { diff --git a/epp-client/src/host/check.rs b/epp-client/src/host/check.rs index 732bcce..e729f66 100644 --- a/epp-client/src/host/check.rs +++ b/epp-client/src/host/check.rs @@ -1,13 +1,29 @@ //! Types for EPP host check request +use std::fmt::Debug; + use epp_client_macros::*; -use crate::common::{ElementName, EppObject, StringValue}; +use crate::common::{ElementName, NoExtension, StringValue}; use crate::host::EPP_HOST_XMLNS; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct HostCheck { + request: HostCheckRequest, + extension: Option, +} + +impl EppRequest for HostCheck { + type Input = HostCheckRequest; + type Output = HostCheckResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for host <check> command /// /// ## Usage @@ -17,8 +33,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::host::check::{EppHostCheck, EppHostCheckResponse}; +/// use epp_client::host::check::HostCheck; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,41 +60,42 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppHostCheck instance -/// let host_check = EppHostCheck::new( -/// &["ns1.eppdev-101.com", "ns2.eppdev-101.com"], -/// generate_client_tr_id(&client).as_str() +/// // Create an HostCheck instance +/// let host_check = HostCheck::::new( +/// &["ns1.eppdev-101.com", "ns2.eppdev-101.com"] /// ); /// -/// // send it to the registry and receive a response of type EppHostCheckResponse -/// let response = client.transact::<_, EppHostCheckResponse>(&host_check).await.unwrap(); +/// // send it to the registry and receive a response of type HostCheckResponse +/// let response = client.transact_new(host_check, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppHostCheck = EppObject>; - -impl EppHostCheck { - /// Creates a new EppObject for host check corresponding to the <epp> tag in EPP XML - pub fn new(hosts: &[&str], client_tr_id: &str) -> EppHostCheck { +impl HostCheck { + pub fn new(hosts: &[&str]) -> HostCheck { let hosts = hosts.iter().map(|&d| d.into()).collect(); - let host_check = HostCheckRequest { - list: HostList { - xmlns: EPP_HOST_XMLNS.to_string(), - hosts, + HostCheck { + request: HostCheckRequest { + list: HostList { + xmlns: EPP_HOST_XMLNS.to_string(), + hosts, + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new(host_check, client_tr_id)) + pub fn with_extension(self, extension: F) -> HostCheck { + HostCheck { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML host check response -pub type EppHostCheckResponse = EppObject>; - // Request /// Type for data under the host <check> tag @@ -104,7 +122,7 @@ pub struct HostCheckRequest { /// Type that represents the <name> tag for host check response #[derive(Serialize, Deserialize, Debug)] -pub struct HostCheck { +pub struct HostAvailable { /// The host name #[serde(rename = "$value")] pub name: StringValue, @@ -118,7 +136,7 @@ pub struct HostCheck { pub struct HostCheckDataItem { /// Data under the <name> tag #[serde(rename = "name")] - pub host: HostCheck, + pub host: HostAvailable, /// The reason for (un)availability pub reason: Option, } @@ -136,7 +154,7 @@ pub struct HostCheckData { /// Type that represents the <resData> tag for host check response #[derive(Serialize, Deserialize, Debug)] -pub struct HostCheckResult { +pub struct HostCheckResponse { /// Data under the <chkData> tag #[serde(rename = "chkData")] pub check_data: HostCheckData, diff --git a/epp-client/src/host/create.rs b/epp-client/src/host/create.rs index a282960..97898ca 100644 --- a/epp-client/src/host/create.rs +++ b/epp-client/src/host/create.rs @@ -2,12 +2,26 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject, HostAddr, StringValue}; +use crate::common::{ElementName, HostAddr, NoExtension, StringValue}; use crate::host::EPP_HOST_XMLNS; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct HostCreate { + request: HostCreateRequest, + extension: Option, +} + +impl EppRequest for HostCreate { + type Input = HostCreateRequest; + type Output = HostCreateResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for host <create> command /// /// ## Usage @@ -18,8 +32,9 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::common::HostAddr; -/// use epp_client::host::create::{EppHostCreate, EppHostCreateResponse}; +/// use epp_client::host::create::HostCreate; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -50,37 +65,39 @@ use serde::{Deserialize, Serialize}; /// HostAddr::new("v6", "2404:6800:4001:801::200e"), /// ]; /// -/// // Create an EppHostCreate instance -/// let host_create = EppHostCreate::new("ns1.eppdev-101.com", addresses, generate_client_tr_id(&client).as_str()); +/// // Create an HostCreate instance +/// let host_create = HostCreate::::new("ns1.eppdev-101.com", addresses); /// -/// // send it to the registry and receive a response of type EppHostCreateResponse -/// let response = client.transact::<_, EppHostCreateResponse>(&host_create).await.unwrap(); +/// // send it to the registry and receive a response of type HostCreateResponse +/// let response = client.transact_new(host_create, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppHostCreate = EppObject>; - -impl EppHostCreate { - /// Creates a new EppObject for host create corresponding to the <epp> tag in EPP XML - pub fn new(host: &str, addresses: Vec, client_tr_id: &str) -> EppHostCreate { - let host_create = HostCreateRequest { - host: HostCreateRequestData { - xmlns: EPP_HOST_XMLNS.to_string(), - name: host.into(), - addresses: Some(addresses), +impl HostCreate { + pub fn new(host: &str, addresses: Vec) -> HostCreate { + HostCreate { + request: HostCreateRequest { + host: HostCreateRequestData { + xmlns: EPP_HOST_XMLNS.to_string(), + name: host.into(), + addresses: Some(addresses), + }, }, - }; + extension: None, + } + } - EppObject::build(Command::::new(host_create, client_tr_id)) + pub fn with_extension(self, extension: F) -> HostCreate { + HostCreate { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML host create response -pub type EppHostCreateResponse = EppObject>; - // Request /// Type for data under the host <create> tag diff --git a/epp-client/src/host/delete.rs b/epp-client/src/host/delete.rs index bc20514..6d33edf 100644 --- a/epp-client/src/host/delete.rs +++ b/epp-client/src/host/delete.rs @@ -2,12 +2,27 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject, StringValue}; +use crate::common::{ElementName, NoExtension, StringValue}; use crate::host::EPP_HOST_XMLNS; -use crate::request::Command; +use crate::request::{EppExtension, EppRequest}; use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct HostDelete { + request: HostDeleteRequest, + extension: Option, +} + +impl EppRequest for HostDelete { + type Input = HostDeleteRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for host <delete> command /// /// ## Usage @@ -17,8 +32,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::host::delete::{EppHostDelete, EppHostDeleteResponse}; +/// use epp_client::host::delete::HostDelete; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,37 +59,38 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppHostDelete instance -/// let host_delete = EppHostDelete::new("ns2.eppdev-101.com", generate_client_tr_id(&client).as_str()); +/// // Create an HostDelete instance +/// let host_delete = HostDelete::::new("ns2.eppdev-101.com"); /// -/// // send it to the registry and receive a response of type EppHostDeleteResponse -/// let response = client.transact::<_, EppHostDeleteResponse>(&host_delete).await.unwrap(); +/// // send it to the registry and receive a response of type HostDeleteResponse +/// let response = client.transact_new(host_delete, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppHostDelete = EppObject>; - -impl EppHostDelete { - /// Creates a new EppObject for host delete corresponding to the <epp> tag in EPP XML - pub fn new(name: &str, client_tr_id: &str) -> EppHostDelete { - EppObject::build(Command::::new( - HostDeleteRequest { +impl HostDelete { + pub fn new(name: &str) -> HostDelete { + HostDelete { + request: HostDeleteRequest { host: HostDeleteRequestData { xmlns: EPP_HOST_XMLNS.to_string(), name: name.into(), }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> HostDelete { + HostDelete { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML host delete response -pub type EppHostDeleteResponse = EppCommandResponse; - /// Type for data under the host <delete> tag #[derive(Serialize, Deserialize, Debug)] pub struct HostDeleteRequestData { diff --git a/epp-client/src/host/info.rs b/epp-client/src/host/info.rs index dc34f1b..782a82c 100644 --- a/epp-client/src/host/info.rs +++ b/epp-client/src/host/info.rs @@ -2,12 +2,26 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject, HostAddr, HostStatus, StringValue}; +use crate::common::{ElementName, HostAddr, HostStatus, NoExtension, StringValue}; use crate::host::EPP_HOST_XMLNS; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct HostInfo { + request: HostInfoRequest, + extension: Option, +} + +impl EppRequest for HostInfo { + type Input = HostInfoRequest; + type Output = HostInfoResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for host <info> command /// /// ## Usage @@ -17,8 +31,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::host::info::{EppHostInfo, EppHostInfoResponse}; +/// use epp_client::host::info::HostInfo; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -43,37 +58,38 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppHostCreate instance -/// let host_info = EppHostInfo::new("ns2.eppdev-101.com", generate_client_tr_id(&client).as_str()); +/// // Create an HostInfo instance +/// let host_info = HostInfo::::new("ns2.eppdev-101.com"); /// -/// // send it to the registry and receive a response of type EppHostInfoResponse -/// let response = client.transact::<_, EppHostInfoResponse>(&host_info).await.unwrap(); +/// // send it to the registry and receive a response of type HostInfoResponse +/// let response = client.transact_new(host_info, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppHostInfo = EppObject>; - -impl EppHostInfo { - /// Creates a new EppObject for host info corresponding to the <epp> tag in EPP XML - pub fn new(name: &str, client_tr_id: &str) -> EppHostInfo { - EppObject::build(Command::::new( - HostInfoRequest { +impl HostInfo { + pub fn new(name: &str) -> HostInfo { + HostInfo { + request: HostInfoRequest { info: HostInfoRequestData { xmlns: EPP_HOST_XMLNS.to_string(), name: name.into(), }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> HostInfo { + HostInfo { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML host info response -pub type EppHostInfoResponse = EppObject>; - // Request /// Type for data under the host <info> tag diff --git a/epp-client/src/host/update.rs b/epp-client/src/host/update.rs index 9e1d042..3312eeb 100644 --- a/epp-client/src/host/update.rs +++ b/epp-client/src/host/update.rs @@ -2,12 +2,27 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject, HostAddr, HostStatus, StringValue}; +use crate::common::{ElementName, HostAddr, HostStatus, NoExtension, StringValue}; use crate::host::EPP_HOST_XMLNS; -use crate::request::Command; +use crate::request::{EppExtension, EppRequest}; use crate::response::EppCommandResponse; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct HostUpdate { + request: HostUpdateRequest, + extension: Option, +} + +impl EppRequest for HostUpdate { + type Input = HostUpdateRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for host <update> command /// /// ## Usage @@ -18,8 +33,9 @@ use serde::{Deserialize, Serialize}; /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; /// use epp_client::common::{HostAddr, HostStatus}; -/// use epp_client::host::update::{EppHostUpdate, EppHostUpdateResponse, HostAddRemove, HostChangeInfo}; +/// use epp_client::host::update::{HostUpdate, HostAddRemove, HostChangeInfo}; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -44,8 +60,8 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppHostUpdate instance -/// let mut host_update = EppHostUpdate::new("ns1.eppdev-101.com", generate_client_tr_id(&client).as_str()); +/// // Create an HostUpdate instance +/// let mut host_update = HostUpdate::::new("ns1.eppdev-101.com"); /// /// /// Prepare the add and remove sections for the update /// let add = HostAddRemove { @@ -68,21 +84,18 @@ use serde::{Deserialize, Serialize}; /// // Send a <chg> section as well /// host_update.info(HostChangeInfo { name: "ns2.eppdev-101.com".into() }); /// -/// // send it to the registry and receive a response of type EppHostUpdateResponse -/// let response = client.transact::<_, EppHostUpdateResponse>(&host_update).await.unwrap(); +/// // send it to the registry and receive a response of type HostUpdateResponse +/// let response = client.transact_new(host_update, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppHostUpdate = EppObject>; - -impl EppHostUpdate { - /// Creates a new EppObject for host update corresponding to the <epp> tag in EPP XML - pub fn new(name: &str, client_tr_id: &str) -> EppHostUpdate { - EppObject::build(Command::::new( - HostUpdateRequest { +impl HostUpdate { + pub fn new(name: &str) -> HostUpdate { + HostUpdate { + request: HostUpdateRequest { host: HostUpdateRequestData { xmlns: EPP_HOST_XMLNS.to_string(), name: name.into(), @@ -91,29 +104,33 @@ impl EppHostUpdate { change_info: None, }, }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> HostUpdate { + HostUpdate { + request: self.request, + extension: Some(extension), + } } /// Sets the data for the <chg> element of the host update pub fn info(&mut self, info: HostChangeInfo) { - self.data.command.host.change_info = Some(info); + self.request.host.change_info = Some(info); } /// Sets the data for the <add> element of the host update pub fn add(&mut self, add: HostAddRemove) { - self.data.command.host.add = Some(add); + self.request.host.add = Some(add); } /// Sets the data for the <rem> element of the host update pub fn remove(&mut self, remove: HostAddRemove) { - self.data.command.host.remove = Some(remove); + self.request.host.remove = Some(remove); } } -/// Type that represents the <epp> tag for the EPP XML host update response -pub type EppHostUpdateResponse = EppCommandResponse; - /// Type for data under the <chg> tag #[derive(Serialize, Deserialize, Debug)] pub struct HostChangeInfo { diff --git a/epp-client/src/lib.rs b/epp-client/src/lib.rs index 66d0def..72765c2 100644 --- a/epp-client/src/lib.rs +++ b/epp-client/src/lib.rs @@ -43,8 +43,9 @@ //! //! use epp_client::config::{EppClientConfig, EppClientConnection}; //! use epp_client::EppClient; -//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse}; +//! use epp_client::domain::check::DomainCheck; //! use epp_client::generate_client_tr_id; +//! use epp_client::common::NoExtension; //! //! #[tokio::main] //! async fn main() { @@ -72,15 +73,14 @@ //! //! // Make a domain check call, which returns an object of type EppDomainCheckResponse //! // that contains the result of the call -//! let domain_check = EppDomainCheck::new( +//! let domain_check = DomainCheck::::new( //! vec!["eppdev.com", "eppdev.net"], -//! generate_client_tr_id(&client).as_str() //! ); //! -//! let response = client.transact::<_, EppDomainCheckResponse>(&domain_check).await.unwrap(); +//! let response = client.transact_new(domain_check, generate_client_tr_id(&client).as_str()).await.unwrap(); //! //! // print the availability results -//! response.data.res_data.unwrap().check_data.domain_list +//! response.res_data.unwrap().check_data.domain_list //! .iter() //! .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available)); //! diff --git a/epp-client/src/login.rs b/epp-client/src/login.rs index 9dbebdc..3984759 100644 --- a/epp-client/src/login.rs +++ b/epp-client/src/login.rs @@ -4,71 +4,82 @@ use epp_client_macros::ElementName; use serde::{Deserialize, Serialize}; use crate::{ - common::{ElementName, EppObject, Options, ServiceExtension, Services, StringValue}, + common::{ElementName, NoExtension, Options, ServiceExtension, Services, StringValue}, contact::EPP_CONTACT_XMLNS, domain::EPP_DOMAIN_XMLNS, host::EPP_HOST_XMLNS, - request::{Command, EPP_LANG, EPP_VERSION}, + request::{EppExtension, EppRequest, EPP_LANG, EPP_VERSION}, response::EppCommandResponse, }; -/// The EPP Login Request -pub type EppLogin = EppObject>; +#[derive(Debug)] +pub struct Login { + request: LoginRequest, + extension: Option, +} -impl EppLogin { - /// Creates a new EPP Login request +impl EppRequest for Login { + type Input = LoginRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + +impl Login { pub fn new( username: &str, password: &str, ext_uris: &Option>, - client_tr_id: &str, - ) -> EppLogin { + ) -> Login { let ext_uris = ext_uris .as_ref() .map(|uris| uris.iter().map(|u| u.as_str().into()).collect()); - let login = Login { - username: username.into(), - password: password.into(), - options: Options { - version: EPP_VERSION.into(), - lang: EPP_LANG.into(), + Login { + request: LoginRequest { + username: username.into(), + password: password.into(), + options: Options { + version: EPP_VERSION.into(), + lang: EPP_LANG.into(), + }, + services: Services { + obj_uris: vec![ + EPP_HOST_XMLNS.into(), + EPP_CONTACT_XMLNS.into(), + EPP_DOMAIN_XMLNS.into(), + ], + svc_ext: Some(ServiceExtension { ext_uris }), + }, }, - services: Services { - obj_uris: vec![ - EPP_HOST_XMLNS.into(), - EPP_CONTACT_XMLNS.into(), - EPP_DOMAIN_XMLNS.into(), - ], - svc_ext: Some(ServiceExtension { ext_uris }), - }, - }; - - EppObject::build(Command:: { - command: login, extension: None, - client_tr_id: client_tr_id.into(), - }) + } + } + + pub fn with_extension(self, extension: F) -> Login { + Login { + request: self.request, + extension: Some(extension), + } } /// Sets the tag data pub fn options(&mut self, options: Options) { - self.data.command.options = options; + self.request.options = options; } /// Sets the tag data pub fn services(&mut self, services: Services) { - self.data.command.services = services; + self.request.services = services; } } -/// An alias of `EppCommandResponse` received in response to a successful login request -pub type EppLoginResponse = EppCommandResponse; - #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[element_name(name = "login")] /// Type corresponding to the <login> tag in an EPP XML login request -pub struct Login { +pub struct LoginRequest { /// The username to use for the login #[serde(rename(serialize = "clID", deserialize = "clID"))] username: StringValue, diff --git a/epp-client/src/logout.rs b/epp-client/src/logout.rs index 51f56bb..b7d3f6f 100644 --- a/epp-client/src/logout.rs +++ b/epp-client/src/logout.rs @@ -4,29 +4,43 @@ use epp_client_macros::ElementName; use serde::{Deserialize, Serialize}; use crate::{ - common::{ElementName, EppObject}, - request::Command, + common::{ElementName, NoExtension}, + request::{EppExtension, EppRequest}, response::EppCommandResponse, }; -/// The EPP Logout request -pub type EppLogout = EppObject>; +#[derive(Debug)] +pub struct Logout { + request: LogoutRequest, + extension: Option, +} -impl EppLogout { - /// Creates a new EPP Logout request - pub fn new(client_tr_id: &str) -> EppLogout { - EppObject::build(Command:: { - command: Logout, - extension: None, - client_tr_id: client_tr_id.into(), - }) +impl EppRequest for Logout { + type Input = LogoutRequest; + type Output = EppCommandResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) } } -/// An alias of `EppCommandResponse` received in response to a successful logout request -pub type EppLogoutResponse = EppCommandResponse; +impl Logout { + pub fn new() -> Logout { + Logout { + request: LogoutRequest {}, + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> Logout { + Logout { + request: self.request, + extension: Some(extension), + } + } +} #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[element_name(name = "logout")] /// Type corresponding to the <logout> tag in an EPP XML logout request -pub struct Logout; +pub struct LogoutRequest; diff --git a/epp-client/src/message/ack.rs b/epp-client/src/message/ack.rs index a17640c..653cc53 100644 --- a/epp-client/src/message/ack.rs +++ b/epp-client/src/message/ack.rs @@ -2,11 +2,25 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject}; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::common::{ElementName, NoExtension}; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct MessageAck { + request: MessageAckRequest, + extension: Option, +} + +impl EppRequest for MessageAck { + type Input = MessageAckRequest; + type Output = String; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for registry command /// ## Usage /// @@ -15,8 +29,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::message::ack::{EppMessageAck, EppMessageAckResponse}; +/// use epp_client::message::ack::MessageAck; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -41,35 +56,36 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppMessageAck instance -/// let message_ack = EppMessageAck::new(12345, generate_client_tr_id(&client).as_str()); +/// // Create an MessageAck instance +/// let message_ack = MessageAck::::new(12345); /// -/// // send it to the registry and receive a response of type EppMessageAckResponse -/// let response = client.transact::<_, EppMessageAckResponse>(&message_ack).await.unwrap(); +/// // send it to the registry and receive a response of type MessageAckResponse +/// let response = client.transact_new(message_ack, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppMessageAck = EppObject>; - -impl EppMessageAck { - /// Creates a new EppObject for <poll> ack corresponding to the <epp> tag in EPP XML - pub fn new(message_id: u32, client_tr_id: &str) -> EppMessageAck { - EppObject::build(Command::::new( - MessageAckRequest { +impl MessageAck { + pub fn new(message_id: u32) -> MessageAck { + MessageAck { + request: MessageAckRequest { op: "ack".to_string(), message_id: message_id.to_string(), }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> MessageAck { + MessageAck { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML message ack response -pub type EppMessageAckResponse = EppObject>; - #[derive(Serialize, Deserialize, Debug, ElementName)] #[element_name(name = "poll")] /// Type for EPP XML <poll> command for message ack diff --git a/epp-client/src/message/poll.rs b/epp-client/src/message/poll.rs index 7736052..692f794 100644 --- a/epp-client/src/message/poll.rs +++ b/epp-client/src/message/poll.rs @@ -2,11 +2,25 @@ use epp_client_macros::*; -use crate::common::{ElementName, EppObject, StringValue}; -use crate::request::Command; -use crate::response::CommandResponse; +use crate::common::{ElementName, NoExtension, StringValue}; +use crate::request::{EppExtension, EppRequest}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub struct MessagePoll { + request: MessagePollRequest, + extension: Option, +} + +impl EppRequest for MessagePoll { + type Input = MessagePollRequest; + type Output = MessagePollResponse; + + fn into_parts(self) -> (Self::Input, Option) { + (self.request, self.extension) + } +} + /// Type that represents the <epp> request for registry command /// /// ## Usage @@ -16,8 +30,9 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::message::poll::{EppMessagePoll, EppMessagePollResponse}; +/// use epp_client::message::poll::MessagePoll; /// use epp_client::generate_client_tr_id; +/// use epp_client::common::NoExtension; /// /// #[tokio::main] /// async fn main() { @@ -42,34 +57,35 @@ use serde::{Deserialize, Serialize}; /// Err(e) => panic!("Failed to create EppClient: {}", e) /// }; /// -/// // Create an EppMessagePoll instance -/// let message_poll = EppMessagePoll::new(generate_client_tr_id(&client).as_str()); +/// // Create an MessagePoll instance +/// let message_poll = MessagePoll::::new(); /// -/// // send it to the registry and receive a response of type EppMessagePollResponse -/// let response = client.transact::<_, EppMessagePollResponse>(&message_poll).await.unwrap(); +/// // send it to the registry and receive a response of type MessagePollResponse +/// let response = client.transact_new(message_poll, generate_client_tr_id(&client).as_str()).await.unwrap(); /// /// println!("{:?}", response); /// /// client.logout().await.unwrap(); /// } /// ``` -pub type EppMessagePoll = EppObject>; - -impl EppMessagePoll { - /// Creates a new EppObject for <poll> req corresponding to the <epp> tag in EPP XML - pub fn new(client_tr_id: &str) -> EppMessagePoll { - EppObject::build(Command::::new( - MessagePollRequest { +impl MessagePoll { + pub fn new() -> MessagePoll { + MessagePoll { + request: MessagePollRequest { op: "req".to_string(), }, - client_tr_id, - )) + extension: None, + } + } + + pub fn with_extension(self, extension: F) -> MessagePoll { + MessagePoll { + request: self.request, + extension: Some(extension), + } } } -/// Type that represents the <epp> tag for the EPP XML message poll response -pub type EppMessagePollResponse = EppObject>; - // Request #[derive(Serialize, Deserialize, Debug, ElementName)] diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index deaa0bf..1269e6c 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -3,35 +3,37 @@ mod response { use super::super::get_xml; use super::super::CLTRID; - use crate::contact::check::EppContactCheckResponse; - use crate::contact::create::EppContactCreateResponse; - use crate::contact::delete::EppContactDeleteResponse; - use crate::contact::info::EppContactInfoResponse; - use crate::contact::update::EppContactUpdateResponse; - use crate::domain::check::EppDomainCheckResponse; - use crate::domain::create::EppDomainCreateResponse; - use crate::domain::delete::EppDomainDeleteResponse; - use crate::domain::info::EppDomainInfoResponse; - use crate::domain::renew::EppDomainRenewResponse; + use crate::common::NoExtension; + use crate::contact::check::ContactCheck; + use crate::contact::create::ContactCreate; + use crate::contact::delete::ContactDelete; + use crate::contact::info::ContactInfo; + use crate::contact::update::ContactUpdate; + use crate::domain::check::DomainCheck; + use crate::domain::create::DomainCreate; + use crate::domain::delete::DomainDelete; + use crate::domain::info::DomainInfo; + use crate::domain::renew::DomainRenew; use crate::domain::rgp::request::EppDomainRgpRestoreRequestResponse; - use crate::domain::transfer::EppDomainTransferApproveResponse; - use crate::domain::transfer::EppDomainTransferCancelResponse; - use crate::domain::transfer::EppDomainTransferQueryResponse; - use crate::domain::transfer::EppDomainTransferRejectResponse; - use crate::domain::transfer::EppDomainTransferRequestResponse; - use crate::domain::update::EppDomainUpdateResponse; + use crate::domain::transfer::DomainTransferApprove; + use crate::domain::transfer::DomainTransferCancel; + use crate::domain::transfer::DomainTransferQuery; + use crate::domain::transfer::DomainTransferReject; + use crate::domain::transfer::DomainTransferRequest; + use crate::domain::update::DomainUpdate; use crate::hello::EppGreeting; use crate::hello::ExpiryType; use crate::hello::Relative; - use crate::host::check::EppHostCheckResponse; - use crate::host::create::EppHostCreateResponse; - use crate::host::delete::EppHostDeleteResponse; - use crate::host::info::EppHostInfoResponse; - use crate::host::update::EppHostUpdateResponse; - use crate::login::EppLoginResponse; - use crate::logout::EppLogoutResponse; - use crate::message::ack::EppMessageAckResponse; - use crate::message::poll::EppMessagePollResponse; + use crate::host::check::HostCheck; + use crate::host::create::HostCreate; + use crate::host::delete::HostDelete; + use crate::host::info::HostInfo; + use crate::host::update::HostUpdate; + use crate::login::Login; + use crate::logout::Logout; + use crate::message::ack::MessageAck; + use crate::message::poll::MessagePoll; + use crate::request::EppRequest; use crate::response::EppCommandResponseError; use crate::xml::EppXml; @@ -87,37 +89,37 @@ mod response { #[test] fn login() { let xml = get_xml("response/login.xml").unwrap(); - let object = EppLoginResponse::deserialize(xml.as_str()).unwrap(); + let object = Login::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn logout() { let xml = get_xml("response/logout.xml").unwrap(); - let object = EppLogoutResponse::deserialize(xml.as_str()).unwrap(); + let object = Logout::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1500); + assert_eq!(object.result.code, 1500); assert_eq!( - object.data.result.message, + object.result.message, "Command completed successfully; ending session".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn contact_check() { let xml = get_xml("response/contact/check.xml").unwrap(); - let object = EppContactCheckResponse::deserialize(xml.as_str()).unwrap(); + let object = ContactCheck::::deserialize_response(xml.as_str()).unwrap(); - let results = object.data.res_data().unwrap(); + let results = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!( results.check_data.contact_list[0].contact.id, "eppdev-contact-1".into() @@ -128,52 +130,52 @@ mod response { "eppdev-contact-2".into() ); assert_eq!(results.check_data.contact_list[1].contact.available, 1); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn contact_create() { let xml = get_xml("response/contact/create.xml").unwrap(); - let object = EppContactCreateResponse::deserialize(xml.as_str()).unwrap(); + let object = ContactCreate::::deserialize_response(xml.as_str()).unwrap(); - let results = object.data.res_data().unwrap(); + let results = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(results.create_data.id, "eppdev-contact-4".into()); assert_eq!( results.create_data.created_at, "2021-07-25T16:05:32.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn contact_delete() { let xml = get_xml("response/contact/delete.xml").unwrap(); - let object = EppContactDeleteResponse::deserialize(xml.as_str()).unwrap(); + let object = ContactDelete::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn contact_info() { let xml = get_xml("response/contact/info.xml").unwrap(); - let object = EppContactInfoResponse::deserialize(xml.as_str()).unwrap(); + let object = ContactInfo::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); let fax = result.info_data.fax.as_ref().unwrap(); let voice_ext = result.info_data.voice.extension.as_ref().unwrap(); let fax_ext = fax.extension.as_ref().unwrap(); let auth_info = result.info_data.auth_info.as_ref().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.info_data.id, "eppdev-contact-3".into()); assert_eq!(result.info_data.roid, "UNDEF-ROID".into()); assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); @@ -218,30 +220,30 @@ mod response { "2021-07-23T13:09:09.0Z".into() ); assert_eq!((*auth_info).password, "eppdev-387323".into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn contact_update() { let xml = get_xml("response/contact/update.xml").unwrap(); - let object = EppContactUpdateResponse::deserialize(xml.as_str()).unwrap(); + let object = ContactUpdate::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_check() { let xml = get_xml("response/domain/check.xml").unwrap(); - let object = EppDomainCheckResponse::deserialize(xml.as_str()).unwrap(); + let object = DomainCheck::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!( result.check_data.domain_list[0].domain.name, "eppdev.com".into() @@ -252,19 +254,19 @@ mod response { "eppdev.net".into() ); assert_eq!(result.check_data.domain_list[1].domain.available, 0); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_create() { let xml = get_xml("response/domain/create.xml").unwrap(); - let object = EppDomainCreateResponse::deserialize(xml.as_str()).unwrap(); + let object = DomainCreate::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.create_data.name, "eppdev-2.com".into()); assert_eq!( result.create_data.created_at, @@ -274,34 +276,34 @@ mod response { result.create_data.expiring_at, "2022-07-25T18:11:34.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_delete() { let xml = get_xml("response/domain/delete.xml").unwrap(); - let object = EppDomainDeleteResponse::deserialize(xml.as_str()).unwrap(); + let object = DomainDelete::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_info() { let xml = get_xml("response/domain/info.xml").unwrap(); - let object = EppDomainInfoResponse::deserialize(xml.as_str()).unwrap(); + let object = DomainInfo::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); let auth_info = result.info_data.auth_info.as_ref().unwrap(); let ns_list = result.info_data.ns.as_ref().unwrap(); let ns = (*ns_list).host_obj.as_ref().unwrap(); let hosts = result.info_data.hosts.as_ref().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.info_data.name, "eppdev-1.com".into()); assert_eq!(result.info_data.roid, "125899511_DOMAIN_COM-VRSN".into()); assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); @@ -348,38 +350,39 @@ mod response { "2023-07-23T15:31:20.0Z".into() ); assert_eq!((*auth_info).password, "epP4uthd#v".into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_renew() { let xml = get_xml("response/domain/renew.xml").unwrap(); - let object = EppDomainRenewResponse::deserialize(xml.as_str()).unwrap(); + let object = DomainRenew::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.renew_data.name, "eppdev-1.com".into()); assert_eq!( result.renew_data.expiring_at, "2024-07-23T15:31:20.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_transfer_request() { let xml = get_xml("response/domain/transfer_request.xml").unwrap(); - let object = EppDomainTransferRequestResponse::deserialize(xml.as_str()).unwrap(); + let object = + DomainTransferRequest::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1001); + assert_eq!(object.result.code, 1001); assert_eq!( - object.data.result.message, + object.result.message, "Command completed successfully; action pending".into() ); assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into()); @@ -395,52 +398,56 @@ mod response { result.transfer_data.expiring_at, "2022-07-02T14:53:19.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_transfer_approve() { let xml = get_xml("response/domain/transfer_approve.xml").unwrap(); - let object = EppDomainTransferApproveResponse::deserialize(xml.as_str()).unwrap(); + let object = + DomainTransferApprove::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_transfer_reject() { let xml = get_xml("response/domain/transfer_reject.xml").unwrap(); - let object = EppDomainTransferRejectResponse::deserialize(xml.as_str()).unwrap(); + let object = + DomainTransferReject::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_transfer_cancel() { let xml = get_xml("response/domain/transfer_cancel.xml").unwrap(); - let object = EppDomainTransferCancelResponse::deserialize(xml.as_str()).unwrap(); + let object = + DomainTransferCancel::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_transfer_query() { let xml = get_xml("response/domain/transfer_query.xml").unwrap(); - let object = EppDomainTransferQueryResponse::deserialize(xml.as_str()).unwrap(); + let object = + DomainTransferQuery::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.transfer_data.name, "eppdev-transfer.com".into()); assert_eq!(result.transfer_data.transfer_status, "pending".into()); assert_eq!(result.transfer_data.requester_id, "eppdev".into()); @@ -454,30 +461,30 @@ mod response { result.transfer_data.expiring_at, "2022-07-02T14:53:19.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn domain_update() { let xml = get_xml("response/domain/update.xml").unwrap(); - let object = EppDomainUpdateResponse::deserialize(xml.as_str()).unwrap(); + let object = DomainUpdate::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn host_check() { let xml = get_xml("response/host/check.xml").unwrap(); - let object = EppHostCheckResponse::deserialize(xml.as_str()).unwrap(); + let object = HostCheck::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!( result.check_data.host_list[0].host.name, "host1.eppdev-1.com".into() @@ -488,37 +495,37 @@ mod response { "ns1.testing.com".into() ); assert_eq!(result.check_data.host_list[1].host.available, 0); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn host_create() { let xml = get_xml("response/host/create.xml").unwrap(); - let object = EppHostCreateResponse::deserialize(xml.as_str()).unwrap(); + let object = HostCreate::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.create_data.name, "host2.eppdev-1.com".into()); assert_eq!( result.create_data.created_at, "2021-07-26T05:28:55.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn host_info() { let xml = get_xml("response/host/info.xml").unwrap(); - let object = EppHostInfoResponse::deserialize(xml.as_str()).unwrap(); + let object = HostInfo::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); + let result = object.res_data().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(result.info_data.name, "host2.eppdev-1.com".into()); assert_eq!(result.info_data.roid, "UNDEF-ROID".into()); assert_eq!(result.info_data.statuses[0].status, "ok".to_string()); @@ -549,43 +556,43 @@ mod response { *(result.info_data.updated_at.as_ref().unwrap()), "2021-07-26T05:28:55.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn host_update() { let xml = get_xml("response/host/update.xml").unwrap(); - let object = EppHostUpdateResponse::deserialize(xml.as_str()).unwrap(); + let object = HostUpdate::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn host_delete() { let xml = get_xml("response/host/delete.xml").unwrap(); - let object = EppHostDeleteResponse::deserialize(xml.as_str()).unwrap(); + let object = HostDelete::::deserialize_response(xml.as_str()).unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn message_poll() { let xml = get_xml("response/message/poll.xml").unwrap(); - let object = EppMessagePollResponse::deserialize(xml.as_str()).unwrap(); + let object = MessagePoll::::deserialize_response(xml.as_str()).unwrap(); - let result = object.data.res_data().unwrap(); - let msg = object.data.message_queue().unwrap(); + let result = object.res_data().unwrap(); + let msg = object.message_queue().unwrap(); - assert_eq!(object.data.result.code, 1301); + assert_eq!(object.result.code, 1301); assert_eq!( - object.data.result.message, + object.result.message, "Command completed successfully; ack to dequeue".into() ); assert_eq!(msg.count, 5); @@ -611,22 +618,22 @@ mod response { result.message_data.expiring_at, "2022-07-02T14:53:19.0Z".into() ); - assert_eq!(object.data.tr_ids.client_tr_id.unwrap(), CLTRID.into()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] fn message_ack() { let xml = get_xml("response/message/ack.xml").unwrap(); - let object = EppMessageAckResponse::deserialize(xml.as_str()).unwrap(); + let object = MessageAck::::deserialize_response(xml.as_str()).unwrap(); - let msg = object.data.message_queue().unwrap(); + let msg = object.message_queue().unwrap(); - assert_eq!(object.data.result.code, 1000); - assert_eq!(object.data.result.message, SUCCESS_MSG.into()); + assert_eq!(object.result.code, 1000); + assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!(msg.count, 4); assert_eq!(msg.id, "12345".to_string()); - assert_eq!(object.data.tr_ids.server_tr_id, SVTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } #[test] diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index cba71c4..909d85f 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -3,42 +3,47 @@ mod request { use super::super::get_xml; use super::super::CLTRID; + use crate::common::HostAttrList; + use crate::common::HostList; + use crate::common::HostObjList; + use crate::common::NoExtension; use crate::common::{ Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr, HostStatus, Phone, PostalInfo, }; - use crate::contact::check::EppContactCheck; - use crate::contact::create::EppContactCreate; - use crate::contact::delete::EppContactDelete; - use crate::contact::info::EppContactInfo; - use crate::contact::update::EppContactUpdate; - use crate::domain::check::EppDomainCheck; - use crate::domain::create::EppDomainCreate; - use crate::domain::delete::EppDomainDelete; - use crate::domain::info::EppDomainInfo; - use crate::domain::renew::EppDomainRenew; + use crate::contact::check::ContactCheck; + use crate::contact::create::ContactCreate; + use crate::contact::delete::ContactDelete; + use crate::contact::info::ContactInfo; + use crate::contact::update::ContactUpdate; + use crate::domain::check::DomainCheck; + use crate::domain::create::DomainCreate; + use crate::domain::delete::DomainDelete; + use crate::domain::info::DomainInfo; + use crate::domain::renew::DomainRenew; use crate::domain::rgp::report::EppDomainRgpRestoreReport; use crate::domain::rgp::request::EppDomainRgpRestoreRequest; - use crate::domain::transfer::EppDomainTransferApprove; - use crate::domain::transfer::EppDomainTransferCancel; - use crate::domain::transfer::EppDomainTransferQuery; - use crate::domain::transfer::EppDomainTransferReject; - use crate::domain::transfer::EppDomainTransferRequest; + use crate::domain::transfer::DomainTransferApprove; + use crate::domain::transfer::DomainTransferCancel; + use crate::domain::transfer::DomainTransferQuery; + use crate::domain::transfer::DomainTransferReject; + use crate::domain::transfer::DomainTransferRequest; use crate::domain::update::DomainAddRemove; use crate::domain::update::DomainChangeInfo; - use crate::domain::update::EppDomainUpdate; + use crate::domain::update::DomainUpdate; use crate::hello::EppHello; - use crate::host::check::EppHostCheck; - use crate::host::create::EppHostCreate; - use crate::host::delete::EppHostDelete; - use crate::host::info::EppHostInfo; - use crate::host::update::EppHostUpdate; + use crate::host::check::HostCheck; + use crate::host::create::HostCreate; + use crate::host::delete::HostDelete; + use crate::host::info::HostInfo; use crate::host::update::HostAddRemove; use crate::host::update::HostChangeInfo; - use crate::login::EppLogin; - use crate::logout::EppLogout; - use crate::message::ack::EppMessageAck; - use crate::message::poll::EppMessagePoll; + use crate::host::update::HostUpdate; + use crate::login::Login; + use crate::logout::Logout; + use crate::message::ack::MessageAck; + use crate::message::poll::MessagePoll; + use crate::request::EppRequest; use crate::xml::EppXml; use chrono::{DateTime, NaiveDate}; use std::str::FromStr; @@ -59,8 +64,8 @@ mod request { ]); let xml = get_xml("request/login.xml").unwrap(); - let object = EppLogin::new("username", "password", &ext_uris, CLTRID); - let serialized = object.serialize().unwrap(); + let object = Login::::new("username", "password", &ext_uris); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -68,8 +73,8 @@ mod request { #[test] fn logout() { let xml = get_xml("request/logout.xml").unwrap(); - let object = EppLogout::new(CLTRID); - let serialized = object.serialize().unwrap(); + let object = Logout::::new(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -77,8 +82,8 @@ mod request { #[test] fn contact_check() { let xml = get_xml("request/contact/check.xml").unwrap(); - let object = EppContactCheck::new(&["eppdev-contact-1", "eppdev-contact-2"], CLTRID); - let serialized = object.serialize().unwrap(); + let object = ContactCheck::::new(&["eppdev-contact-1", "eppdev-contact-2"]); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -95,17 +100,16 @@ mod request { let mut fax = Phone::new("+33.86698799"); fax.set_extension("677"); - let mut object = EppContactCreate::new( + let mut object = ContactCreate::::new( "eppdev-contact-3", "contact@eppdev.net", postal_info, voice, "eppdev-387323", - CLTRID, ); object.set_fax(fax); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -114,9 +118,9 @@ mod request { fn contact_info() { let xml = get_xml("request/contact/info.xml").unwrap(); - let object = EppContactInfo::new("eppdev-contact-3", "eppdev-387323", CLTRID); + let object = ContactInfo::::new("eppdev-contact-3", "eppdev-387323"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -125,7 +129,7 @@ mod request { fn contact_update() { let xml = get_xml("request/contact/update.xml").unwrap(); - let mut object = EppContactUpdate::new("eppdev-contact-3", CLTRID); + let mut object = ContactUpdate::::new("eppdev-contact-3"); let street = &["58", "Orchid Road"]; let address = Address::new(street, "Paris", "Paris", "392374", "FR"); @@ -142,7 +146,7 @@ mod request { }]; object.remove(remove_statuses); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -151,9 +155,9 @@ mod request { fn contact_delete() { let xml = get_xml("request/contact/delete.xml").unwrap(); - let object = EppContactDelete::new("eppdev-contact-3", CLTRID); + let object = ContactDelete::::new("eppdev-contact-3"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -162,9 +166,9 @@ mod request { fn domain_check() { let xml = get_xml("request/domain/check.xml").unwrap(); - let object = EppDomainCheck::new(vec!["eppdev.com", "eppdev.net"], CLTRID); + let object = DomainCheck::::new(vec!["eppdev.com", "eppdev.net"]); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -188,16 +192,16 @@ mod request { }, ]; - let object = EppDomainCreate::new( + let object = DomainCreate::::new( "eppdev-1.com", 1, - "eppdev-contact-3", + None, + Some("eppdev-contact-3"), "epP4uthd#v", - contacts, - CLTRID, + Some(contacts), ); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -221,17 +225,20 @@ mod request { }, ]; - let object = EppDomainCreate::new_with_ns( + let ns = Some(HostList::HostObjList(HostObjList { + hosts: vec!["ns1.test.com".into(), "ns2.test.com".into()], + })); + + let object = DomainCreate::::new( "eppdev-1.com", 1, - &["ns1.test.com", "ns2.test.com"], - "eppdev-contact-3", + ns, + Some("eppdev-contact-3"), "epP4uthd#v", - contacts, - CLTRID, + Some(contacts), ); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -255,31 +262,32 @@ mod request { }, ]; - let host_attr = vec![ - HostAttr { - name: "ns1.eppdev-1.com".into(), - addresses: None, - }, - HostAttr { - name: "ns2.eppdev-1.com".into(), - addresses: Some(vec![ - HostAddr::new_v4("177.232.12.58"), - HostAddr::new_v6("2404:6800:4001:801::200e"), - ]), - }, - ]; + let host_attr = HostList::HostAttrList(HostAttrList { + hosts: vec![ + HostAttr { + name: "ns1.eppdev-1.com".into(), + addresses: None, + }, + HostAttr { + name: "ns2.eppdev-1.com".into(), + addresses: Some(vec![ + HostAddr::new_v4("177.232.12.58"), + HostAddr::new_v6("2404:6800:4001:801::200e"), + ]), + }, + ], + }); - let object = EppDomainCreate::new_with_host_attr( + let object = DomainCreate::::new( "eppdev-2.com", 1, - host_attr, - "eppdev-contact-3", + Some(host_attr), + Some("eppdev-contact-3"), "epP4uthd#v", - contacts, - CLTRID, + Some(contacts), ); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -288,9 +296,9 @@ mod request { fn domain_info() { let xml = get_xml("request/domain/info.xml").unwrap(); - let object = EppDomainInfo::new("eppdev.com", CLTRID); + let object = DomainInfo::::new("eppdev.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -299,7 +307,7 @@ mod request { fn domain_update() { let xml = get_xml("request/domain/update.xml").unwrap(); - let mut object = EppDomainUpdate::new("eppdev.com", CLTRID); + let mut object = DomainUpdate::::new("eppdev.com"); let add = DomainAddRemove { ns: None, @@ -327,7 +335,7 @@ mod request { object.remove(remove); object.info(change_info); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -336,9 +344,9 @@ mod request { fn domain_delete() { let xml = get_xml("request/domain/delete.xml").unwrap(); - let object = EppDomainDelete::new("eppdev.com", CLTRID); + let object = DomainDelete::::new("eppdev.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -348,9 +356,9 @@ mod request { let xml = get_xml("request/domain/renew.xml").unwrap(); let exp_date = NaiveDate::from_ymd(2022, 7, 23); - let object = EppDomainRenew::new("eppdev.com", exp_date, 1, CLTRID); + let object = DomainRenew::::new("eppdev.com", exp_date, 1); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -359,9 +367,9 @@ mod request { fn domain_transfer_request() { let xml = get_xml("request/domain/transfer_request.xml").unwrap(); - let object = EppDomainTransferRequest::request("testing.com", 1, "epP4uthd#v", CLTRID); + let object = DomainTransferRequest::::new("testing.com", 1, "epP4uthd#v"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -370,9 +378,9 @@ mod request { fn domain_transfer_approve() { let xml = get_xml("request/domain/transfer_approve.xml").unwrap(); - let object = EppDomainTransferApprove::approve("testing.com", CLTRID); + let object = DomainTransferApprove::::new("testing.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -381,9 +389,9 @@ mod request { fn domain_transfer_reject() { let xml = get_xml("request/domain/transfer_reject.xml").unwrap(); - let object = EppDomainTransferReject::reject("testing.com", CLTRID); + let object = DomainTransferReject::::new("testing.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -392,9 +400,9 @@ mod request { fn domain_transfer_cancel() { let xml = get_xml("request/domain/transfer_cancel.xml").unwrap(); - let object = EppDomainTransferCancel::cancel("testing.com", CLTRID); + let object = DomainTransferCancel::::new("testing.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -403,9 +411,9 @@ mod request { fn domain_transfer_query() { let xml = get_xml("request/domain/transfer_query.xml").unwrap(); - let object = EppDomainTransferQuery::query("testing.com", "epP4uthd#v", CLTRID); + let object = DomainTransferQuery::::new("testing.com", "epP4uthd#v"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -414,9 +422,9 @@ mod request { fn host_check() { let xml = get_xml("request/host/check.xml").unwrap(); - let object = EppHostCheck::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"], CLTRID); + let object = HostCheck::::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"]); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -430,9 +438,9 @@ mod request { HostAddr::new("v6", "2404:6800:4001:801::200e"), ]; - let object = EppHostCreate::new("host1.eppdev-1.com", addresses, CLTRID); + let object = HostCreate::::new("host1.eppdev-1.com", addresses); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -441,9 +449,9 @@ mod request { fn host_info() { let xml = get_xml("request/host/info.xml").unwrap(); - let object = EppHostInfo::new("ns1.eppdev-1.com", CLTRID); + let object = HostInfo::::new("ns1.eppdev-1.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -466,7 +474,7 @@ mod request { }]), }; - let mut object = EppHostUpdate::new("host1.eppdev-1.com", CLTRID); + let mut object = HostUpdate::::new("host1.eppdev-1.com"); object.add(add); object.remove(remove); @@ -474,7 +482,7 @@ mod request { name: "host2.eppdev-1.com".into(), }); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -483,9 +491,9 @@ mod request { fn host_delete() { let xml = get_xml("request/host/delete.xml").unwrap(); - let object = EppHostDelete::new("ns1.eppdev-1.com", CLTRID); + let object = HostDelete::::new("ns1.eppdev-1.com"); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -494,9 +502,9 @@ mod request { fn message_poll() { let xml = get_xml("request/message/poll.xml").unwrap(); - let object = EppMessagePoll::new(CLTRID); + let object = MessagePoll::::new(); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); } @@ -505,9 +513,9 @@ mod request { fn message_ack() { let xml = get_xml("request/message/ack.xml").unwrap(); - let object = EppMessageAck::new(12345, CLTRID); + let object = MessageAck::::new(12345); - let serialized = object.serialize().unwrap(); + let serialized = object.serialize_request(CLTRID).unwrap(); assert_eq!(xml, serialized); }