diff --git a/epp-client/src/client.rs b/epp-client/src/client.rs index bdee383..5bf2175 100644 --- a/epp-client/src/client.rs +++ b/epp-client/src/client.rs @@ -45,10 +45,9 @@ use std::{error::Error, fmt::Debug}; -use crate::common::EppObject; use crate::config::EppClientConfig; use crate::error; -use crate::hello::{Greeting, Hello}; +use crate::hello::{Greeting, GreetingDocument, HelloDocument}; use crate::registry::{epp_connect, EppConnection}; use crate::request::{EppExtension, EppRequest}; use crate::response::Response; @@ -81,11 +80,11 @@ impl EppClient { /// Executes an EPP Hello call and returns the response as an `Greeting` pub async fn hello(&mut self) -> Result> { - let hello_xml = EppObject::::build(Hello).serialize()?; + let hello_xml = HelloDocument::default().serialize()?; let response = self.connection.transact(&hello_xml).await?; - Ok(EppObject::::deserialize(&response)?.data) + Ok(GreetingDocument::deserialize(&response)?.data) } pub async fn transact( @@ -117,6 +116,6 @@ impl EppClient { /// Returns the greeting received on establishment of the connection as an `Greeting` pub fn greeting(&self) -> Result { - EppObject::::deserialize(&self.connection.greeting).map(|obj| obj.data) + GreetingDocument::deserialize(&self.connection.greeting).map(|obj| obj.data) } } diff --git a/epp-client/src/common.rs b/epp-client/src/common.rs index 099a653..281dd58 100644 --- a/epp-client/src/common.rs +++ b/epp-client/src/common.rs @@ -3,11 +3,11 @@ use std::{fmt::Display, str::FromStr}; use epp_client_macros::ElementName; -use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; +use serde::{Deserialize, Serialize}; use crate::request::EppExtension; -const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0"; +pub(crate) const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0"; /// Wraps String for easier serialization to and from values that are inner text /// for tags rather than attributes @@ -46,33 +46,6 @@ impl EppExtension for NoExtension { type Response = NoExtension; } -/// An EPP XML Document that is used either as an EPP XML request or -/// an EPP XML response -#[derive(Deserialize, Debug, PartialEq)] -#[serde(rename = "epp")] -pub struct EppObject { - /// XML namespace for the <epp> tag - pub xmlns: String, - /// the request or response object that is set or received in the EPP XML document - #[serde(alias = "greeting", alias = "response")] - pub data: T, - // TODO: save serialized xml in the instance for debugging or client logging purposes - // #[serde(skip)] - // pub xml: Option, -} - -impl Serialize for EppObject { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut state = serializer.serialize_struct("epp", 4)?; - state.serialize_field("xmlns", &self.xmlns)?; - state.serialize_field(T::ELEMENT, &self.data)?; - state.end() - } -} - /// The