From a5d6643d6fb99bcb5d7557001832beaf7dfb96d1 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 27 Jan 2022 12:24:47 +0100 Subject: [PATCH] Share CheckResponse type with contacts --- src/common.rs | 4 +-- src/contact/check.rs | 61 ++++++++------------------------------------ src/domain/check.rs | 4 +-- src/host/check.rs | 4 +-- src/lib.rs | 2 +- tests/basic.rs | 2 +- 6 files changed, 19 insertions(+), 58 deletions(-) diff --git a/src/common.rs b/src/common.rs index df43b09..bb09e95 100644 --- a/src/common.rs +++ b/src/common.rs @@ -44,7 +44,7 @@ impl Extension for NoExtension { pub struct Available { /// The resource name #[serde(rename = "$value")] - pub name: StringValue<'static>, + pub id: StringValue<'static>, /// The resource (un)availability #[serde(rename = "avail")] pub available: bool, @@ -54,7 +54,7 @@ pub struct Available { #[derive(Deserialize, Debug)] pub struct CheckResponseDataItem { /// Data under the <name> tag - #[serde(rename = "name")] + #[serde(rename = "name", alias = "id")] pub resource: Available, /// The reason for (un)availability pub reason: Option>, diff --git a/src/contact/check.rs b/src/contact/check.rs index 5ad94f7..f3d4164 100644 --- a/src/contact/check.rs +++ b/src/contact/check.rs @@ -2,12 +2,17 @@ use std::fmt::Debug; /// Types for EPP contact check request use super::XMLNS; -use crate::common::{NoExtension, StringValue}; +use crate::common::{CheckResponse, NoExtension, StringValue}; use crate::request::{Command, Transaction}; -use serde::{Deserialize, Serialize}; +use serde::Serialize; impl<'a> Transaction for ContactCheck<'a> {} +impl<'a> Command for ContactCheck<'a> { + type Response = CheckResponse; + const COMMAND: &'static str = "check"; +} + // Request /// Type that represents the <check> command for contact transactions @@ -40,50 +45,6 @@ impl<'a> ContactCheck<'a> { } } -impl<'a> Command for ContactCheck<'a> { - type Response = ContactCheckResponse; - const COMMAND: &'static str = "check"; -} - -// Response - -/// Type that represents the <id> tag for contact check response -#[derive(Deserialize, Debug)] -pub struct ContactAvailable { - /// The text of the <id> tag - #[serde(rename = "$value")] - pub id: StringValue<'static>, - /// The avail attr on the <id> tag - #[serde(rename = "avail")] - pub available: bool, -} - -/// Type that represents the <cd> tag for contact check response -#[derive(Deserialize, Debug)] -pub struct ContactCheckResponseDataItem { - /// Data under the <id> tag - #[serde(rename = "id")] - pub contact: ContactAvailable, - /// The reason for (un)availability - pub reason: Option>, -} - -/// Type that represents the <chkData> tag for contact check response -#[derive(Deserialize, Debug)] -pub struct ContactCheckResponseData { - /// Data under the <cd> tag - #[serde(rename = "cd")] - pub contact_list: Vec, -} - -/// Type that represents the <resData> tag for contact check response -#[derive(Deserialize, Debug)] -pub struct ContactCheckResponse { - /// Data under the <chkData> tag - #[serde(rename = "chkData")] - pub check_data: ContactCheckResponseData, -} - #[cfg(test)] mod tests { use super::ContactCheck; @@ -114,15 +75,15 @@ mod tests { assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!( - results.check_data.contact_list[0].contact.id, + results.check_data.list[0].resource.id, "eppdev-contact-1".into() ); - assert!(!results.check_data.contact_list[0].contact.available); + assert!(!results.check_data.list[0].resource.available); assert_eq!( - results.check_data.contact_list[1].contact.id, + results.check_data.list[1].resource.id, "eppdev-contact-2".into() ); - assert!(results.check_data.contact_list[1].contact.available); + assert!(results.check_data.list[1].resource.available); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); } diff --git a/src/domain/check.rs b/src/domain/check.rs index ee1e0ad..5fe88d4 100644 --- a/src/domain/check.rs +++ b/src/domain/check.rs @@ -75,9 +75,9 @@ mod tests { assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); - assert_eq!(result.check_data.list[0].resource.name, "eppdev.com".into()); + assert_eq!(result.check_data.list[0].resource.id, "eppdev.com".into()); assert!(result.check_data.list[0].resource.available); - assert_eq!(result.check_data.list[1].resource.name, "eppdev.net".into()); + assert_eq!(result.check_data.list[1].resource.id, "eppdev.net".into()); assert!(!result.check_data.list[1].resource.available); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); diff --git a/src/host/check.rs b/src/host/check.rs index 5ab9a2b..af3bcee 100644 --- a/src/host/check.rs +++ b/src/host/check.rs @@ -80,12 +80,12 @@ mod tests { assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully); assert_eq!(object.result.message, SUCCESS_MSG.into()); assert_eq!( - result.check_data.list[0].resource.name, + result.check_data.list[0].resource.id, "host1.eppdev-1.com".into() ); assert!(result.check_data.list[0].resource.available); assert_eq!( - result.check_data.list[1].resource.name, + result.check_data.list[1].resource.id, "ns1.testing.com".into() ); assert!(!result.check_data.list[1].resource.available); diff --git a/src/lib.rs b/src/lib.rs index bbfeac8..0aea2b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ //! // print the availability results //! response.res_data.unwrap().check_data.list //! .iter() -//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.resource.name, chk.resource.available)); +//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.resource.id, chk.resource.available)); //! //! // Close the connection //! client.transact(&Logout, "transaction-id").await.unwrap(); diff --git a/tests/basic.rs b/tests/basic.rs index 8e889be..62254a1 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -107,5 +107,5 @@ async fn client() { assert_eq!(rsp.result.code, ResultCode::CommandCompletedSuccessfully); let result = rsp.res_data().unwrap(); - assert_eq!(result.check_data.list[0].resource.name, "eppdev.com".into()); + assert_eq!(result.check_data.list[0].resource.id, "eppdev.com".into()); }