Refactor host check models
This commit is contained in:
parent
18097c14f0
commit
fa032804a6
|
@ -5,7 +5,6 @@ pub mod request;
|
|||
pub mod response;
|
||||
pub mod xml;
|
||||
|
||||
pub use request::host::check::*;
|
||||
pub use request::host::create::*;
|
||||
pub use request::host::delete::*;
|
||||
pub use request::host::info::*;
|
||||
|
@ -13,7 +12,6 @@ pub use request::host::update::*;
|
|||
pub use request::message::ack::*;
|
||||
pub use request::message::poll::*;
|
||||
|
||||
pub use response::host::check::*;
|
||||
pub use response::host::create::*;
|
||||
pub use response::host::delete::*;
|
||||
pub use response::host::info::*;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Types for EPP host requests
|
||||
|
||||
pub mod check;
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod info;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Types for EPP host responses
|
||||
|
||||
pub mod check;
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod info;
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//! Types for EPP host check response
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::epp::object::{EppObject, StringValue};
|
||||
use crate::epp::response::CommandResponse;
|
||||
|
||||
/// Type that represents the <epp> tag for the EPP XML host check response
|
||||
pub type EppHostCheckResponse = EppObject<CommandResponse<HostCheckResult>>;
|
||||
|
||||
/// Type that represents the <name> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheck {
|
||||
/// The host name
|
||||
#[serde(rename = "$value")]
|
||||
pub name: StringValue,
|
||||
/// The host (un)availability
|
||||
#[serde(rename = "avail")]
|
||||
pub available: u16,
|
||||
}
|
||||
|
||||
/// Type that represents the <cd> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheckDataItem {
|
||||
/// Data under the <name> tag
|
||||
#[serde(rename = "name")]
|
||||
pub host: HostCheck,
|
||||
/// The reason for (un)availability
|
||||
pub reason: Option<StringValue>,
|
||||
}
|
||||
|
||||
/// Type that represents the <chkData> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheckData {
|
||||
/// XML namespace for host response data
|
||||
#[serde(rename = "xmlns:host")]
|
||||
xmlns: String,
|
||||
/// Data under the <cd> tag
|
||||
#[serde(rename = "cd")]
|
||||
pub host_list: Vec<HostCheckDataItem>,
|
||||
}
|
||||
|
||||
/// Type that represents the <resData> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheckResult {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "chkData")]
|
||||
pub check_data: HostCheckData,
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub mod check;
|
|
@ -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_HOST_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::{EppHostCheck, EppHostCheckResponse};
|
||||
/// use epp_client::host::check::{EppHostCheck, EppHostCheckResponse};
|
||||
/// use epp_client::epp::generate_client_tr_id;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
|
@ -56,7 +57,28 @@ use serde::{Deserialize, Serialize};
|
|||
/// client.logout().await.unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
pub type EppHostCheck = EppObject<Command<HostCheck>>;
|
||||
pub type EppHostCheck = EppObject<Command<HostCheckRequest>>;
|
||||
|
||||
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 {
|
||||
let hosts = hosts.iter().map(|&d| d.into()).collect();
|
||||
|
||||
let host_check = HostCheckRequest {
|
||||
list: HostList {
|
||||
xmlns: EPP_HOST_XMLNS.to_string(),
|
||||
hosts,
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<HostCheckRequest>::new(host_check, client_tr_id))
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that represents the <epp> tag for the EPP XML host check response
|
||||
pub type EppHostCheckResponse = EppObject<CommandResponse<HostCheckResult>>;
|
||||
|
||||
// Request
|
||||
|
||||
/// Type for data under the host <check> tag
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -72,24 +94,50 @@ pub struct HostList {
|
|||
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
||||
#[element_name(name = "check")]
|
||||
/// Type for EPP XML <check> command for hosts
|
||||
pub struct HostCheck {
|
||||
pub struct HostCheckRequest {
|
||||
/// The instance holding the list of hosts to be checked
|
||||
#[serde(rename = "host:check", alias = "check")]
|
||||
list: HostList,
|
||||
}
|
||||
|
||||
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 {
|
||||
let hosts = hosts.iter().map(|&d| d.into()).collect();
|
||||
// Response
|
||||
|
||||
let host_check = HostCheck {
|
||||
list: HostList {
|
||||
xmlns: EPP_HOST_XMLNS.to_string(),
|
||||
hosts,
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<HostCheck>::new(host_check, client_tr_id))
|
||||
}
|
||||
/// Type that represents the <name> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheck {
|
||||
/// The host name
|
||||
#[serde(rename = "$value")]
|
||||
pub name: StringValue,
|
||||
/// The host (un)availability
|
||||
#[serde(rename = "avail")]
|
||||
pub available: u16,
|
||||
}
|
||||
|
||||
/// Type that represents the <cd> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheckDataItem {
|
||||
/// Data under the <name> tag
|
||||
#[serde(rename = "name")]
|
||||
pub host: HostCheck,
|
||||
/// The reason for (un)availability
|
||||
pub reason: Option<StringValue>,
|
||||
}
|
||||
|
||||
/// Type that represents the <chkData> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheckData {
|
||||
/// XML namespace for host response data
|
||||
#[serde(rename = "xmlns:host")]
|
||||
xmlns: String,
|
||||
/// Data under the <cd> tag
|
||||
#[serde(rename = "cd")]
|
||||
pub host_list: Vec<HostCheckDataItem>,
|
||||
}
|
||||
|
||||
/// Type that represents the <resData> tag for host check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct HostCheckResult {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "chkData")]
|
||||
pub check_data: HostCheckData,
|
||||
}
|
|
@ -106,6 +106,7 @@ pub mod contact;
|
|||
pub mod domain;
|
||||
pub mod epp;
|
||||
pub mod error;
|
||||
pub mod host;
|
||||
pub use connection::client::EppClient;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -27,6 +27,7 @@ mod response {
|
|||
};
|
||||
use crate::epp::xml::EppXml;
|
||||
use crate::epp::*;
|
||||
use crate::host::check::EppHostCheckResponse;
|
||||
|
||||
const SVTRID: &str = "RO-6879-1627224678242975";
|
||||
const SUCCESS_MSG: &str = "Command completed successfully";
|
||||
|
|
|
@ -30,6 +30,7 @@ mod request {
|
|||
use crate::epp::request::{EppHello, EppLogin, EppLogout};
|
||||
use crate::epp::xml::EppXml;
|
||||
use crate::epp::*;
|
||||
use crate::host::check::EppHostCheck;
|
||||
use chrono::{DateTime, NaiveDate};
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
Loading…
Reference in New Issue