Refactor contact check models
This commit is contained in:
parent
dc90f91b8f
commit
964f3a7376
|
@ -0,0 +1 @@
|
|||
pub mod check;
|
|
@ -3,6 +3,7 @@ use epp_client_macros::*;
|
|||
|
||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
||||
use crate::epp::request::Command;
|
||||
use crate::epp::response::CommandResponse;
|
||||
use crate::epp::xml::EPP_CONTACT_XMLNS;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize};
|
|||
///
|
||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||
/// use epp_client::EppClient;
|
||||
/// use epp_client::epp::{EppContactCheck, EppContactCheckResponse};
|
||||
/// use epp_client::contact::check::{EppContactCheck, EppContactCheckResponse};
|
||||
/// use epp_client::epp::generate_client_tr_id;
|
||||
///
|
||||
/// #[tokio::main]
|
||||
|
@ -55,7 +56,34 @@ use serde::{Deserialize, Serialize};
|
|||
/// client.logout().await.unwrap();
|
||||
/// }
|
||||
/// ```
|
||||
pub type EppContactCheck = EppObject<Command<ContactCheck>>;
|
||||
pub type EppContactCheck = EppObject<Command<ContactCheckRequest>>;
|
||||
|
||||
impl EppContactCheck {
|
||||
/// Creates an EppObject corresponding to the <epp> tag with data for a contact check request
|
||||
pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck {
|
||||
let contact_ids = contact_ids
|
||||
.iter()
|
||||
.map(|&d| d.into())
|
||||
.collect::<Vec<StringValue>>();
|
||||
|
||||
let contact_check = ContactCheckRequest {
|
||||
list: ContactList {
|
||||
xmlns: EPP_CONTACT_XMLNS.to_string(),
|
||||
contact_ids,
|
||||
},
|
||||
};
|
||||
|
||||
EppObject::build(Command::<ContactCheckRequest>::new(
|
||||
contact_check,
|
||||
client_tr_id,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that represents the <epp> tag for the EPP XML contact check response
|
||||
pub type EppContactCheckResponse = EppObject<CommandResponse<ContactCheckResponse>>;
|
||||
|
||||
// Request
|
||||
|
||||
/// Type that represents the <check> command for contact transactions
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -71,27 +99,50 @@ pub struct ContactList {
|
|||
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
||||
#[element_name(name = "check")]
|
||||
/// The <command> type for contact check command
|
||||
pub struct ContactCheck {
|
||||
pub struct ContactCheckRequest {
|
||||
/// The <check> tag for the contact check command
|
||||
#[serde(rename = "contact:check", alias = "check")]
|
||||
list: ContactList,
|
||||
}
|
||||
|
||||
impl EppContactCheck {
|
||||
/// Creates an EppObject corresponding to the <epp> tag with data for a contact check request
|
||||
pub fn new(contact_ids: &[&str], client_tr_id: &str) -> EppContactCheck {
|
||||
let contact_ids = contact_ids
|
||||
.iter()
|
||||
.map(|&d| d.into())
|
||||
.collect::<Vec<StringValue>>();
|
||||
// Response
|
||||
|
||||
let contact_check = ContactCheck {
|
||||
list: ContactList {
|
||||
xmlns: EPP_CONTACT_XMLNS.to_string(),
|
||||
contact_ids,
|
||||
},
|
||||
};
|
||||
/// Type that represents the <id> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheck {
|
||||
/// The text of the <id> tag
|
||||
#[serde(rename = "$value")]
|
||||
pub id: StringValue,
|
||||
/// The avail attr on the <id> tag
|
||||
#[serde(rename = "avail")]
|
||||
pub available: u16,
|
||||
}
|
||||
|
||||
EppObject::build(Command::<ContactCheck>::new(contact_check, client_tr_id))
|
||||
/// Type that represents the <cd> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheckResponseDataItem {
|
||||
/// Data under the <id> tag
|
||||
#[serde(rename = "id")]
|
||||
pub contact: ContactCheck,
|
||||
/// The reason for (un)availability
|
||||
pub reason: Option<StringValue>,
|
||||
}
|
||||
|
||||
/// Type that represents the <chkData> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheckResponseData {
|
||||
/// XML namespace for contact response data
|
||||
#[serde(rename = "xmlns:contact")]
|
||||
xmlns: String,
|
||||
/// Data under the <cd> tag
|
||||
#[serde(rename = "cd")]
|
||||
pub contact_list: Vec<ContactCheckResponseDataItem>,
|
||||
}
|
||||
|
||||
/// Type that represents the <resData> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheckResponse {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "chkData")]
|
||||
pub check_data: ContactCheckResponseData,
|
||||
}
|
|
@ -5,7 +5,6 @@ pub mod request;
|
|||
pub mod response;
|
||||
pub mod xml;
|
||||
|
||||
pub use request::contact::check::*;
|
||||
pub use request::contact::create::*;
|
||||
pub use request::contact::delete::*;
|
||||
pub use request::contact::info::*;
|
||||
|
@ -18,7 +17,6 @@ pub use request::host::update::*;
|
|||
pub use request::message::ack::*;
|
||||
pub use request::message::poll::*;
|
||||
|
||||
pub use response::contact::check::*;
|
||||
pub use response::contact::create::*;
|
||||
pub use response::contact::delete::*;
|
||||
pub use response::contact::info::*;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Types for EPP contact requests
|
||||
|
||||
pub mod check;
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod info;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Types for EPP contact responses
|
||||
|
||||
pub mod check;
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod info;
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
//! Types for EPP contact check response
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::epp::object::{EppObject, StringValue};
|
||||
use crate::epp::response::CommandResponse;
|
||||
|
||||
/// Type that represents the <epp> tag for the EPP XML contact check response
|
||||
pub type EppContactCheckResponse = EppObject<CommandResponse<ContactCheckResult>>;
|
||||
|
||||
/// Type that represents the <id> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheck {
|
||||
/// The text of the <id> tag
|
||||
#[serde(rename = "$value")]
|
||||
pub id: StringValue,
|
||||
/// The avail attr on the <id> tag
|
||||
#[serde(rename = "avail")]
|
||||
pub available: u16,
|
||||
}
|
||||
|
||||
/// Type that represents the <cd> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheckDataItem {
|
||||
/// Data under the <id> tag
|
||||
#[serde(rename = "id")]
|
||||
pub contact: ContactCheck,
|
||||
/// The reason for (un)availability
|
||||
pub reason: Option<StringValue>,
|
||||
}
|
||||
|
||||
/// Type that represents the <chkData> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheckData {
|
||||
/// XML namespace for contact response data
|
||||
#[serde(rename = "xmlns:contact")]
|
||||
xmlns: String,
|
||||
/// Data under the <cd> tag
|
||||
#[serde(rename = "cd")]
|
||||
pub contact_list: Vec<ContactCheckDataItem>,
|
||||
}
|
||||
|
||||
/// Type that represents the <resData> tag for contact check response
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ContactCheckResult {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "chkData")]
|
||||
pub check_data: ContactCheckData,
|
||||
}
|
|
@ -102,6 +102,7 @@ extern crate log;
|
|||
|
||||
pub mod config;
|
||||
pub mod connection;
|
||||
pub mod contact;
|
||||
pub mod domain;
|
||||
pub mod epp;
|
||||
pub mod error;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
mod response {
|
||||
use super::super::get_xml;
|
||||
use super::super::CLTRID;
|
||||
use crate::contact::check::EppContactCheckResponse;
|
||||
use crate::domain::check::EppDomainCheckResponse;
|
||||
use crate::domain::create::EppDomainCreateResponse;
|
||||
use crate::domain::delete::EppDomainDeleteResponse;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
mod request {
|
||||
use super::super::get_xml;
|
||||
use super::super::CLTRID;
|
||||
use crate::contact::check::EppContactCheck;
|
||||
use crate::domain::check::EppDomainCheck;
|
||||
use crate::domain::create::EppDomainCreate;
|
||||
use crate::domain::delete::EppDomainDelete;
|
||||
|
|
Loading…
Reference in New Issue