Refactor Logout into logout.rs

This commit is contained in:
Nicholas Rempel 2021-11-29 14:38:37 -08:00 committed by masalachai
parent 2745e2b1ca
commit 8de5984e38
7 changed files with 40 additions and 26 deletions

View File

@ -54,8 +54,9 @@ use crate::connection::registry::{epp_connect, EppConnection};
use crate::error; use crate::error;
use crate::hello::{EppGreeting, EppHello}; use crate::hello::{EppGreeting, EppHello};
use crate::login::{EppLogin, EppLoginResponse}; use crate::login::{EppLogin, EppLoginResponse};
use crate::request::{generate_client_tr_id, EppLogout}; use crate::logout::{EppLogout, EppLogoutResponse};
use crate::response::{EppCommandResponse, EppCommandResponseError, EppLogoutResponse}; use crate::request::generate_client_tr_id;
use crate::response::{EppCommandResponse, EppCommandResponseError};
use crate::xml::EppXml; use crate::xml::EppXml;
/// Instances of the EppClient type are used to transact with the registry. /// Instances of the EppClient type are used to transact with the registry.
/// Once initialized, the EppClient instance can serialize EPP requests to XML and send them /// Once initialized, the EppClient instance can serialize EPP requests to XML and send them

View File

@ -109,6 +109,7 @@ pub mod error;
pub mod hello; pub mod hello;
pub mod host; pub mod host;
pub mod login; pub mod login;
pub mod logout;
pub mod message; pub mod message;
pub mod request; pub mod request;
pub mod response; pub mod response;

32
epp-client/src/logout.rs Normal file
View File

@ -0,0 +1,32 @@
use std::fmt::Debug;
use epp_client_macros::ElementName;
use serde::{Deserialize, Serialize};
use crate::{
common::{ElementName, EppObject},
request::Command,
response::EppCommandResponse,
};
/// The EPP Logout request
pub type EppLogout = EppObject<Command<Logout>>;
impl EppLogout {
/// Creates a new EPP Logout request
pub fn new(client_tr_id: &str) -> EppLogout {
EppObject::build(Command::<Logout> {
command: Logout,
extension: None,
client_tr_id: client_tr_id.into(),
})
}
}
/// An alias of `EppCommandResponse` received in response to a successful logout request
pub type EppLogoutResponse = EppCommandResponse;
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
#[element_name(name = "logout")]
/// Type corresponding to the &lt;logout&gt; tag in an EPP XML logout request
pub struct Logout;

View File

@ -4,7 +4,7 @@ use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize};
use std::error::Error; use std::error::Error;
use std::time::SystemTime; use std::time::SystemTime;
use crate::common::{ElementName, EmptyTag, EppObject, Extension, StringValue}; use crate::common::{ElementName, EmptyTag, Extension, StringValue};
use epp_client_macros::ElementName; use epp_client_macros::ElementName;
pub const EPP_VERSION: &str = "1.0"; pub const EPP_VERSION: &str = "1.0";
@ -14,9 +14,6 @@ pub const EPP_LANG: &str = "en";
/// without an &lt;extension&gt; tag /// without an &lt;extension&gt; tag
pub type Command<T> = CommandWithExtension<T, EmptyTag>; pub type Command<T> = CommandWithExtension<T, EmptyTag>;
/// The EPP Logout request
pub type EppLogout = EppObject<Command<Logout>>;
#[derive(Deserialize, Debug, PartialEq, ElementName)] #[derive(Deserialize, Debug, PartialEq, ElementName)]
#[element_name(name = "command")] #[element_name(name = "command")]
/// Type corresponding to the &lt;command&gt; tag in an EPP XML request /// Type corresponding to the &lt;command&gt; tag in an EPP XML request
@ -73,19 +70,3 @@ pub fn generate_client_tr_id(username: &str) -> Result<String, Box<dyn Error>> {
let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
Ok(format!("{}:{}", username, timestamp.as_secs())) Ok(format!("{}:{}", username, timestamp.as_secs()))
} }
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
#[element_name(name = "logout")]
/// Type corresponding to the &lt;logout&gt; tag in an EPP XML logout request
pub struct Logout;
impl EppLogout {
/// Creates a new EPP Logout request
pub fn new(client_tr_id: &str) -> EppLogout {
EppObject::build(Command::<Logout> {
command: Logout,
extension: None,
client_tr_id: client_tr_id.into(),
})
}
}

View File

@ -13,8 +13,6 @@ pub type CommandResponse<T> = CommandResponseWithExtension<T, EmptyTag>;
pub type EppCommandResponse = EppObject<CommandResponseStatus>; pub type EppCommandResponse = EppObject<CommandResponseStatus>;
/// An alias of `EppCommandResponse` indicating an EPP Error /// An alias of `EppCommandResponse` indicating an EPP Error
pub type EppCommandResponseError = EppCommandResponse; pub type EppCommandResponseError = EppCommandResponse;
/// An alias of `EppCommandResponse` received in response to a successful logout request
pub type EppLogoutResponse = EppCommandResponse;
/// Type corresponding to the <undef> tag an EPP response XML /// Type corresponding to the <undef> tag an EPP response XML
#[derive(Serialize, Deserialize, Debug, PartialEq)] #[derive(Serialize, Deserialize, Debug, PartialEq)]

View File

@ -29,9 +29,10 @@ mod response {
use crate::host::info::EppHostInfoResponse; use crate::host::info::EppHostInfoResponse;
use crate::host::update::EppHostUpdateResponse; use crate::host::update::EppHostUpdateResponse;
use crate::login::EppLoginResponse; use crate::login::EppLoginResponse;
use crate::logout::EppLogoutResponse;
use crate::message::ack::EppMessageAckResponse; use crate::message::ack::EppMessageAckResponse;
use crate::message::poll::EppMessagePollResponse; use crate::message::poll::EppMessagePollResponse;
use crate::response::{EppCommandResponseError, EppLogoutResponse}; use crate::response::EppCommandResponseError;
use crate::xml::EppXml; use crate::xml::EppXml;
const SVTRID: &str = "RO-6879-1627224678242975"; const SVTRID: &str = "RO-6879-1627224678242975";

View File

@ -36,9 +36,9 @@ mod request {
use crate::host::update::HostAddRemove; use crate::host::update::HostAddRemove;
use crate::host::update::HostChangeInfo; use crate::host::update::HostChangeInfo;
use crate::login::EppLogin; use crate::login::EppLogin;
use crate::logout::EppLogout;
use crate::message::ack::EppMessageAck; use crate::message::ack::EppMessageAck;
use crate::message::poll::EppMessagePoll; use crate::message::poll::EppMessagePoll;
use crate::request::EppLogout;
use crate::xml::EppXml; use crate::xml::EppXml;
use chrono::{DateTime, NaiveDate}; use chrono::{DateTime, NaiveDate};
use std::str::FromStr; use std::str::FromStr;