Refactor message poll models

This commit is contained in:
Nicholas Rempel 2021-11-26 10:45:56 -08:00 committed by masalachai
parent dd102fa2cf
commit 8bf0283b7e
10 changed files with 62 additions and 73 deletions

View File

@ -5,8 +5,4 @@ pub mod request;
pub mod response; pub mod response;
pub mod xml; 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; pub use crate::connection::client::default_client_tr_id_fn as generate_client_tr_id;

View File

@ -1,7 +1,5 @@
//! Types for EPP requests //! Types for EPP requests
pub mod message;
use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize}; use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize};
use std::error::Error; use std::error::Error;
use std::time::SystemTime; use std::time::SystemTime;

View File

@ -1,3 +0,0 @@
//! Types for EPP message requests
pub mod poll;

View File

@ -1,7 +1,5 @@
//! Types for EPP responses //! Types for EPP responses
pub mod message;
use epp_client_macros::*; use epp_client_macros::*;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use std::fmt::Debug; use std::fmt::Debug;

View File

@ -1,3 +0,0 @@
//! Types for EPP message responses
pub mod poll;

View File

@ -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<CommandResponse<MessagePollResult>>;
/// Type that represents the &lt;trnData&gt; 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 &lt;resData&gt; tag for message poll response
#[derive(Serialize, Deserialize, Debug)]
pub struct MessagePollResult {
/// Data under the &lt;trnData&gt; tag
#[serde(rename = "obj:trnData", alias = "trnData")]
pub message_data: MessageDomainTransferData,
}

View File

@ -1 +1,2 @@
pub mod ack; pub mod ack;
pub mod poll;

View File

@ -2,8 +2,9 @@
use epp_client_macros::*; 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::request::Command;
use crate::epp::response::CommandResponse;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Type that represents the &lt;epp&gt; request for registry <poll op="req"> command /// Type that represents the &lt;epp&gt; request for registry <poll op="req"> command
@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize};
/// ///
/// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient; /// 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; /// use epp_client::epp::generate_client_tr_id;
/// ///
/// #[tokio::main] /// #[tokio::main]
@ -52,25 +53,69 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppMessagePoll = EppObject<Command<MessagePoll>>; pub type EppMessagePoll = EppObject<Command<MessagePollRequest>>;
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "poll")]
/// Type for EPP XML &lt;poll&gt; command for message poll
pub struct MessagePoll {
/// The type of operation to perform
/// The value is "req" for message polling
op: String,
}
impl EppMessagePoll { impl EppMessagePoll {
/// Creates a new EppObject for &lt;poll&gt; req corresponding to the &lt;epp&gt; tag in EPP XML /// Creates a new EppObject for &lt;poll&gt; req corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(client_tr_id: &str) -> EppMessagePoll { pub fn new(client_tr_id: &str) -> EppMessagePoll {
EppObject::build(Command::<MessagePoll>::new( EppObject::build(Command::<MessagePollRequest>::new(
MessagePoll { MessagePollRequest {
op: "req".to_string(), op: "req".to_string(),
}, },
client_tr_id, client_tr_id,
)) ))
} }
} }
/// Type that represents the &lt;epp&gt; tag for the EPP XML message poll response
pub type EppMessagePollResponse = EppObject<CommandResponse<MessagePollResponse>>;
// Request
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "poll")]
/// Type for EPP XML &lt;poll&gt; 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 &lt;trnData&gt; 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 &lt;resData&gt; tag for message poll response
#[derive(Serialize, Deserialize, Debug)]
pub struct MessagePollResponse {
/// Data under the &lt;trnData&gt; tag
#[serde(rename = "obj:trnData", alias = "trnData")]
pub message_data: MessageDomainTransferData,
}

View File

@ -33,6 +33,7 @@ mod response {
use crate::host::info::EppHostInfoResponse; use crate::host::info::EppHostInfoResponse;
use crate::host::update::EppHostUpdateResponse; use crate::host::update::EppHostUpdateResponse;
use crate::message::ack::EppMessageAckResponse; use crate::message::ack::EppMessageAckResponse;
use crate::message::poll::EppMessagePollResponse;
const SVTRID: &str = "RO-6879-1627224678242975"; const SVTRID: &str = "RO-6879-1627224678242975";
const SUCCESS_MSG: &str = "Command completed successfully"; const SUCCESS_MSG: &str = "Command completed successfully";

View File

@ -38,6 +38,7 @@ mod request {
use crate::host::update::HostAddRemove; use crate::host::update::HostAddRemove;
use crate::host::update::HostChangeInfo; use crate::host::update::HostChangeInfo;
use crate::message::ack::EppMessageAck; use crate::message::ack::EppMessageAck;
use crate::message::poll::EppMessagePoll;
use chrono::{DateTime, NaiveDate}; use chrono::{DateTime, NaiveDate};
use std::str::FromStr; use std::str::FromStr;