diff --git a/epp-client/examples/client.rs b/epp-client/examples/client.rs index d37214f..29d804e 100644 --- a/epp-client/examples/client.rs +++ b/epp-client/examples/client.rs @@ -1,11 +1,11 @@ use epp_client::{epp::request::generate_client_tr_id, connection::client::EppClient, connection, epp::xml::EppXml}; -use epp_client::epp::response::EppGreeting; use epp_client::epp::request::domain::check::EppDomainCheck; use epp_client::epp::response::domain::check::EppDomainCheckResponse; use epp_client::epp::request::contact::check::EppContactCheck; use epp_client::epp::response::contact::check::EppContactCheckResponse; use epp_client::epp::object::data::{PostalInfo, Address, Phone}; use epp_client::epp::request::contact::create::EppContactCreate; +use epp_client::epp::response::contact::create::EppContactCreateResponse; async fn check_domains(client: &mut EppClient) { let domains = vec!["eppdev.com", "hexonet.net"]; @@ -21,7 +21,7 @@ async fn check_contacts(client: &mut EppClient) { client.transact::<_, EppContactCheckResponse>(&contact_check).await.unwrap(); } -async fn create_contact() { +async fn create_contact(client: &mut EppClient) { let street = vec!["58", "Orchid Road"]; let address = Address::new(street, "Paris", "Paris", "392374", "FR"); let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address); @@ -33,9 +33,9 @@ async fn create_contact() { let mut contact_create = EppContactCreate::new("eppdev-contact-1", "contact@eppdev.net", postal_info, voice, "eppdev-387323", generate_client_tr_id("eppdev").unwrap().as_str()); contact_create.set_fax(fax); - println!("xml: {}", contact_create.serialize().unwrap()); + // println!("xml: {}", contact_create.serialize().unwrap()); - //client.transact::(&contact_check).await.unwrap(); + client.transact::<_, EppContactCreateResponse>(&contact_create).await.unwrap(); } async fn hello(client: &mut EppClient) { @@ -48,9 +48,7 @@ async fn hello(client: &mut EppClient) { async fn main() { let mut client = match EppClient::new("hexonet").await { Ok(client) => { - let greeting = client.xml_greeting(); - let greeting_object = EppGreeting::deserialize(&greeting).unwrap(); - println!("{:?}", greeting_object); + println!("{:?}", client.greeting()); client }, Err(e) => panic!("Error: {}", e) @@ -58,9 +56,9 @@ async fn main() { // hello(&mut client).await; - check_domains(&mut client).await; + // check_domains(&mut client).await; // check_contacts(&mut client).await; - // create_contact().await; + create_contact(&mut client).await; } diff --git a/epp-client/src/connection/client.rs b/epp-client/src/connection/client.rs index f31f88e..fec750d 100644 --- a/epp-client/src/connection/client.rs +++ b/epp-client/src/connection/client.rs @@ -66,6 +66,8 @@ impl EppClient { let response = self.connection.transact(&hello_xml).await?; + println!("hello response: {}", response); + Ok(EppGreeting::deserialize(&response)?) } @@ -86,8 +88,7 @@ impl EppClient { Ok(response) } else { let epp_error = EppCommandResponseError::deserialize(&response)?; - let epp_error = error::Error::EppCommandError(error::EppCommandError::new(epp_error)); - Err(epp_error) + Err(error::Error::EppCommandError(epp_error)) } } diff --git a/epp-client/src/epp/object.rs b/epp-client/src/epp/object.rs index 932c5db..36fa103 100644 --- a/epp-client/src/epp/object.rs +++ b/epp-client/src/epp/object.rs @@ -1,7 +1,7 @@ pub mod data; -use std::fmt::Display; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; +use std::fmt::Display; use crate::epp::xml::{EPP_XMLNS, EPP_XMLNS_XSI, EPP_XSI_SCHEMA_LOCATION}; diff --git a/epp-client/src/epp/quick_xml.rs b/epp-client/src/epp/quick_xml.rs index 8ed7aa5..ad59c12 100644 --- a/epp-client/src/epp/quick_xml.rs +++ b/epp-client/src/epp/quick_xml.rs @@ -5,6 +5,7 @@ use std::{error::Error, fmt::Debug}; use crate::epp::object::{ElementName, EppObject}; use crate::epp::xml::{EppXml, EPP_XML_HEADER}; +use crate::error; impl EppXml for EppObject { type Output = EppObject; @@ -15,10 +16,14 @@ impl EppXml for EppObject Ok(epp_xml) } - fn deserialize(epp_xml: &str) -> Result> { + fn deserialize(epp_xml: &str) -> Result { let mut object: Self::Output = match from_str(epp_xml) { Ok(v) => v, - Err(e) => return Err(format!("epp-client Deserialization Error: {}", e).into()), + Err(e) => { + return Err(error::Error::EppDeserializationError( + format!("epp-client Deserialization Error: {}", e).to_string(), + )) + } }; // object.xml = Some(epp_xml.to_string()); Ok(object) diff --git a/epp-client/src/epp/request/domain/check.rs b/epp-client/src/epp/request/domain/check.rs index 309e258..28ea9e7 100644 --- a/epp-client/src/epp/request/domain/check.rs +++ b/epp-client/src/epp/request/domain/check.rs @@ -15,7 +15,7 @@ pub struct DomainList { } #[derive(Serialize, Deserialize, Debug, ElementName)] -#[element_name(name = "checkr")] +#[element_name(name = "check")] pub struct DomainCheck { #[serde(rename = "check")] list: DomainList, diff --git a/epp-client/src/epp/response/contact.rs b/epp-client/src/epp/response/contact.rs index 3e8ff0f..3aa3078 100644 --- a/epp-client/src/epp/response/contact.rs +++ b/epp-client/src/epp/response/contact.rs @@ -1 +1,2 @@ pub mod check; +pub mod create; diff --git a/epp-client/src/epp/response/contact/create.rs b/epp-client/src/epp/response/contact/create.rs new file mode 100644 index 0000000..8cbea77 --- /dev/null +++ b/epp-client/src/epp/response/contact/create.rs @@ -0,0 +1,19 @@ +use serde::{Deserialize, Serialize}; + +use crate::epp::object::{EppObject, StringValue}; +use crate::epp::response::CommandResponse; + +pub type EppContactCreateResponse = EppObject>; + +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCreateData { + pub id: StringValue, + #[serde(rename = "crDate")] + pub created_at: StringValue, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCreateResult { + #[serde(rename = "creData")] + pub check_data: ContactCreateData, +} diff --git a/epp-client/src/epp/xml.rs b/epp-client/src/epp/xml.rs index a192614..390aeff 100644 --- a/epp-client/src/epp/xml.rs +++ b/epp-client/src/epp/xml.rs @@ -1,6 +1,6 @@ use std::{error::Error, fmt::Debug}; -// use crate::epp::object::EppObject; +use crate::error; pub const EPP_XML_HEADER: &str = r#""#; pub const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0"; @@ -17,5 +17,5 @@ pub trait EppXml { type Output: Debug; fn serialize(&self) -> Result>; - fn deserialize(epp_xml: &str) -> Result>; + fn deserialize(epp_xml: &str) -> Result; } diff --git a/epp-client/src/error.rs b/epp-client/src/error.rs index 8f24aae..5332e1c 100644 --- a/epp-client/src/error.rs +++ b/epp-client/src/error.rs @@ -4,7 +4,8 @@ use std::fmt::Display; #[derive(Debug)] pub enum Error { EppConnectionError(std::io::Error), - EppCommandError(EppCommandError), + EppCommandError(EppCommandResponseError), + EppDeserializationError(String), Other(String), } @@ -15,35 +16,21 @@ pub struct EppCommandError { impl std::error::Error for Error {} -impl std::error::Error for EppCommandError {} - -impl Display for EppCommandError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "epp-client EppCommandError: {}", - self.epp_error.data.result.message - ) - } -} - -impl EppCommandError { - pub fn new(epp_error: EppCommandResponseError) -> EppCommandError { - EppCommandError { - epp_error: epp_error, - } - } -} - impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "epp-client Exception: {:?}", self) + match self { + Error::EppCommandError(e) => { + write!(f, "epp-client EppCommandError: {}", e.data.result.message) + } + Error::Other(e) => write!(f, "epp-client Exception: {}", e), + _ => write!(f, "epp-client Exception: {:?}", self), + } } } impl From> for Error { fn from(e: std::boxed::Box) -> Self { - Self::Other(format!("{}", e).to_string()) + Self::Other(format!("{:?}", e).to_string()) } }