basic epp serialization/deserialization added
This commit is contained in:
parent
85ae3d601c
commit
89ed02c4d4
|
@ -11,7 +11,6 @@ path = "examples/client.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
chrono = "0.4"
|
|
||||||
confy = "0.4"
|
confy = "0.4"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
lazy_static = "1.4"
|
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]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let mut client = match connection::connect("hexonet").await {
|
let mut client = match connection::connect("hexonet").await {
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
let greeting = client.greeting();
|
let greeting = client.greeting();
|
||||||
let greeting_object = EppResponse::deserialize(&greeting).unwrap();
|
let greeting_object = EppGreeting::deserialize(&greeting).unwrap();
|
||||||
println!("{:?}", greeting_object);
|
println!("{:?}", greeting_object);
|
||||||
client
|
client
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,6 +11,7 @@ use tokio::{net::TcpStream, io::AsyncWriteExt, io::AsyncReadExt, io::split, io::
|
||||||
use crate::config::{CONFIG, EppClientConnection};
|
use crate::config::{CONFIG, EppClientConnection};
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use crate::epp::request::{EppRequest, Login, Logout};
|
use crate::epp::request::{EppRequest, Login, Logout};
|
||||||
|
use crate::epp::response::EppCommandResponse;
|
||||||
use crate::epp::xml::EppXml;
|
use crate::epp::xml::EppXml;
|
||||||
|
|
||||||
pub struct ConnectionStream {
|
pub struct ConnectionStream {
|
||||||
|
@ -156,8 +157,13 @@ impl EppClient {
|
||||||
println!("Request:\r\n{}", epp_xml);
|
println!("Request:\r\n{}", epp_xml);
|
||||||
|
|
||||||
let response = self.connection.transact(&epp_xml).await?;
|
let response = self.connection.transact(&epp_xml).await?;
|
||||||
|
|
||||||
println!("Response:\r\n{}", response);
|
println!("Response:\r\n{}", response);
|
||||||
|
|
||||||
|
let response_obj = EppCommandResponse::deserialize(&response).unwrap();
|
||||||
|
|
||||||
|
println!("Response:\r\n{:?}", response_obj);
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ pub struct EppObject<T> {
|
||||||
#[serde(rename = "xmlns:xsi")]
|
#[serde(rename = "xmlns:xsi")]
|
||||||
pub xmlns_xsi: String,
|
pub xmlns_xsi: String,
|
||||||
#[serde(rename = "xsi:schemaLocation")]
|
#[serde(rename = "xsi:schemaLocation")]
|
||||||
pub xsi_schema_location: String,
|
pub xsi_schema_location: String,
|
||||||
#[serde(alias = "greeting")]
|
#[serde(alias = "greeting", alias = "response")]
|
||||||
pub data: T,
|
pub data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// use chrono::{DateTime, Utc};
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::error::Error;
|
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)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum ResponseType {
|
pub struct ResponseType<T>(T);
|
||||||
#[serde(rename = "greeting")]
|
|
||||||
Greeting(Greeting),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type EppResponse = EppObject<ResponseType>;
|
pub type EppGreeting = EppObject<ResponseType<Greeting>>;
|
||||||
|
pub type EppCommandResponse = EppObject<ResponseType<CommandResponse>>;
|
||||||
|
|
||||||
#[derive(Serialize, Debug, PartialEq)]
|
#[derive(Serialize, Debug, PartialEq)]
|
||||||
pub struct ServiceMenu {
|
pub struct ServiceMenu {
|
||||||
|
@ -116,3 +113,26 @@ pub struct Greeting {
|
||||||
svc_menu: ServiceMenu,
|
svc_menu: ServiceMenu,
|
||||||
dcp: Dcp,
|
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