Refactor contact check models

This commit is contained in:
Nicholas Rempel 2021-11-26 10:11:14 -08:00 committed by masalachai
parent dc90f91b8f
commit 964f3a7376
9 changed files with 74 additions and 72 deletions

View File

@ -0,0 +1 @@
pub mod check;

View File

@ -3,6 +3,7 @@ use epp_client_macros::*;
use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command; use crate::epp::request::Command;
use crate::epp::response::CommandResponse;
use crate::epp::xml::EPP_CONTACT_XMLNS; use crate::epp::xml::EPP_CONTACT_XMLNS;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize};
/// ///
/// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient; /// use epp_client::EppClient;
/// use epp_client::epp::{EppContactCheck, EppContactCheckResponse}; /// use epp_client::contact::check::{EppContactCheck, EppContactCheckResponse};
/// use epp_client::epp::generate_client_tr_id; /// use epp_client::epp::generate_client_tr_id;
/// ///
/// #[tokio::main] /// #[tokio::main]
@ -55,7 +56,34 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppContactCheck = EppObject<Command<ContactCheck>>; pub type EppContactCheck = EppObject<Command<ContactCheckRequest>>;
impl EppContactCheck {
/// Creates an EppObject corresponding to the &lt;epp&gt; tag with data for a contact check request
pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck {
let contact_ids = contact_ids
.iter()
.map(|&d| d.into())
.collect::<Vec<StringValue>>();
let contact_check = ContactCheckRequest {
list: ContactList {
xmlns: EPP_CONTACT_XMLNS.to_string(),
contact_ids,
},
};
EppObject::build(Command::<ContactCheckRequest>::new(
contact_check,
client_tr_id,
))
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML contact check response
pub type EppContactCheckResponse = EppObject<CommandResponse<ContactCheckResponse>>;
// Request
/// Type that represents the &lt;check&gt; command for contact transactions /// Type that represents the &lt;check&gt; command for contact transactions
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -71,27 +99,50 @@ pub struct ContactList {
#[derive(Serialize, Deserialize, Debug, ElementName)] #[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "check")] #[element_name(name = "check")]
/// The &lt;command&gt; type for contact check command /// The &lt;command&gt; type for contact check command
pub struct ContactCheck { pub struct ContactCheckRequest {
/// The &lt;check&gt; tag for the contact check command /// The &lt;check&gt; tag for the contact check command
#[serde(rename = "contact:check", alias = "check")] #[serde(rename = "contact:check", alias = "check")]
list: ContactList, list: ContactList,
} }
impl EppContactCheck { // Response
/// Creates an EppObject corresponding to the &lt;epp&gt; tag with data for a contact check request
pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck {
let contact_ids = contact_ids
.iter()
.map(|&d| d.into())
.collect::<Vec<StringValue>>();
let contact_check = ContactCheck { /// Type that represents the &lt;id&gt; tag for contact check response
list: ContactList { #[derive(Serialize, Deserialize, Debug)]
xmlns: EPP_CONTACT_XMLNS.to_string(), pub struct ContactCheck {
contact_ids, /// The text of the &lt;id&gt; tag
}, #[serde(rename = "$value")]
}; pub id: StringValue,
/// The avail attr on the &lt;id&gt; tag
EppObject::build(Command::<ContactCheck>::new(contact_check, client_tr_id)) #[serde(rename = "avail")]
} pub available: u16,
}
/// Type that represents the &lt;cd&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckResponseDataItem {
/// Data under the &lt;id&gt; tag
#[serde(rename = "id")]
pub contact: ContactCheck,
/// The reason for (un)availability
pub reason: Option<StringValue>,
}
/// Type that represents the &lt;chkData&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckResponseData {
/// XML namespace for contact response data
#[serde(rename = "xmlns:contact")]
xmlns: String,
/// Data under the &lt;cd&gt; tag
#[serde(rename = "cd")]
pub contact_list: Vec<ContactCheckResponseDataItem>,
}
/// Type that represents the &lt;resData&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckResponse {
/// Data under the &lt;chkData&gt; tag
#[serde(rename = "chkData")]
pub check_data: ContactCheckResponseData,
} }

View File

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

View File

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

View File

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

View File

@ -1,49 +0,0 @@
//! Types for EPP contact check response
use serde::{Deserialize, Serialize};
use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::CommandResponse;
/// Type that represents the &lt;epp&gt; tag for the EPP XML contact check response
pub type EppContactCheckResponse = EppObject<CommandResponse<ContactCheckResult>>;
/// Type that represents the &lt;id&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheck {
/// The text of the &lt;id&gt; tag
#[serde(rename = "$value")]
pub id: StringValue,
/// The avail attr on the &lt;id&gt; tag
#[serde(rename = "avail")]
pub available: u16,
}
/// Type that represents the &lt;cd&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckDataItem {
/// Data under the &lt;id&gt; tag
#[serde(rename = "id")]
pub contact: ContactCheck,
/// The reason for (un)availability
pub reason: Option<StringValue>,
}
/// Type that represents the &lt;chkData&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckData {
/// XML namespace for contact response data
#[serde(rename = "xmlns:contact")]
xmlns: String,
/// Data under the &lt;cd&gt; tag
#[serde(rename = "cd")]
pub contact_list: Vec<ContactCheckDataItem>,
}
/// Type that represents the &lt;resData&gt; tag for contact check response
#[derive(Serialize, Deserialize, Debug)]
pub struct ContactCheckResult {
/// Data under the &lt;chkData&gt; tag
#[serde(rename = "chkData")]
pub check_data: ContactCheckData,
}

View File

@ -102,6 +102,7 @@ extern crate log;
pub mod config; pub mod config;
pub mod connection; pub mod connection;
pub mod contact;
pub mod domain; pub mod domain;
pub mod epp; pub mod epp;
pub mod error; pub mod error;

View File

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

View File

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