Share CheckResponse types for domain and host resources
This commit is contained in:
parent
999149ba31
commit
dd1c9c1e66
|
@ -50,6 +50,32 @@ pub struct Available {
|
||||||
pub available: bool,
|
pub available: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <cd> tag for domain check response
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct CheckResponseDataItem {
|
||||||
|
/// Data under the <name> tag
|
||||||
|
#[serde(rename = "name")]
|
||||||
|
pub resource: Available,
|
||||||
|
/// The reason for (un)availability
|
||||||
|
pub reason: Option<StringValue<'static>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <chkData> tag for host check response
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct CheckData {
|
||||||
|
/// Data under the <cd> tag
|
||||||
|
#[serde(rename = "cd")]
|
||||||
|
pub list: Vec<CheckResponseDataItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <resData> tag for host check response
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct CheckResponse {
|
||||||
|
/// Data under the <chkData> tag
|
||||||
|
#[serde(rename = "chkData")]
|
||||||
|
pub check_data: CheckData,
|
||||||
|
}
|
||||||
|
|
||||||
/// The <option> type in EPP XML login requests
|
/// The <option> type in EPP XML login requests
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
#[serde(rename = "options")]
|
#[serde(rename = "options")]
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
//! Types for EPP domain check request
|
//! Types for EPP domain check request
|
||||||
|
|
||||||
use super::XMLNS;
|
use super::XMLNS;
|
||||||
use crate::common::{NoExtension, StringValue, Available};
|
use crate::common::{CheckResponse, NoExtension, StringValue};
|
||||||
use crate::request::{Command, Transaction};
|
use crate::request::{Command, Transaction};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::Serialize;
|
||||||
|
|
||||||
impl<'a> Transaction<NoExtension> for DomainCheck<'a> {}
|
impl<'a> Transaction<NoExtension> for DomainCheck<'a> {}
|
||||||
|
|
||||||
impl<'a> Command for DomainCheck<'a> {
|
impl<'a> Command for DomainCheck<'a> {
|
||||||
type Response = DomainCheckResponse;
|
type Response = CheckResponse;
|
||||||
const COMMAND: &'static str = "check";
|
const COMMAND: &'static str = "check";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,34 +44,6 @@ pub struct DomainCheck<'a> {
|
||||||
list: DomainList<'a>,
|
list: DomainList<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response
|
|
||||||
|
|
||||||
/// Type that represents the <cd> tag for domain check response
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct DomainCheckResponseDataItem {
|
|
||||||
/// Data under the <name> tag
|
|
||||||
#[serde(rename = "name")]
|
|
||||||
pub domain: Available,
|
|
||||||
/// The reason for (un)availability
|
|
||||||
pub reason: Option<StringValue<'static>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <chkData> tag for domain check response
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct DomainCheckResponseData {
|
|
||||||
/// Data under the <cd> tag
|
|
||||||
#[serde(rename = "cd")]
|
|
||||||
pub domain_list: Vec<DomainCheckResponseDataItem>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <resData> tag for domain check response
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct DomainCheckResponse {
|
|
||||||
/// Data under the <chkData> tag
|
|
||||||
#[serde(rename = "chkData")]
|
|
||||||
pub check_data: DomainCheckResponseData,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::DomainCheck;
|
use super::DomainCheck;
|
||||||
|
@ -103,16 +75,10 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||||
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
||||||
assert_eq!(
|
assert_eq!(result.check_data.list[0].resource.name, "eppdev.com".into());
|
||||||
result.check_data.domain_list[0].domain.name,
|
assert!(result.check_data.list[0].resource.available);
|
||||||
"eppdev.com".into()
|
assert_eq!(result.check_data.list[1].resource.name, "eppdev.net".into());
|
||||||
);
|
assert!(!result.check_data.list[1].resource.available);
|
||||||
assert!(result.check_data.domain_list[0].domain.available);
|
|
||||||
assert_eq!(
|
|
||||||
result.check_data.domain_list[1].domain.name,
|
|
||||||
"eppdev.net".into()
|
|
||||||
);
|
|
||||||
assert!(!result.check_data.domain_list[1].domain.available);
|
|
||||||
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
|
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
|
||||||
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
|
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use super::XMLNS;
|
use super::XMLNS;
|
||||||
use crate::common::{NoExtension, StringValue, Available};
|
use crate::common::{CheckResponse, NoExtension, StringValue};
|
||||||
use crate::request::{Command, Transaction};
|
use crate::request::{Command, Transaction};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::Serialize;
|
||||||
|
|
||||||
impl<'a> Transaction<NoExtension> for HostCheck<'a> {}
|
impl<'a> Transaction<NoExtension> for HostCheck<'a> {}
|
||||||
|
|
||||||
impl<'a> Command for HostCheck<'a> {
|
impl<'a> Command for HostCheck<'a> {
|
||||||
type Response = HostCheckResponse;
|
type Response = CheckResponse;
|
||||||
const COMMAND: &'static str = "check";
|
const COMMAND: &'static str = "check";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,34 +48,6 @@ pub struct HostCheck<'a> {
|
||||||
list: HostList<'a>,
|
list: HostList<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response
|
|
||||||
|
|
||||||
/// Type that represents the <cd> tag for host check response
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct HostCheckDataItem {
|
|
||||||
/// Data under the <name> tag
|
|
||||||
#[serde(rename = "name")]
|
|
||||||
pub host: Available,
|
|
||||||
/// The reason for (un)availability
|
|
||||||
pub reason: Option<StringValue<'static>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <chkData> tag for host check response
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct HostCheckData {
|
|
||||||
/// Data under the <cd> tag
|
|
||||||
#[serde(rename = "cd")]
|
|
||||||
pub host_list: Vec<HostCheckDataItem>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <resData> tag for host check response
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct HostCheckResponse {
|
|
||||||
/// Data under the <chkData> tag
|
|
||||||
#[serde(rename = "chkData")]
|
|
||||||
pub check_data: HostCheckData,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::HostCheck;
|
use super::HostCheck;
|
||||||
|
@ -108,15 +80,15 @@ mod tests {
|
||||||
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||||
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.check_data.host_list[0].host.name,
|
result.check_data.list[0].resource.name,
|
||||||
"host1.eppdev-1.com".into()
|
"host1.eppdev-1.com".into()
|
||||||
);
|
);
|
||||||
assert!(result.check_data.host_list[0].host.available);
|
assert!(result.check_data.list[0].resource.available);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.check_data.host_list[1].host.name,
|
result.check_data.list[1].resource.name,
|
||||||
"ns1.testing.com".into()
|
"ns1.testing.com".into()
|
||||||
);
|
);
|
||||||
assert!(!result.check_data.host_list[1].host.available);
|
assert!(!result.check_data.list[1].resource.available);
|
||||||
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
|
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
|
||||||
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
|
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,9 +71,9 @@
|
||||||
//! let response = client.transact(&domain_check, "transaction-id").await.unwrap();
|
//! let response = client.transact(&domain_check, "transaction-id").await.unwrap();
|
||||||
//!
|
//!
|
||||||
//! // print the availability results
|
//! // print the availability results
|
||||||
//! response.res_data.unwrap().check_data.domain_list
|
//! response.res_data.unwrap().check_data.list
|
||||||
//! .iter()
|
//! .iter()
|
||||||
//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available));
|
//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.resource.name, chk.resource.available));
|
||||||
//!
|
//!
|
||||||
//! // Close the connection
|
//! // Close the connection
|
||||||
//! client.transact(&Logout, "transaction-id").await.unwrap();
|
//! client.transact(&Logout, "transaction-id").await.unwrap();
|
||||||
|
|
|
@ -107,8 +107,5 @@ async fn client() {
|
||||||
assert_eq!(rsp.result.code, ResultCode::CommandCompletedSuccessfully);
|
assert_eq!(rsp.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||||
|
|
||||||
let result = rsp.res_data().unwrap();
|
let result = rsp.res_data().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(result.check_data.list[0].resource.name, "eppdev.com".into());
|
||||||
result.check_data.domain_list[0].domain.name,
|
|
||||||
"eppdev.com".into()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue