Remove Hello and Greeting type aliases

This commit is contained in:
Dirkjan Ochtman 2021-12-02 14:40:59 +01:00 committed by masalachai
parent 140f6830a9
commit edb2a2627d
4 changed files with 11 additions and 32 deletions

View File

@ -50,7 +50,7 @@
use std::time::SystemTime; use std::time::SystemTime;
use std::{error::Error, fmt::Debug}; use std::{error::Error, fmt::Debug};
use crate::common::NoExtension; use crate::common::{EppObject, NoExtension};
use crate::config::EppClientConfig; use crate::config::EppClientConfig;
use crate::error; use crate::error;
use crate::hello::{Greeting, Hello}; use crate::hello::{Greeting, Hello};
@ -131,12 +131,11 @@ impl EppClient {
/// Executes an EPP Hello call and returns the response as an `EppGreeting` /// Executes an EPP Hello call and returns the response as an `EppGreeting`
pub async fn hello(&mut self) -> Result<Greeting, Box<dyn Error>> { pub async fn hello(&mut self) -> Result<Greeting, Box<dyn Error>> {
let hello = Hello::new(); let hello_xml = EppObject::<Hello>::build(Hello).serialize()?;
let hello_xml = hello.serialize()?;
let response = self.connection.transact(&hello_xml).await?; let response = self.connection.transact(&hello_xml).await?;
Ok(Greeting::deserialize(&response)?) Ok(EppObject::<Greeting>::deserialize(&response)?.data)
} }
pub async fn transact<T, E>( pub async fn transact<T, E>(
@ -173,7 +172,7 @@ impl EppClient {
/// Returns the greeting received on establishment of the connection as an `EppGreeting` /// Returns the greeting received on establishment of the connection as an `EppGreeting`
pub fn greeting(&self) -> Result<Greeting, error::Error> { pub fn greeting(&self) -> Result<Greeting, error::Error> {
Greeting::deserialize(&self.connection.greeting) EppObject::<Greeting>::deserialize(&self.connection.greeting).map(|obj| obj.data)
} }
/// Sends the EPP Logout command to log out of the EPP session /// Sends the EPP Logout command to log out of the EPP session

View File

@ -3,33 +3,14 @@ use std::fmt::Debug;
use epp_client_macros::ElementName; use epp_client_macros::ElementName;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use crate::common::{ElementName, EppObject, Options, ServiceExtension, Services, StringValue}; use crate::common::{ElementName, Options, ServiceExtension, Services, StringValue};
/// The EPP Hello request
pub type Hello = EppObject<HelloRequest>;
impl Hello {
/// Creates a new Epp Hello request
pub fn new() -> Hello {
EppObject::build(HelloRequest {})
}
}
impl Default for Hello {
fn default() -> Self {
Self::new()
}
}
/// The EPP Greeting that is received on a successful connection and in response to an EPP hello
pub type Greeting = EppObject<GreetingResponse>;
// Request // Request
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
#[element_name(name = "hello")] #[element_name(name = "hello")]
/// Type corresponding to the <hello> tag in an EPP XML hello request /// Type corresponding to the <hello> tag in an EPP XML hello request
pub struct HelloRequest; pub struct Hello;
// Response // Response
@ -284,7 +265,7 @@ pub struct Dcp {
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
#[element_name(name = "greeting")] #[element_name(name = "greeting")]
/// Type corresponding to the <greeting> tag in the EPP greeting XML /// Type corresponding to the <greeting> tag in the EPP greeting XML
pub struct GreetingResponse { pub struct Greeting {
/// The service ID /// The service ID
#[serde(rename = "svID")] #[serde(rename = "svID")]
pub service_id: String, pub service_id: String,

View File

@ -44,7 +44,7 @@ mod response {
#[test] #[test]
fn greeting() { fn greeting() {
let xml = get_xml("response/greeting.xml").unwrap(); let xml = get_xml("response/greeting.xml").unwrap();
let object = Greeting::deserialize(xml.as_str()).unwrap(); let object = EppObject::<Greeting>::deserialize(xml.as_str()).unwrap();
assert_eq!(object.data.service_id, "ISPAPI EPP Server"); assert_eq!(object.data.service_id, "ISPAPI EPP Server");
assert_eq!(object.data.service_date, "2021-07-25T14:51:17.0Z"); assert_eq!(object.data.service_date, "2021-07-25T14:51:17.0Z");

View File

@ -8,8 +8,8 @@ mod request {
use crate::common::HostObjList; use crate::common::HostObjList;
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::common::{ use crate::common::{
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr, Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, EppObject, HostAddr,
HostStatus, Phone, PostalInfo, HostAttr, HostStatus, Phone, PostalInfo,
}; };
use crate::contact::check::ContactCheck; use crate::contact::check::ContactCheck;
use crate::contact::create::ContactCreate; use crate::contact::create::ContactCreate;
@ -52,8 +52,7 @@ mod request {
#[test] #[test]
fn hello() { fn hello() {
let xml = get_xml("request/hello.xml").unwrap(); let xml = get_xml("request/hello.xml").unwrap();
let object = Hello::new(); let serialized = EppObject::<Hello>::build(Hello).serialize().unwrap();
let serialized = object.serialize().unwrap();
assert_eq!(xml, serialized); assert_eq!(xml, serialized);
} }