basic epp serialization/deserialization added
This commit is contained in:
parent
85ae3d601c
commit
89ed02c4d4
|
@ -11,7 +11,6 @@ path = "examples/client.rs"
|
|||
|
||||
[dependencies]
|
||||
bytes = "1"
|
||||
chrono = "0.4"
|
||||
confy = "0.4"
|
||||
futures = "0.3"
|
||||
lazy_static = "1.4"
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ pub struct EppObject<T> {
|
|||
#[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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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>(T);
|
||||
|
||||
pub type EppResponse = EppObject<ResponseType>;
|
||||
pub type EppGreeting = EppObject<ResponseType<Greeting>>;
|
||||
pub type EppCommandResponse = EppObject<ResponseType<CommandResponse>>;
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue