Let callers create CommandDocument directly
This commit is contained in:
parent
dd07ecc4b8
commit
5dce8501d5
|
@ -19,7 +19,7 @@ pub use crate::connection::Connector;
|
||||||
use crate::connection::{self, EppConnection};
|
use crate::connection::{self, EppConnection};
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
|
||||||
use crate::request::{Command, Extension, Transaction};
|
use crate::request::{Command, CommandDocument, Extension, Transaction};
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
use crate::xml::EppXml;
|
use crate::xml::EppXml;
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ impl<C: Connector> EppClient<C> {
|
||||||
Ext: Extension + 'e,
|
Ext: Extension + 'e,
|
||||||
{
|
{
|
||||||
let data = data.into();
|
let data = data.into();
|
||||||
let document = <Cmd as Transaction<Ext>>::command(data.command, data.extension, id);
|
let document = CommandDocument::new(data.command, data.extension, id);
|
||||||
let xml = document.serialize()?;
|
let xml = document.serialize()?;
|
||||||
|
|
||||||
debug!("{}: request: {}", self.connection.registry, &xml);
|
debug!("{}: request: {}", self.connection.registry, &xml);
|
||||||
|
|
|
@ -15,19 +15,6 @@ pub const EPP_LANG: &str = "en";
|
||||||
|
|
||||||
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
||||||
pub trait Transaction<Ext: Extension>: Command + Sized {
|
pub trait Transaction<Ext: Extension>: Command + Sized {
|
||||||
fn command<'c, 'e: 'c, 'i: 'c>(
|
|
||||||
&'c self,
|
|
||||||
extension: Option<&'e Ext>,
|
|
||||||
client_tr_id: &'i str,
|
|
||||||
) -> CommandDocument<'c, Self, Ext> {
|
|
||||||
CommandDocument::new(CommandWrapper {
|
|
||||||
command: Self::COMMAND,
|
|
||||||
data: self,
|
|
||||||
extension,
|
|
||||||
client_tr_id: client_tr_id.into(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deserialize_response(
|
fn deserialize_response(
|
||||||
epp_xml: &str,
|
epp_xml: &str,
|
||||||
) -> Result<Response<Self::Response, Ext::Response>, Error> {
|
) -> Result<Response<Self::Response, Ext::Response>, Error> {
|
||||||
|
@ -55,7 +42,7 @@ pub trait Extension: Serialize + Debug {
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
/// Type corresponding to the <command> tag in an EPP XML request
|
/// Type corresponding to the <command> tag in an EPP XML request
|
||||||
/// with an <extension> tag
|
/// with an <extension> tag
|
||||||
pub struct CommandWrapper<'a, D, E> {
|
struct CommandWrapper<'a, D, E> {
|
||||||
pub command: &'static str,
|
pub command: &'static str,
|
||||||
/// The instance that will be used to populate the <command> tag
|
/// The instance that will be used to populate the <command> tag
|
||||||
pub data: &'a D,
|
pub data: &'a D,
|
||||||
|
@ -80,16 +67,25 @@ impl<'a, D: Serialize, E: Serialize> Serialize for CommandWrapper<'a, D, E> {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize)]
|
#[derive(Debug, PartialEq, Serialize)]
|
||||||
#[serde(rename = "epp")]
|
#[serde(rename = "epp")]
|
||||||
pub struct CommandDocument<'a, D, E> {
|
pub(crate) struct CommandDocument<'a, Cmd, Ext> {
|
||||||
xmlns: &'static str,
|
xmlns: &'static str,
|
||||||
command: CommandWrapper<'a, D, E>,
|
command: CommandWrapper<'a, Cmd, Ext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, D, E> CommandDocument<'a, D, E> {
|
impl<'a, Cmd, Ext> CommandDocument<'a, Cmd, Ext> {
|
||||||
pub fn new(command: CommandWrapper<'a, D, E>) -> Self {
|
pub(crate) fn new(data: &'a Cmd, extension: Option<&'a Ext>, client_tr_id: &'a str) -> Self
|
||||||
|
where
|
||||||
|
Cmd: Transaction<Ext>,
|
||||||
|
Ext: Extension,
|
||||||
|
{
|
||||||
Self {
|
Self {
|
||||||
xmlns: EPP_XMLNS,
|
xmlns: EPP_XMLNS,
|
||||||
command,
|
command: CommandWrapper {
|
||||||
|
command: Cmd::COMMAND,
|
||||||
|
data,
|
||||||
|
extension,
|
||||||
|
client_tr_id: client_tr_id.into(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use regex::Regex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::RequestData,
|
client::RequestData,
|
||||||
request::{Command, Extension, Transaction},
|
request::{Command, CommandDocument, Extension, Transaction},
|
||||||
xml::EppXml,
|
xml::EppXml,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ pub(crate) fn assert_serialized<'c, 'e, Cmd, Ext>(
|
||||||
{
|
{
|
||||||
let expected = get_xml(path).unwrap();
|
let expected = get_xml(path).unwrap();
|
||||||
let req = req.into();
|
let req = req.into();
|
||||||
let document = <Cmd as Transaction<Ext>>::command(req.command, req.extension, CLTRID);
|
let document = CommandDocument::new(req.command, req.extension, CLTRID);
|
||||||
let actual = EppXml::serialize(&document).unwrap();
|
let actual = EppXml::serialize(&document).unwrap();
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue