Refactor domain renew models

This commit is contained in:
Nick Rempel 2021-11-25 22:00:29 -08:00 committed by masalachai
parent 41cafe5acc
commit 8fe9e8bbeb
8 changed files with 62 additions and 63 deletions

View File

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

View File

@ -5,6 +5,7 @@ use epp_client_macros::*;
use crate::epp::object::data::Period; use crate::epp::object::data::Period;
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 chrono::NaiveDate; use chrono::NaiveDate;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -20,7 +21,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::{EppDomainRenew, EppDomainRenewResponse}; /// use epp_client::domain::renew::{EppDomainRenew, EppDomainRenewResponse};
/// use epp_client::epp::generate_client_tr_id; /// use epp_client::epp::generate_client_tr_id;
/// ///
/// #[tokio::main] /// #[tokio::main]
@ -60,11 +61,44 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap(); /// client.logout().await.unwrap();
/// } /// }
/// ``` /// ```
pub type EppDomainRenew = EppObject<Command<DomainRenew>>; pub type EppDomainRenew = EppObject<Command<DomainRenewRequest>>;
impl EppDomainRenew {
/// Creates a new EppObject for domain renew corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(
name: &str,
current_expiry_date: NaiveDate,
years: u16,
client_tr_id: &str,
) -> EppDomainRenew {
let exp_date_str = current_expiry_date.format("%Y-%m-%d").to_string().into();
EppObject::build(Command::<DomainRenewRequest>::new(
DomainRenewRequest {
domain: DomainRenewRequestData {
xmlns: EPP_DOMAIN_XMLNS.to_string(),
name: name.into(),
current_expiry_date: exp_date_str,
period: Period::new(years),
},
},
client_tr_id,
))
}
pub fn set_period(&mut self, period: Period) {
self.data.command.domain.period = period;
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain renew response
pub type EppDomainRenewResponse = EppObject<CommandResponse<DomainRenewResponse>>;
// Request
/// Type for data under the domain &lt;renew&gt; tag /// Type for data under the domain &lt;renew&gt; tag
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct DomainRenewData { pub struct DomainRenewRequestData {
/// XML namespace for domain commands /// XML namespace for domain commands
#[serde(rename = "xmlns:domain", alias = "xmlns")] #[serde(rename = "xmlns:domain", alias = "xmlns")]
xmlns: String, xmlns: String,
@ -82,36 +116,31 @@ pub struct DomainRenewData {
#[derive(Serialize, Deserialize, Debug, ElementName)] #[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "renew")] #[element_name(name = "renew")]
/// Type for EPP XML &lt;renew&gt; command for domains /// Type for EPP XML &lt;renew&gt; command for domains
pub struct DomainRenew { pub struct DomainRenewRequest {
/// The data under the &lt;renew&gt; tag for the domain renewal /// The data under the &lt;renew&gt; tag for the domain renewal
#[serde(rename = "domain:renew", alias = "renew")] #[serde(rename = "domain:renew", alias = "renew")]
domain: DomainRenewData, domain: DomainRenewRequestData,
} }
impl EppDomainRenew { // Response
/// Creates a new EppObject for domain renew corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(
name: &str,
current_expiry_date: NaiveDate,
years: u16,
client_tr_id: &str,
) -> EppDomainRenew {
let exp_date_str = current_expiry_date.format("%Y-%m-%d").to_string().into();
EppObject::build(Command::<DomainRenew>::new( /// Type that represents the &lt;renData&gt; tag for domain renew response
DomainRenew { #[derive(Serialize, Deserialize, Debug)]
domain: DomainRenewData { pub struct DomainRenewResponseData {
xmlns: EPP_DOMAIN_XMLNS.to_string(), /// XML namespace for domain response data
name: name.into(), #[serde(rename = "xmlns:domain")]
current_expiry_date: exp_date_str, xmlns: String,
period: Period::new(years), /// The name of the domain
}, pub name: StringValue,
}, /// The new expiry date after renewal
client_tr_id, #[serde(rename = "exDate")]
)) pub expiring_at: StringValue,
} }
pub fn set_period(&mut self, period: Period) { /// Type that represents the &lt;resData&gt; tag for domain renew response
self.data.command.domain.period = period; #[derive(Serialize, Deserialize, Debug)]
} pub struct DomainRenewResponse {
/// Data under the &lt;renData&gt; tag
#[serde(rename = "renData")]
pub renew_data: DomainRenewResponseData,
} }

View File

@ -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::renew::*;
pub use request::domain::rgp::report::*; pub use request::domain::rgp::report::*;
pub use request::domain::rgp::request::*; pub use request::domain::rgp::request::*;
pub use request::domain::transfer::*; pub use request::domain::transfer::*;
@ -28,7 +27,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::renew::*;
pub use response::domain::rgp::report::*; pub use response::domain::rgp::report::*;
pub use response::domain::rgp::request::*; pub use response::domain::rgp::request::*;
pub use response::domain::transfer::*; pub use response::domain::transfer::*;

View File

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

View File

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

View File

@ -1,29 +0,0 @@
//! Types for EPP domain renew response
use serde::{Deserialize, Serialize};
use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::CommandResponse;
/// Type that represents the &lt;epp&gt; tag for the EPP XML domain renew response
pub type EppDomainRenewResponse = EppObject<CommandResponse<DomainRenewResult>>;
/// Type that represents the &lt;renData&gt; tag for domain renew response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainRenewData {
/// XML namespace for domain response data
#[serde(rename = "xmlns:domain")]
xmlns: String,
/// The name of the domain
pub name: StringValue,
/// The new expiry date after renewal
#[serde(rename = "exDate")]
pub expiring_at: StringValue,
}
/// Type that represents the &lt;resData&gt; tag for domain renew response
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainRenewResult {
/// Data under the &lt;renData&gt; tag
#[serde(rename = "renData")]
pub renew_data: DomainRenewData,
}

View File

@ -7,6 +7,7 @@ mod response {
use crate::domain::create::EppDomainCreateResponse; use crate::domain::create::EppDomainCreateResponse;
use crate::domain::delete::EppDomainDeleteResponse; use crate::domain::delete::EppDomainDeleteResponse;
use crate::domain::info::EppDomainInfoResponse; use crate::domain::info::EppDomainInfoResponse;
use crate::domain::renew::EppDomainRenewResponse;
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::{

View File

@ -7,6 +7,7 @@ mod request {
use crate::domain::create::EppDomainCreate; use crate::domain::create::EppDomainCreate;
use crate::domain::delete::EppDomainDelete; use crate::domain::delete::EppDomainDelete;
use crate::domain::info::EppDomainInfo; use crate::domain::info::EppDomainInfo;
use crate::domain::renew::EppDomainRenew;
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,