Refactor domain renew models
This commit is contained in:
parent
41cafe5acc
commit
8fe9e8bbeb
|
@ -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;
|
||||||
|
|
|
@ -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 <epp> 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 <epp> tag for the EPP XML domain renew response
|
||||||
|
pub type EppDomainRenewResponse = EppObject<CommandResponse<DomainRenewResponse>>;
|
||||||
|
|
||||||
|
// Request
|
||||||
|
|
||||||
/// Type for data under the domain <renew> tag
|
/// Type for data under the domain <renew> 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 <renew> command for domains
|
/// Type for EPP XML <renew> command for domains
|
||||||
pub struct DomainRenew {
|
pub struct DomainRenewRequest {
|
||||||
/// The data under the <renew> tag for the domain renewal
|
/// The data under the <renew> 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 <epp> 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 <renData> 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 <resData> tag for domain renew response
|
||||||
self.data.command.domain.period = period;
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
}
|
pub struct DomainRenewResponse {
|
||||||
|
/// Data under the <renData> tag
|
||||||
|
#[serde(rename = "renData")]
|
||||||
|
pub renew_data: DomainRenewResponseData,
|
||||||
}
|
}
|
|
@ -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::*;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 <epp> tag for the EPP XML domain renew response
|
|
||||||
pub type EppDomainRenewResponse = EppObject<CommandResponse<DomainRenewResult>>;
|
|
||||||
|
|
||||||
/// Type that represents the <renData> 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 <resData> tag for domain renew response
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct DomainRenewResult {
|
|
||||||
/// Data under the <renData> tag
|
|
||||||
#[serde(rename = "renData")]
|
|
||||||
pub renew_data: DomainRenewData,
|
|
||||||
}
|
|
|
@ -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::{
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue