diff --git a/Cargo.toml b/Cargo.toml index 518afa1..fbdd014 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ path = "examples/client.rs" [dependencies] bytes = "1" -chrono = "0.4" confy = "0.4" futures = "0.3" lazy_static = "1.4" diff --git a/examples/client.rs b/examples/client.rs index e72054e..f778b35 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -1,11 +1,11 @@ -use epp_client::{epp::request, connection, epp::xml::EppXml, epp::response::EppResponse}; +use epp_client::{epp::request, connection, epp::xml::EppXml, epp::response::EppGreeting}; #[tokio::main] async fn main() { let mut client = match connection::connect("hexonet").await { Ok(client) => { let greeting = client.greeting(); - let greeting_object = EppResponse::deserialize(&greeting).unwrap(); + let greeting_object = EppGreeting::deserialize(&greeting).unwrap(); println!("{:?}", greeting_object); client }, diff --git a/src/connection.rs b/src/connection.rs index 4a3ebba..e1d55a9 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -11,6 +11,7 @@ use tokio::{net::TcpStream, io::AsyncWriteExt, io::AsyncReadExt, io::split, io:: use crate::config::{CONFIG, EppClientConnection}; use crate::error; use crate::epp::request::{EppRequest, Login, Logout}; +use crate::epp::response::EppCommandResponse; use crate::epp::xml::EppXml; pub struct ConnectionStream { @@ -156,8 +157,13 @@ impl EppClient { println!("Request:\r\n{}", epp_xml); let response = self.connection.transact(&epp_xml).await?; + println!("Response:\r\n{}", response); + let response_obj = EppCommandResponse::deserialize(&response).unwrap(); + + println!("Response:\r\n{:?}", response_obj); + Ok(response) } diff --git a/src/epp/object.rs b/src/epp/object.rs index ecfee58..58161d8 100644 --- a/src/epp/object.rs +++ b/src/epp/object.rs @@ -28,8 +28,8 @@ pub struct EppObject { #[serde(rename = "xmlns:xsi")] pub xmlns_xsi: String, #[serde(rename = "xsi:schemaLocation")] - pub xsi_schema_location: String, - #[serde(alias = "greeting")] + pub xsi_schema_location: String, + #[serde(alias = "greeting", alias = "response")] pub data: T, } diff --git a/src/epp/response.rs b/src/epp/response.rs index 827563b..85d21fc 100644 --- a/src/epp/response.rs +++ b/src/epp/response.rs @@ -1,4 +1,3 @@ -// use chrono::{DateTime, Utc}; use serde::{Deserialize, Deserializer, Serialize}; use std::error::Error; @@ -7,12 +6,10 @@ use crate::epp::xml::{EPP_XMLNS, EPP_XMLNS_XSI, EPP_XSI_SCHEMA_LOCATION}; #[derive(Serialize, Deserialize, Debug, PartialEq)] #[serde(rename_all = "lowercase")] -pub enum ResponseType { - #[serde(rename = "greeting")] - Greeting(Greeting), -} +pub struct ResponseType(T); -pub type EppResponse = EppObject; +pub type EppGreeting = EppObject>; +pub type EppCommandResponse = EppObject>; #[derive(Serialize, Debug, PartialEq)] pub struct ServiceMenu { @@ -116,3 +113,26 @@ pub struct Greeting { svc_menu: ServiceMenu, dcp: Dcp, } + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct EppResult { + pub code: String, + #[serde(rename = "msg")] + pub message: StringValue, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct ResponseTRID { + #[serde(rename = "clTRID")] + pub client_tr_id: StringValue, + #[serde(rename = "svTRID")] + pub server_tr_id: StringValue, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[serde(rename_all = "lowercase")] +pub struct CommandResponse { + pub result: EppResult, + #[serde(rename = "trID")] + pub tr_ids: ResponseTRID, +}