Complete Transaction impl coverage for NameStore extension

This commit is contained in:
Nicholas Rempel 2021-12-07 10:19:05 -08:00 committed by masalachai
parent 8490eefc59
commit 99f90f3c08
24 changed files with 196 additions and 82 deletions

View File

@ -37,7 +37,7 @@
//!
//! // Execute an EPP Command against the registry with distinct request and response objects
//! let domain_check = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]);
//! let response = client.transact(domain_check, "transaction-id").await.unwrap();
//! let response = client.transact(&domain_check, "transaction-id").await.unwrap();
//! println!("{:?}", response);
//!
//! }
@ -88,9 +88,9 @@ impl EppClient {
Ok(GreetingDocument::deserialize(&response)?.data)
}
pub async fn transact<C, E>(
pub async fn transact<'a, C: 'a, E: 'a>(
&mut self,
data: impl Into<RequestData<C, E>>,
data: impl Into<RequestData<'a, C, E>> + 'a,
id: &str,
) -> Result<Response<C::Response, E::Response>, error::Error>
where
@ -122,13 +122,13 @@ impl EppClient {
}
}
pub struct RequestData<C, E> {
command: C,
extension: Option<E>,
pub struct RequestData<'a, C, E> {
command: &'a C,
extension: Option<&'a E>,
}
impl<C: Command> From<C> for RequestData<C, NoExtension> {
fn from(command: C) -> Self {
impl<'a, C: Command> From<&'a C> for RequestData<'a, C, NoExtension> {
fn from(command: &'a C) -> Self {
Self {
command,
extension: None,
@ -136,8 +136,8 @@ impl<C: Command> From<C> for RequestData<C, NoExtension> {
}
}
impl<C: Command, E: Extension> From<(C, E)> for RequestData<C, E> {
fn from((command, extension): (C, E)) -> Self {
impl<'a, C: Command, E: Extension> From<(&'a C, &'a E)> for RequestData<'a, C, E> {
fn from((command, extension): (&'a C, &'a E)) -> Self {
Self {
command,
extension: Some(extension),

View File

@ -92,6 +92,7 @@ pub struct ContactCheckResponse {
#[cfg(test)]
mod tests {
use super::ContactCheck;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -99,7 +100,9 @@ mod tests {
fn command() {
let xml = get_xml("request/contact/check.xml").unwrap();
let object = ContactCheck::new(&["eppdev-contact-1", "eppdev-contact-2"]);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<ContactCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -107,7 +110,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/contact/check.xml").unwrap();
let object = ContactCheck::deserialize_response(xml.as_str()).unwrap();
let object =
<ContactCheck as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let results = object.res_data().unwrap();

View File

@ -101,7 +101,7 @@ pub struct ContactCreateResponse {
#[cfg(test)]
mod tests {
use super::{ContactCreate, Phone, PostalInfo};
use crate::common::Address;
use crate::common::{Address, NoExtension};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -126,7 +126,9 @@ mod tests {
);
object.set_fax(fax);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<ContactCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -134,7 +136,9 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/contact/create.xml").unwrap();
let object = ContactCreate::deserialize_response(xml.as_str()).unwrap();
let object =
<ContactCreate as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let results = object.res_data().unwrap();

View File

@ -45,6 +45,7 @@ impl ContactDelete {
#[cfg(test)]
mod tests {
use super::ContactDelete;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -54,7 +55,9 @@ mod tests {
let object = ContactDelete::new("eppdev-contact-3");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<ContactDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -62,7 +65,9 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/contact/delete.xml").unwrap();
let object = ContactDelete::deserialize_response(xml.as_str()).unwrap();
let object =
<ContactDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -103,6 +103,7 @@ pub struct ContactInfoResponse {
#[cfg(test)]
mod tests {
use super::ContactInfo;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -112,7 +113,9 @@ mod tests {
let object = ContactInfo::new("eppdev-contact-3", "eppdev-387323");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<ContactInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -120,7 +123,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/contact/info.xml").unwrap();
let object = ContactInfo::deserialize_response(xml.as_str()).unwrap();
let object =
<ContactInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();
let fax = result.info_data.fax.as_ref().unwrap();

View File

@ -108,7 +108,7 @@ pub struct ContactUpdate {
#[cfg(test)]
mod tests {
use super::ContactUpdate;
use crate::common::{Address, ContactStatus, Phone, PostalInfo};
use crate::common::{Address, ContactStatus, NoExtension, Phone, PostalInfo};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -133,7 +133,9 @@ mod tests {
}];
object.remove(remove_statuses);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<ContactUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -141,7 +143,9 @@ mod tests {
#[test]
fn contact_update() {
let xml = get_xml("response/contact/update.xml").unwrap();
let object = ContactUpdate::deserialize_response(xml.as_str()).unwrap();
let object =
<ContactUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -100,7 +100,7 @@ mod tests {
let object = DomainCheck::new(vec!["eppdev.com", "eppdev.net"]);
let serialized =
<DomainCheck as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
<DomainCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);

View File

@ -103,7 +103,9 @@ pub struct DomainCreateResponse {
#[cfg(test)]
mod tests {
use super::DomainCreate;
use crate::common::{DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList};
use crate::common::{
DomainContact, HostAddr, HostAttr, HostAttrList, HostList, HostObjList, NoExtension,
};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -135,7 +137,9 @@ mod tests {
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -172,7 +176,9 @@ mod tests {
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -221,7 +227,9 @@ mod tests {
Some(contacts),
);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -229,7 +237,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/domain/create.xml").unwrap();
let object = DomainCreate::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainCreate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();

View File

@ -45,6 +45,7 @@ pub struct DomainDelete {
#[cfg(test)]
mod tests {
use super::DomainDelete;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -54,7 +55,9 @@ mod tests {
let object = DomainDelete::new("eppdev.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -62,7 +65,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/domain/delete.xml").unwrap();
let object = DomainDelete::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -147,7 +147,7 @@ mod tests {
let object = DomainInfo::new("eppdev.com", Some("2fooBAR"));
let serialized =
<DomainInfo as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
<DomainInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);

View File

@ -77,6 +77,7 @@ pub struct DomainRenewResponse {
#[cfg(test)]
mod tests {
use super::DomainRenew;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::NaiveDate;
@ -88,7 +89,9 @@ mod tests {
let exp_date = NaiveDate::from_ymd(2022, 7, 23);
let object = DomainRenew::new("eppdev.com", exp_date, 1);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainRenew as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -96,7 +99,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/domain/renew.xml").unwrap();
let object = DomainRenew::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainRenew as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();

View File

@ -145,6 +145,7 @@ pub struct DomainTransferResponse {
#[cfg(test)]
mod tests {
use super::DomainTransfer;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -154,7 +155,9 @@ mod tests {
let object = DomainTransfer::new("testing.com", Some(1), "epP4uthd#v");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -165,7 +168,9 @@ mod tests {
let object = DomainTransfer::approve("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -176,7 +181,9 @@ mod tests {
let object = DomainTransfer::reject("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -187,7 +194,9 @@ mod tests {
let object = DomainTransfer::cancel("testing.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -198,7 +207,9 @@ mod tests {
let object = DomainTransfer::query("testing.com", "epP4uthd#v");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<DomainTransfer as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -206,7 +217,9 @@ mod tests {
#[test]
fn request_response() {
let xml = get_xml("response/domain/transfer_request.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let result = object.res_data().unwrap();
@ -235,7 +248,9 @@ mod tests {
#[test]
fn approve_response() {
let xml = get_xml("response/domain/transfer_approve.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());
@ -246,7 +261,9 @@ mod tests {
#[test]
fn reject_response() {
let xml = get_xml("response/domain/transfer_reject.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());
@ -257,7 +274,9 @@ mod tests {
#[test]
fn cancel_response() {
let xml = get_xml("response/domain/transfer_cancel.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());
@ -268,7 +287,9 @@ mod tests {
#[test]
fn query_response() {
let xml = get_xml("response/domain/transfer_query.xml").unwrap();
let object = DomainTransfer::deserialize_response(xml.as_str()).unwrap();
let object =
<DomainTransfer as Transaction<NoExtension>>::deserialize_response(xml.as_str())
.unwrap();
let result = object.res_data().unwrap();

View File

@ -140,7 +140,7 @@ mod tests {
object.info(change_info);
let serialized =
<DomainUpdate as Transaction<NoExtension>>::serialize_request(object, None, CLTRID)
<DomainUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);

View File

@ -110,8 +110,8 @@ mod tests {
});
let serialized = <DomainUpdate as Transaction<Update>>::serialize_request(
object,
Some(consolidate_ext),
&object,
Some(&consolidate_ext),
CLTRID,
)
.unwrap();

View File

@ -2,13 +2,50 @@
use serde::{Deserialize, Serialize};
use crate::common::StringValue;
use crate::domain::check::DomainCheck;
use crate::request::{Extension, Transaction};
use crate::{
common::StringValue,
contact::{
check::ContactCheck, create::ContactCreate, delete::ContactDelete, info::ContactInfo,
update::ContactUpdate,
},
domain::{
check::DomainCheck, create::DomainCreate, delete::DomainDelete, info::DomainInfo,
renew::DomainRenew, transfer::DomainTransfer, update::DomainUpdate,
},
host::{
check::HostCheck, create::HostCreate, delete::HostDelete, info::HostInfo,
update::HostUpdate,
},
request::{Extension, Transaction},
};
pub const XMLNS: &str = "http://www.verisign-grs.com/epp/namestoreExt-1.1";
// Contact
impl Transaction<NameStore> for ContactCheck {}
impl Transaction<NameStore> for ContactCreate {}
impl Transaction<NameStore> for ContactDelete {}
impl Transaction<NameStore> for ContactInfo {}
impl Transaction<NameStore> for ContactUpdate {}
// Domain
impl Transaction<NameStore> for DomainCheck {}
impl Transaction<NameStore> for DomainCreate {}
impl Transaction<NameStore> for DomainDelete {}
impl Transaction<NameStore> for DomainInfo {}
impl Transaction<NameStore> for DomainRenew {}
impl Transaction<NameStore> for DomainTransfer {}
impl Transaction<NameStore> for DomainUpdate {}
// Host
impl Transaction<NameStore> for HostCheck {}
impl Transaction<NameStore> for HostCreate {}
impl Transaction<NameStore> for HostDelete {}
impl Transaction<NameStore> for HostInfo {}
impl Transaction<NameStore> for HostUpdate {}
impl NameStore {
/// Create a new RGP restore report request
@ -60,8 +97,8 @@ mod tests {
let object = DomainCheck::new(vec!["example1.com", "example2.com", "example3.com"]);
let serialized = <DomainCheck as Transaction<NameStore>>::serialize_request(
object,
Some(namestore_ext),
&object,
Some(&namestore_ext),
CLTRID,
)
.unwrap();

View File

@ -144,8 +144,8 @@ mod tests {
let serialized =
<DomainUpdate as Transaction<Update<RgpRestoreReport>>>::serialize_request(
object,
Some(domain_restore_report),
&object,
Some(&domain_restore_report),
CLTRID,
)
.unwrap();

View File

@ -94,8 +94,8 @@ mod tests {
let serialized =
<DomainUpdate as Transaction<Update<RgpRestoreRequest>>>::serialize_request(
object,
Some(domain_restore_request),
&object,
Some(&domain_restore_request),
CLTRID,
)
.unwrap();

View File

@ -90,6 +90,7 @@ pub struct HostCheckResponse {
#[cfg(test)]
mod tests {
use super::HostCheck;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -99,7 +100,9 @@ mod tests {
let object = HostCheck::new(&["ns1.eppdev-1.com", "host1.eppdev-1.com"]);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<HostCheck as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -107,7 +110,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/host/check.xml").unwrap();
let object = HostCheck::deserialize_response(xml.as_str()).unwrap();
let object =
<HostCheck as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();

View File

@ -71,7 +71,7 @@ pub struct HostCreateResponse {
#[cfg(test)]
mod tests {
use super::HostCreate;
use crate::common::HostAddr;
use crate::common::{HostAddr, NoExtension};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -86,7 +86,9 @@ mod tests {
let object = HostCreate::new("host1.eppdev-1.com", addresses);
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<HostCreate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -94,7 +96,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/host/create.xml").unwrap();
let object = HostCreate::deserialize_response(xml.as_str()).unwrap();
let object =
<HostCreate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();

View File

@ -45,6 +45,7 @@ pub struct HostDelete {
#[cfg(test)]
mod tests {
use super::HostDelete;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -54,7 +55,9 @@ mod tests {
let object = HostDelete::new("ns1.eppdev-1.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<HostDelete as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -62,7 +65,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/host/delete.xml").unwrap();
let object = HostDelete::deserialize_response(xml.as_str()).unwrap();
let object =
<HostDelete as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -90,6 +90,7 @@ pub struct HostInfoResponse {
#[cfg(test)]
mod tests {
use super::HostInfo;
use crate::common::NoExtension;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -99,7 +100,9 @@ mod tests {
let object = HostInfo::new("ns1.eppdev-1.com");
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<HostInfo as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -107,7 +110,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/host/info.xml").unwrap();
let object = HostInfo::deserialize_response(xml.as_str()).unwrap();
let object =
<HostInfo as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
let result = object.res_data().unwrap();

View File

@ -91,7 +91,7 @@ pub struct HostUpdate {
#[cfg(test)]
mod tests {
use super::{HostAddRemove, HostChangeInfo, HostUpdate};
use crate::common::{HostAddr, HostStatus};
use crate::common::{HostAddr, HostStatus, NoExtension};
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
@ -121,7 +121,9 @@ mod tests {
name: "host2.eppdev-1.com".into(),
});
let serialized = object.serialize_request(None, CLTRID).unwrap();
let serialized =
<HostUpdate as Transaction<NoExtension>>::serialize_request(&object, None, CLTRID)
.unwrap();
assert_eq!(xml, serialized);
}
@ -129,7 +131,8 @@ mod tests {
#[test]
fn response() {
let xml = get_xml("response/host/update.xml").unwrap();
let object = HostUpdate::deserialize_response(xml.as_str()).unwrap();
let object =
<HostUpdate as Transaction<NoExtension>>::deserialize_response(xml.as_str()).unwrap();
assert_eq!(object.result.code, 1000);
assert_eq!(object.result.message, SUCCESS_MSG.into());

View File

@ -70,7 +70,7 @@
//! };
//!
//! let login = Login::new("username", "password", None);
//! client.transact(login, "transaction-id").await.unwrap();
//! client.transact(&login, "transaction-id").await.unwrap();
//!
//! // Make a domain check call, which returns an object of type EppDomainCheckResponse
//! // that contains the result of the call
@ -78,7 +78,7 @@
//! vec!["eppdev.com", "eppdev.net"],
//! );
//!
//! let response = client.transact(domain_check, "transaction-id").await.unwrap();
//! let response = client.transact(&domain_check, "transaction-id").await.unwrap();
//!
//! // print the availability results
//! response.res_data.unwrap().check_data.domain_list
@ -86,7 +86,7 @@
//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.domain.name, chk.domain.available));
//!
//! // Close the connection
//! client.transact(Logout, "transaction-id").await.unwrap();
//! client.transact(&Logout, "transaction-id").await.unwrap();
//! }
//! ```
//!

View File

@ -15,8 +15,8 @@ pub const EPP_LANG: &str = "en";
/// Trait to set correct value for xml tags when tags are being generated from generic types
pub trait Transaction<Ext: Extension>: Command + Sized {
fn serialize_request(
self,
extension: Option<Ext>,
&self,
extension: Option<&Ext>,
client_tr_id: &str,
) -> Result<String, Box<dyn std::error::Error>> {
<CommandDocument<Self, Ext> as EppXml>::serialize(&CommandDocument::new(CommandWrapper {
@ -54,23 +54,23 @@ pub trait Extension: Serialize + Debug {
#[derive(Debug, PartialEq)]
/// Type corresponding to the &lt;command&gt; tag in an EPP XML request
/// with an &lt;extension&gt; tag
pub struct CommandWrapper<D, E> {
pub struct CommandWrapper<'a, D, E> {
pub command: &'static str,
/// The instance that will be used to populate the &lt;command&gt; tag
pub data: D,
pub data: &'a D,
/// The client TRID
pub extension: Option<E>,
pub extension: Option<&'a E>,
pub client_tr_id: StringValue,
}
impl<D: Serialize, E: Serialize> Serialize for CommandWrapper<D, E> {
impl<'a, D: Serialize, E: Serialize> Serialize for CommandWrapper<'a, D, E> {
/// Serializes the generic type T to the proper XML tag (set by the `#[element_name(name = <tagname>)]` attribute) for the request
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("command", 3)?;
state.serialize_field(self.command, &self.data)?;
state.serialize_field(self.command, self.data)?;
state.serialize_field("extension", &self.extension)?;
state.serialize_field("clTRID", &self.client_tr_id)?;
state.end()
@ -79,13 +79,13 @@ impl<D: Serialize, E: Serialize> Serialize for CommandWrapper<D, E> {
#[derive(Debug, PartialEq, Serialize)]
#[serde(rename = "epp")]
pub struct CommandDocument<D, E> {
pub struct CommandDocument<'a, D, E> {
xmlns: &'static str,
command: CommandWrapper<D, E>,
command: CommandWrapper<'a, D, E>,
}
impl<D, E> CommandDocument<D, E> {
pub fn new(command: CommandWrapper<D, E>) -> Self {
impl<'a, D, E> CommandDocument<'a, D, E> {
pub fn new(command: CommandWrapper<'a, D, E>) -> Self {
Self {
xmlns: EPP_XMLNS,
command,
@ -93,4 +93,4 @@ impl<D, E> CommandDocument<D, E> {
}
}
impl<D: Serialize, E: Serialize> EppXml for CommandDocument<D, E> {}
impl<'a, D: Serialize, E: Serialize> EppXml for CommandDocument<'a, D, E> {}