From 8bf0283b7e4fb5ca5a2aaaa90eb5c28abb6bee75 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Fri, 26 Nov 2021 10:45:56 -0800 Subject: [PATCH] Refactor message poll models --- epp-client/src/epp.rs | 4 - epp-client/src/epp/request.rs | 2 - epp-client/src/epp/request/message.rs | 3 - epp-client/src/epp/response.rs | 2 - epp-client/src/epp/response/message.rs | 3 - epp-client/src/epp/response/message/poll.rs | 45 ------------ epp-client/src/message.rs | 1 + .../src/{epp/request => }/message/poll.rs | 73 +++++++++++++++---- epp-client/src/tests/de.rs | 1 + epp-client/src/tests/se.rs | 1 + 10 files changed, 62 insertions(+), 73 deletions(-) delete mode 100644 epp-client/src/epp/request/message.rs delete mode 100644 epp-client/src/epp/response/message.rs delete mode 100644 epp-client/src/epp/response/message/poll.rs rename epp-client/src/{epp/request => }/message/poll.rs (52%) diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index 332a201..6fcdd9e 100644 --- a/epp-client/src/epp.rs +++ b/epp-client/src/epp.rs @@ -5,8 +5,4 @@ pub mod request; pub mod response; pub mod xml; -pub use request::message::poll::*; - -pub use response::message::poll::*; - pub use crate::connection::client::default_client_tr_id_fn as generate_client_tr_id; diff --git a/epp-client/src/epp/request.rs b/epp-client/src/epp/request.rs index 15b3d5b..77f61e4 100644 --- a/epp-client/src/epp/request.rs +++ b/epp-client/src/epp/request.rs @@ -1,7 +1,5 @@ //! Types for EPP requests -pub mod message; - use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize}; use std::error::Error; use std::time::SystemTime; diff --git a/epp-client/src/epp/request/message.rs b/epp-client/src/epp/request/message.rs deleted file mode 100644 index 547c027..0000000 --- a/epp-client/src/epp/request/message.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Types for EPP message requests - -pub mod poll; diff --git a/epp-client/src/epp/response.rs b/epp-client/src/epp/response.rs index 0806f27..7a6caa6 100644 --- a/epp-client/src/epp/response.rs +++ b/epp-client/src/epp/response.rs @@ -1,7 +1,5 @@ //! Types for EPP responses -pub mod message; - use epp_client_macros::*; use serde::{Deserialize, Deserializer, Serialize}; use std::fmt::Debug; diff --git a/epp-client/src/epp/response/message.rs b/epp-client/src/epp/response/message.rs deleted file mode 100644 index ec7957f..0000000 --- a/epp-client/src/epp/response/message.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Types for EPP message responses - -pub mod poll; diff --git a/epp-client/src/epp/response/message/poll.rs b/epp-client/src/epp/response/message/poll.rs deleted file mode 100644 index 47afe07..0000000 --- a/epp-client/src/epp/response/message/poll.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! Types for EPP message poll response - -use crate::epp::object::{EppObject, StringValue}; -use crate::epp::response::CommandResponse; -use serde::{Deserialize, Serialize}; - -/// Type that represents the <epp> tag for the EPP XML message poll response -pub type EppMessagePollResponse = EppObject>; - -/// Type that represents the <trnData> tag for message poll response -#[derive(Serialize, Deserialize, Debug)] -pub struct MessageDomainTransferData { - /// XML namespace for message response data - #[serde(rename = "xmlns:obj", alias = "xmlns")] - xmlns: String, - /// The name of the domain under transfer - #[serde(rename = "obj:name", alias = "name")] - pub name: StringValue, - /// The domain transfer status - #[serde(rename = "obj:trStatus", alias = "trStatus")] - pub transfer_status: StringValue, - /// The epp user who requested the transfer - #[serde(rename = "obj:reID", alias = "reID")] - pub requester_id: StringValue, - /// The date of the transfer request - #[serde(rename = "obj:reDate", alias = "reDate")] - pub requested_at: StringValue, - /// The epp user who should acknowledge the transfer request - #[serde(rename = "obj:acID", alias = "acID")] - pub ack_id: StringValue, - /// The date by which the transfer request should be acknowledged - #[serde(rename = "obj:acDate", alias = "acDate")] - pub ack_by: StringValue, - /// The domain expiry date - #[serde(rename = "obj:exDate", alias = "exDate")] - pub expiring_at: StringValue, -} - -/// Type that represents the <resData> tag for message poll response -#[derive(Serialize, Deserialize, Debug)] -pub struct MessagePollResult { - /// Data under the <trnData> tag - #[serde(rename = "obj:trnData", alias = "trnData")] - pub message_data: MessageDomainTransferData, -} diff --git a/epp-client/src/message.rs b/epp-client/src/message.rs index ef98272..60b48c9 100644 --- a/epp-client/src/message.rs +++ b/epp-client/src/message.rs @@ -1 +1,2 @@ pub mod ack; +pub mod poll; diff --git a/epp-client/src/epp/request/message/poll.rs b/epp-client/src/message/poll.rs similarity index 52% rename from epp-client/src/epp/request/message/poll.rs rename to epp-client/src/message/poll.rs index 16f884a..5f04d11 100644 --- a/epp-client/src/epp/request/message/poll.rs +++ b/epp-client/src/message/poll.rs @@ -2,8 +2,9 @@ use epp_client_macros::*; -use crate::epp::object::{ElementName, EppObject}; +use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::request::Command; +use crate::epp::response::CommandResponse; use serde::{Deserialize, Serialize}; /// Type that represents the <epp> request for registry command @@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::epp::{EppMessagePoll, EppMessagePollResponse}; +/// use epp_client::message::poll::{EppMessagePoll, EppMessagePollResponse}; /// use epp_client::epp::generate_client_tr_id; /// /// #[tokio::main] @@ -52,25 +53,69 @@ use serde::{Deserialize, Serialize}; /// client.logout().await.unwrap(); /// } /// ``` -pub type EppMessagePoll = EppObject>; - -#[derive(Serialize, Deserialize, Debug, ElementName)] -#[element_name(name = "poll")] -/// Type for EPP XML <poll> command for message poll -pub struct MessagePoll { - /// The type of operation to perform - /// The value is "req" for message polling - op: String, -} +pub type EppMessagePoll = EppObject>; impl EppMessagePoll { /// Creates a new EppObject for <poll> req corresponding to the <epp> tag in EPP XML pub fn new(client_tr_id: &str) -> EppMessagePoll { - EppObject::build(Command::::new( - MessagePoll { + EppObject::build(Command::::new( + MessagePollRequest { op: "req".to_string(), }, client_tr_id, )) } } + +/// Type that represents the <epp> tag for the EPP XML message poll response +pub type EppMessagePollResponse = EppObject>; + +// Request + +#[derive(Serialize, Deserialize, Debug, ElementName)] +#[element_name(name = "poll")] +/// Type for EPP XML <poll> command for message poll +pub struct MessagePollRequest { + /// The type of operation to perform + /// The value is "req" for message polling + op: String, +} + +// Response + +/// Type that represents the <trnData> tag for message poll response +#[derive(Serialize, Deserialize, Debug)] +pub struct MessageDomainTransferData { + /// XML namespace for message response data + #[serde(rename = "xmlns:obj", alias = "xmlns")] + xmlns: String, + /// The name of the domain under transfer + #[serde(rename = "obj:name", alias = "name")] + pub name: StringValue, + /// The domain transfer status + #[serde(rename = "obj:trStatus", alias = "trStatus")] + pub transfer_status: StringValue, + /// The epp user who requested the transfer + #[serde(rename = "obj:reID", alias = "reID")] + pub requester_id: StringValue, + /// The date of the transfer request + #[serde(rename = "obj:reDate", alias = "reDate")] + pub requested_at: StringValue, + /// The epp user who should acknowledge the transfer request + #[serde(rename = "obj:acID", alias = "acID")] + pub ack_id: StringValue, + /// The date by which the transfer request should be acknowledged + #[serde(rename = "obj:acDate", alias = "acDate")] + pub ack_by: StringValue, + /// The domain expiry date + #[serde(rename = "obj:exDate", alias = "exDate")] + pub expiring_at: StringValue, +} + +/// Type that represents the <resData> tag for message poll response +#[derive(Serialize, Deserialize, Debug)] +pub struct MessagePollResponse { + /// Data under the <trnData> tag + #[serde(rename = "obj:trnData", alias = "trnData")] + pub message_data: MessageDomainTransferData, +} diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index a4bf1ff..e283359 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -33,6 +33,7 @@ mod response { use crate::host::info::EppHostInfoResponse; use crate::host::update::EppHostUpdateResponse; use crate::message::ack::EppMessageAckResponse; + use crate::message::poll::EppMessagePollResponse; const SVTRID: &str = "RO-6879-1627224678242975"; const SUCCESS_MSG: &str = "Command completed successfully"; diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index 46de6a3..d7ad662 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -38,6 +38,7 @@ mod request { use crate::host::update::HostAddRemove; use crate::host::update::HostChangeInfo; use crate::message::ack::EppMessageAck; + use crate::message::poll::EppMessagePoll; use chrono::{DateTime, NaiveDate}; use std::str::FromStr;