mirror of
https://github.com/instant-labs/instant-epp.git
synced 2025-01-20 16:49:05 +00:00
Refactor domain check models
This commit is contained in:
parent
458f39a6ed
commit
c082a5e3bf
@ -7,7 +7,7 @@
|
|||||||
//!
|
//!
|
||||||
//! use epp_client::config::{EppClientConfig, EppClientConnection};
|
//! use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
//! use epp_client::EppClient;
|
//! use epp_client::EppClient;
|
||||||
//! use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse};
|
//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse};
|
||||||
//! use epp_client::epp::generate_client_tr_id;
|
//! use epp_client::epp::generate_client_tr_id;
|
||||||
//!
|
//!
|
||||||
//! #[tokio::main]
|
//! #[tokio::main]
|
||||||
|
1
epp-client/src/domain.rs
Normal file
1
epp-client/src/domain.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod check;
|
@ -4,6 +4,7 @@ use epp_client_macros::*;
|
|||||||
|
|
||||||
use crate::epp::object::{ElementName, EppObject, StringValue};
|
use crate::epp::object::{ElementName, EppObject, StringValue};
|
||||||
use crate::epp::request::Command;
|
use crate::epp::request::Command;
|
||||||
|
use crate::epp::response::CommandResponse;
|
||||||
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
use crate::epp::xml::EPP_DOMAIN_XMLNS;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
///
|
///
|
||||||
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
/// use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
/// use epp_client::EppClient;
|
/// use epp_client::EppClient;
|
||||||
/// use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse};
|
/// use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse};
|
||||||
/// use epp_client::epp::generate_client_tr_id;
|
/// use epp_client::epp::generate_client_tr_id;
|
||||||
///
|
///
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
@ -56,7 +57,31 @@ use serde::{Deserialize, Serialize};
|
|||||||
/// client.logout().await.unwrap();
|
/// client.logout().await.unwrap();
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub type EppDomainCheck = EppObject<Command<DomainCheck>>;
|
pub type EppDomainCheck = EppObject<Command<DomainCheckRequest>>;
|
||||||
|
|
||||||
|
impl EppDomainCheck {
|
||||||
|
/// Creates a new EppObject for domain check corresponding to the <epp> tag in EPP XML
|
||||||
|
pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck {
|
||||||
|
let domains = domains.into_iter().map(|d| d.into()).collect();
|
||||||
|
|
||||||
|
let domain_check = DomainCheckRequest {
|
||||||
|
list: DomainList {
|
||||||
|
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
||||||
|
domains,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
EppObject::build(Command::<DomainCheckRequest>::new(
|
||||||
|
domain_check,
|
||||||
|
client_tr_id,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <epp> tag for the EPP XML domain check response
|
||||||
|
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResponse>>;
|
||||||
|
|
||||||
|
// Request
|
||||||
|
|
||||||
/// Type for <name> elements under the domain <check> tag
|
/// Type for <name> elements under the domain <check> tag
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@ -72,24 +97,50 @@ pub struct DomainList {
|
|||||||
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
#[derive(Serialize, Deserialize, Debug, ElementName)]
|
||||||
#[element_name(name = "check")]
|
#[element_name(name = "check")]
|
||||||
/// Type for EPP XML <check> command for domains
|
/// Type for EPP XML <check> command for domains
|
||||||
pub struct DomainCheck {
|
pub struct DomainCheckRequest {
|
||||||
/// The object holding the list of domains to be checked
|
/// The object holding the list of domains to be checked
|
||||||
#[serde(rename = "domain:check", alias = "check")]
|
#[serde(rename = "domain:check", alias = "check")]
|
||||||
list: DomainList,
|
list: DomainList,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EppDomainCheck {
|
// Response
|
||||||
/// Creates a new EppObject for domain check corresponding to the <epp> tag in EPP XML
|
|
||||||
pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck {
|
|
||||||
let domains = domains.into_iter().map(|d| d.into()).collect();
|
|
||||||
|
|
||||||
let domain_check = DomainCheck {
|
/// Type that represents the <name> tag for domain check response
|
||||||
list: DomainList {
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
xmlns: EPP_DOMAIN_XMLNS.to_string(),
|
pub struct DomainAvailable {
|
||||||
domains,
|
/// The domain name
|
||||||
},
|
#[serde(rename = "$value")]
|
||||||
};
|
pub name: StringValue,
|
||||||
|
/// The domain (un)availability
|
||||||
EppObject::build(Command::<DomainCheck>::new(domain_check, client_tr_id))
|
#[serde(rename = "avail")]
|
||||||
}
|
pub available: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <cd> tag for domain check response
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct DomainCheckResponseDataItem {
|
||||||
|
/// Data under the <name> tag
|
||||||
|
#[serde(rename = "name")]
|
||||||
|
pub domain: DomainAvailable,
|
||||||
|
/// The reason for (un)availability
|
||||||
|
pub reason: Option<StringValue>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <chkData> tag for domain check response
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct DomainCheckResponseData {
|
||||||
|
/// XML namespace for domain response data
|
||||||
|
#[serde(rename = "xmlns:domain")]
|
||||||
|
xmlns: String,
|
||||||
|
/// Data under the <cd> tag
|
||||||
|
#[serde(rename = "cd")]
|
||||||
|
pub domain_list: Vec<DomainCheckResponseDataItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type that represents the <resData> tag for domain check response
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct DomainCheckResponse {
|
||||||
|
/// Data under the <chkData> tag
|
||||||
|
#[serde(rename = "chkData")]
|
||||||
|
pub check_data: DomainCheckResponseData,
|
||||||
}
|
}
|
@ -10,7 +10,6 @@ pub use request::contact::create::*;
|
|||||||
pub use request::contact::delete::*;
|
pub use request::contact::delete::*;
|
||||||
pub use request::contact::info::*;
|
pub use request::contact::info::*;
|
||||||
pub use request::contact::update::*;
|
pub use request::contact::update::*;
|
||||||
pub use request::domain::check::*;
|
|
||||||
pub use request::domain::create::*;
|
pub use request::domain::create::*;
|
||||||
pub use request::domain::delete::*;
|
pub use request::domain::delete::*;
|
||||||
pub use request::domain::info::*;
|
pub use request::domain::info::*;
|
||||||
@ -32,7 +31,6 @@ pub use response::contact::create::*;
|
|||||||
pub use response::contact::delete::*;
|
pub use response::contact::delete::*;
|
||||||
pub use response::contact::info::*;
|
pub use response::contact::info::*;
|
||||||
pub use response::contact::update::*;
|
pub use response::contact::update::*;
|
||||||
pub use response::domain::check::*;
|
|
||||||
pub use response::domain::create::*;
|
pub use response::domain::create::*;
|
||||||
pub use response::domain::delete::*;
|
pub use response::domain::delete::*;
|
||||||
pub use response::domain::info::*;
|
pub use response::domain::info::*;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
//! Types for EPP domain requests
|
//! Types for EPP domain requests
|
||||||
|
|
||||||
pub mod check;
|
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
pub mod info;
|
pub mod info;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
//! Types for EPP domain responses
|
//! Types for EPP domain responses
|
||||||
|
|
||||||
pub mod check;
|
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
pub mod info;
|
pub mod info;
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
//! Types for EPP domain 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 domain check response
|
|
||||||
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResult>>;
|
|
||||||
|
|
||||||
/// Type that represents the <name> tag for domain check response
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct DomainCheck {
|
|
||||||
/// The domain name
|
|
||||||
#[serde(rename = "$value")]
|
|
||||||
pub name: StringValue,
|
|
||||||
/// The domain (un)availability
|
|
||||||
#[serde(rename = "avail")]
|
|
||||||
pub available: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <cd> tag for domain check response
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct DomainCheckDataItem {
|
|
||||||
/// Data under the <name> tag
|
|
||||||
#[serde(rename = "name")]
|
|
||||||
pub domain: DomainCheck,
|
|
||||||
/// The reason for (un)availability
|
|
||||||
pub reason: Option<StringValue>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <chkData> tag for domain check response
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct DomainCheckData {
|
|
||||||
/// XML namespace for domain response data
|
|
||||||
#[serde(rename = "xmlns:domain")]
|
|
||||||
xmlns: String,
|
|
||||||
/// Data under the <cd> tag
|
|
||||||
#[serde(rename = "cd")]
|
|
||||||
pub domain_list: Vec<DomainCheckDataItem>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Type that represents the <resData> tag for domain check response
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct DomainCheckResult {
|
|
||||||
/// Data under the <chkData> tag
|
|
||||||
#[serde(rename = "chkData")]
|
|
||||||
pub check_data: DomainCheckData,
|
|
||||||
}
|
|
@ -43,7 +43,7 @@
|
|||||||
//!
|
//!
|
||||||
//! use epp_client::config::{EppClientConfig, EppClientConnection};
|
//! use epp_client::config::{EppClientConfig, EppClientConnection};
|
||||||
//! use epp_client::EppClient;
|
//! use epp_client::EppClient;
|
||||||
//! use epp_client::epp::{EppDomainCheck, EppDomainCheckResponse};
|
//! use epp_client::domain::check::{EppDomainCheck, EppDomainCheckResponse};
|
||||||
//! use epp_client::epp::generate_client_tr_id;
|
//! use epp_client::epp::generate_client_tr_id;
|
||||||
//!
|
//!
|
||||||
//! #[tokio::main]
|
//! #[tokio::main]
|
||||||
@ -102,6 +102,7 @@ extern crate log;
|
|||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod connection;
|
pub mod connection;
|
||||||
|
pub mod domain;
|
||||||
pub mod epp;
|
pub mod epp;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub use connection::client::EppClient;
|
pub use connection::client::EppClient;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
mod response {
|
mod response {
|
||||||
use super::super::get_xml;
|
use super::super::get_xml;
|
||||||
use super::super::CLTRID;
|
use super::super::CLTRID;
|
||||||
|
use crate::domain::check::EppDomainCheckResponse;
|
||||||
use crate::epp::response::ExpiryType;
|
use crate::epp::response::ExpiryType;
|
||||||
use crate::epp::response::Relative;
|
use crate::epp::response::Relative;
|
||||||
use crate::epp::response::{
|
use crate::epp::response::{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
mod request {
|
mod request {
|
||||||
use super::super::get_xml;
|
use super::super::get_xml;
|
||||||
use super::super::CLTRID;
|
use super::super::CLTRID;
|
||||||
|
use crate::domain::check::EppDomainCheck;
|
||||||
use crate::epp::object::data::{
|
use crate::epp::object::data::{
|
||||||
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
|
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
|
||||||
HostStatus, Phone, PostalInfo,
|
HostStatus, Phone, PostalInfo,
|
||||||
|
Loading…
Reference in New Issue
Block a user