Refactor domain check models

This commit is contained in:
Nick Rempel 2021-11-24 21:36:05 -08:00 committed by masalachai
parent 458f39a6ed
commit c082a5e3bf
10 changed files with 73 additions and 71 deletions

View File

@ -7,7 +7,7 @@
//!
//! use epp_client::config::{EppClientConfig, EppClientConnection};
//! use epp_client::EppClient;
//! use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse};
//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse};
//! use epp_client::epp::generate_client_tr_id;
//!
//! #[tokio::main]

1
epp-client/src/domain.rs Normal file
View File

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

View File

@ -4,6 +4,7 @@ use epp_client_macros::*;
use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command;
use crate::epp::response::CommandResponse;
use crate::epp::xml::EPP_DOMAIN_XMLNS;
use serde::{Deserialize, Serialize};
@ -16,7 +17,7 @@ use serde::{Deserialize, Serialize};
///
/// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse};
/// use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
@ -56,7 +57,31 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppDomainCheck = EppObject<Command<DomainCheck>>;
pub type EppDomainCheck = EppObject<Command<DomainCheckRequest>>;
impl EppDomainCheck {
/// Creates a new EppObject for domain check corresponding to the &lt;epp&gt; 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,
},
};
EppObject::build(Command::<DomainCheckRequest>::new(
domain_check,
client_tr_id,
))
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain check response
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResponse>>;
// Request
/// Type for &lt;name&gt; elements under the domain &lt;check&gt; tag
#[derive(Serialize, Deserialize, Debug)]
@ -72,24 +97,50 @@ pub struct DomainList {
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "check")]
/// Type for EPP XML &lt;check&gt; command for domains
pub struct DomainCheck {
pub struct DomainCheckRequest {
/// The object holding the list of domains to be checked
#[serde(rename = "domain:check", alias = "check")]
list: DomainList,
}
impl EppDomainCheck {
/// Creates a new EppObject for domain check corresponding to the &lt;epp&gt; 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();
// Response
let domain_check = DomainCheck {
list: DomainList {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
domains,
},
};
/// Type that represents the &lt;name&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainAvailable {
/// The domain name
#[serde(rename = "$value")]
pub name: StringValue,
/// The domain (un)availability
#[serde(rename = "avail")]
pub available: u16,
}
EppObject::build(Command::<DomainCheck>::new(domain_check, client_tr_id))
/// Type that represents the &lt;cd&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckResponseDataItem {
/// Data under the &lt;name&gt; tag
#[serde(rename = "name")]
pub domain: DomainAvailable,
/// The reason for (un)availability
pub reason: Option<StringValue>,
}
/// Type that represents the &lt;chkData&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckResponseData {
/// XML namespace for domain response data
#[serde(rename = "xmlns:domain")]
xmlns: String,
/// Data under the &lt;cd&gt; tag
#[serde(rename = "cd")]
pub domain_list: Vec<DomainCheckResponseDataItem>,
}
/// Type that represents the &lt;resData&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckResponse {
/// Data under the &lt;chkData&gt; tag
#[serde(rename = "chkData")]
pub check_data: DomainCheckResponseData,
}

View File

@ -10,7 +10,6 @@ pub use request::contact::create::*;
pub use request::contact::delete::*;
pub use request::contact::info::*;
pub use request::contact::update::*;
pub use request::domain::check::*;
pub use request::domain::create::*;
pub use request::domain::delete::*;
pub use request::domain::info::*;
@ -32,7 +31,6 @@ pub use response::contact::create::*;
pub use response::contact::delete::*;
pub use response::contact::info::*;
pub use response::contact::update::*;
pub use response::domain::check::*;
pub use response::domain::create::*;
pub use response::domain::delete::*;
pub use response::domain::info::*;

View File

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

View File

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

View File

@ -1,49 +0,0 @@
//! Types for EPP domain 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 domain check response
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResult>>;
/// Type that represents the &lt;name&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheck {
/// The domain name
#[serde(rename = "$value")]
pub name: StringValue,
/// The domain (un)availability
#[serde(rename = "avail")]
pub available: u16,
}
/// Type that represents the &lt;cd&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckDataItem {
/// Data under the &lt;name&gt; tag
#[serde(rename = "name")]
pub domain: DomainCheck,
/// The reason for (un)availability
pub reason: Option<StringValue>,
}
/// Type that represents the &lt;chkData&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckData {
/// XML namespace for domain response data
#[serde(rename = "xmlns:domain")]
xmlns: String,
/// Data under the &lt;cd&gt; tag
#[serde(rename = "cd")]
pub domain_list: Vec<DomainCheckDataItem>,
}
/// Type that represents the &lt;resData&gt; tag for domain check response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainCheckResult {
/// Data under the &lt;chkData&gt; tag
#[serde(rename = "chkData")]
pub check_data: DomainCheckData,
}

View File

@ -43,7 +43,7 @@
//!
//! use epp_client::config::{EppClientConfig, EppClientConnection};
//! use epp_client::EppClient;
//! use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse};
//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse};
//! use epp_client::epp::generate_client_tr_id;
//!
//! #[tokio::main]
@ -102,6 +102,7 @@ extern crate log;
pub mod config;
pub mod connection;
pub mod domain;
pub mod epp;
pub mod error;
pub use connection::client::EppClient;

View File

@ -3,6 +3,7 @@
mod response {
use super::super::get_xml;
use super::super::CLTRID;
use crate::domain::check::EppDomainCheckResponse;
use crate::epp::response::ExpiryType;
use crate::epp::response::Relative;
use crate::epp::response::{

View File

@ -3,6 +3,7 @@
mod request {
use super::super::get_xml;
use super::super::CLTRID;
use crate::domain::check::EppDomainCheck;
use crate::epp::object::data::{
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
HostStatus, Phone, PostalInfo,