Refactor domain info models

This commit is contained in:
Nick Rempel 2021-11-25 22:02:08 -08:00 committed by masalachai
parent e5f5ba0695
commit 41cafe5acc
8 changed files with 105 additions and 107 deletions

View File

@ -1,3 +1,4 @@
pub mod check;
pub mod create;
pub mod delete;
pub mod info;

View File

@ -2,9 +2,12 @@
use epp_client_macros::*;
use crate::epp::object::{ElementName, EppObject};
use crate::epp::object::data::{DomainAuthInfo, DomainContact, DomainStatus, HostAttr};
use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command;
use crate::epp::response::CommandResponseWithExtension;
use crate::epp::xml::EPP_DOMAIN_XMLNS;
use crate::epp::RgpRequestResult;
use serde::{Deserialize, Serialize};
/// Type that represents the <epp> request for domain <info> command
@ -16,7 +19,7 @@ use serde::{Deserialize, Serialize};
///
/// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainInfo, EppDomainInfoResponse};
/// use epp_client::domain::info::{EppDomainInfo, EppDomainInfoResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
@ -53,7 +56,31 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppDomainInfo = EppObject<Command<DomainInfo>>;
pub type EppDomainInfo = EppObject<Command<DomainInfoRequest>>;
impl EppDomainInfo {
/// Creates a new EppObject for domain info corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(name: &str, client_tr_id: &str) -> EppDomainInfo {
EppObject::build(Command::<DomainInfoRequest>::new(
DomainInfoRequest {
info: DomainInfoRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
domain: Domain {
hosts: "all".to_string(),
name: name.to_string(),
},
},
},
client_tr_id,
))
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain info response
pub type EppDomainInfoResponse =
EppObject<CommandResponseWithExtension<DomainInfoResponse, RgpRequestResult>>;
// Request
/// Type for data under the &lt;name&gt; element tag for the domain &lt;info&gt; tag
#[derive(Serialize, Deserialize, Debug)]
@ -67,7 +94,7 @@ pub struct Domain {
/// Type for &lt;name&gt; element under the domain &lt;info&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainInfoData {
pub struct DomainInfoRequestData {
/// XML namespace for domain commands
#[serde(rename = "xmlns:domain", alias = "xmlns")]
xmlns: String,
@ -79,26 +106,79 @@ pub struct DomainInfoData {
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "info")]
/// Type for EPP XML &lt;info&gt; command for domains
pub struct DomainInfo {
pub struct DomainInfoRequest {
/// The data under the &lt;info&gt; tag for domain info
#[serde(rename = "domain:info", alias = "info")]
info: DomainInfoData,
info: DomainInfoRequestData,
}
impl EppDomainInfo {
/// Creates a new EppObject for domain info corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(name: &str, client_tr_id: &str) -> EppDomainInfo {
EppObject::build(Command::<DomainInfo>::new(
DomainInfo {
info: DomainInfoData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
domain: Domain {
hosts: "all".to_string(),
name: name.to_string(),
},
},
},
client_tr_id,
))
}
// Response
/// The two types of ns lists, hostObj and hostAttr, that may be returned in the
/// domain info response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainNsList {
/// List of &lt;hostObj&gt; ns elements
#[serde(rename = "hostObj")]
pub host_obj: Option<Vec<StringValue>>,
/// List of &lt;hostAttr&gt; ns elements
pub host_attr: Option<Vec<HostAttr>>,
}
/// Type that represents the &lt;infData&gt; tag for domain info response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainInfoResponseData {
/// XML namespace for domain response data
#[serde(rename = "xmlns:domain")]
xmlns: String,
/// The domain name
pub name: StringValue,
/// The domain ROID
pub roid: StringValue,
/// The list of domain statuses
#[serde(rename = "status")]
pub statuses: Vec<DomainStatus>,
/// The domain registrant
pub registrant: StringValue,
/// The list of domain contacts
#[serde(rename = "contact")]
pub contacts: Vec<DomainContact>,
/// The list of domain nameservers
#[serde(rename = "ns")]
pub ns: Option<DomainNsList>,
/// The list of domain hosts
#[serde(rename = "host")]
pub hosts: Option<Vec<StringValue>>,
/// The epp user who owns the domain
#[serde(rename = "clID")]
pub client_id: StringValue,
/// The epp user who created the domain
#[serde(rename = "crID")]
pub creator_id: StringValue,
/// The domain creation date
#[serde(rename = "crDate")]
pub created_at: StringValue,
/// The epp user who last updated the domain
#[serde(rename = "upID")]
pub updater_id: StringValue,
/// The domain last updated date
#[serde(rename = "upDate")]
pub updated_at: StringValue,
/// The domain expiry date
#[serde(rename = "exDate")]
pub expiring_at: StringValue,
/// The domain transfer date
#[serde(rename = "trDate")]
pub transferred_at: Option<StringValue>,
/// The domain auth info
#[serde(rename = "authInfo")]
pub auth_info: Option<DomainAuthInfo>,
}
/// Type that represents the &lt;resData&gt; tag for domain info response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainInfoResponse {
/// Data under the &lt;resData&gt; tag
#[serde(rename = "infData")]
pub info_data: DomainInfoResponseData,
}

View File

@ -10,7 +10,6 @@ pub use request::contact::create::*;
pub use request::contact::delete::*;
pub use request::contact::info::*;
pub use request::contact::update::*;
pub use request::domain::info::*;
pub use request::domain::renew::*;
pub use request::domain::rgp::report::*;
pub use request::domain::rgp::request::*;
@ -29,7 +28,6 @@ pub use response::contact::create::*;
pub use response::contact::delete::*;
pub use response::contact::info::*;
pub use response::contact::update::*;
pub use response::domain::info::*;
pub use response::domain::renew::*;
pub use response::domain::rgp::report::*;
pub use response::domain::rgp::request::*;

View File

@ -1,6 +1,5 @@
//! Types for EPP domain requests
pub mod info;
pub mod renew;
pub mod rgp;
pub mod transfer;

View File

@ -1,6 +1,5 @@
//! Types for EPP domain responses
pub mod info;
pub mod renew;
pub mod rgp;
pub mod transfer;

View File

@ -1,81 +0,0 @@
//! Types for EPP domain info response
use serde::{Deserialize, Serialize};
use crate::epp::object::data::{DomainAuthInfo, DomainContact, DomainStatus, HostAttr};
use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::domain::rgp::request::RgpRequestResult;
use crate::epp::response::CommandResponseWithExtension;
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain info response
pub type EppDomainInfoResponse =
EppObject<CommandResponseWithExtension<DomainInfoResult, RgpRequestResult>>;
/// The two types of ns lists, hostObj and hostAttr, that may be returned in the
/// domain info response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainNsList {
/// List of &lt;hostObj&gt; ns elements
#[serde(rename = "hostObj")]
pub host_obj: Option<Vec<StringValue>>,
/// List of &lt;hostAttr&gt; ns elements
pub host_attr: Option<Vec<HostAttr>>,
}
/// Type that represents the &lt;infData&gt; tag for domain info response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainInfoData {
/// XML namespace for domain response data
#[serde(rename = "xmlns:domain")]
xmlns: String,
/// The domain name
pub name: StringValue,
/// The domain ROID
pub roid: StringValue,
/// The list of domain statuses
#[serde(rename = "status")]
pub statuses: Vec<DomainStatus>,
/// The domain registrant
pub registrant: StringValue,
/// The list of domain contacts
#[serde(rename = "contact")]
pub contacts: Vec<DomainContact>,
/// The list of domain nameservers
#[serde(rename = "ns")]
pub ns: Option<DomainNsList>,
/// The list of domain hosts
#[serde(rename = "host")]
pub hosts: Option<Vec<StringValue>>,
/// The epp user who owns the domain
#[serde(rename = "clID")]
pub client_id: StringValue,
/// The epp user who created the domain
#[serde(rename = "crID")]
pub creator_id: StringValue,
/// The domain creation date
#[serde(rename = "crDate")]
pub created_at: StringValue,
/// The epp user who last updated the domain
#[serde(rename = "upID")]
pub updater_id: StringValue,
/// The domain last updated date
#[serde(rename = "upDate")]
pub updated_at: StringValue,
/// The domain expiry date
#[serde(rename = "exDate")]
pub expiring_at: StringValue,
/// The domain transfer date
#[serde(rename = "trDate")]
pub transferred_at: Option<StringValue>,
/// The domain auth info
#[serde(rename = "authInfo")]
pub auth_info: Option<DomainAuthInfo>,
}
/// Type that represents the &lt;resData&gt; tag for domain info response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainInfoResult {
/// Data under the &lt;resData&gt; tag
#[serde(rename = "infData")]
pub info_data: DomainInfoData,
}

View File

@ -6,6 +6,7 @@ mod response {
use crate::domain::check::EppDomainCheckResponse;
use crate::domain::create::EppDomainCreateResponse;
use crate::domain::delete::EppDomainDeleteResponse;
use crate::domain::info::EppDomainInfoResponse;
use crate::epp::response::ExpiryType;
use crate::epp::response::Relative;
use crate::epp::response::{

View File

@ -6,6 +6,7 @@ mod request {
use crate::domain::check::EppDomainCheck;
use crate::domain::create::EppDomainCreate;
use crate::domain::delete::EppDomainDelete;
use crate::domain::info::EppDomainInfo;
use crate::epp::object::data::{
Address, ContactStatus, DomainAuthInfo, DomainContact, DomainStatus, HostAddr, HostAttr,
HostStatus, Phone, PostalInfo,