Deduplicate DomainTransfer constructor methods

This commit is contained in:
Dirkjan Ochtman 2021-12-14 10:31:48 +01:00 committed by masalachai
parent a5f57fa836
commit 1efe19000e

View File

@ -14,61 +14,48 @@ impl Command for DomainTransfer {
impl DomainTransfer { impl DomainTransfer {
pub fn new(name: &str, years: Option<u16>, auth_password: &str) -> Self { pub fn new(name: &str, years: Option<u16>, auth_password: &str) -> Self {
Self { Self::build(
operation: "request".to_string(), "request",
domain: DomainTransferReqData { name,
xmlns: XMLNS, years.map(Period::new),
name: name.into(), Some(DomainAuthInfo::new(auth_password)),
period: years.map(Period::new), )
auth_info: Some(DomainAuthInfo::new(auth_password)),
},
}
} }
pub fn query(name: &str, auth_password: &str) -> Self { pub fn query(name: &str, auth_password: &str) -> Self {
Self { Self::build(
operation: "query".to_string(), "query",
domain: DomainTransferReqData { name,
xmlns: XMLNS, None,
name: name.into(), Some(DomainAuthInfo::new(auth_password)),
period: None, )
auth_info: Some(DomainAuthInfo::new(auth_password)),
},
}
} }
pub fn approve(name: &str) -> Self { pub fn approve(name: &str) -> Self {
Self { Self::build("approve", name, None, None)
operation: "approve".to_string(),
domain: DomainTransferReqData {
xmlns: XMLNS,
name: name.into(),
period: None,
auth_info: None,
},
}
} }
pub fn reject(name: &str) -> Self { pub fn reject(name: &str) -> Self {
Self { Self::build("reject", name, None, None)
operation: "reject".to_string(),
domain: DomainTransferReqData {
xmlns: XMLNS,
name: name.into(),
period: None,
auth_info: None,
},
}
} }
pub fn cancel(name: &str) -> Self { pub fn cancel(name: &str) -> Self {
Self::build("cancel", name, None, None)
}
fn build(
operation: &str,
name: &str,
period: Option<Period>,
auth_info: Option<DomainAuthInfo>,
) -> Self {
Self { Self {
operation: "cancel".to_string(), operation: operation.to_string(),
domain: DomainTransferReqData { domain: DomainTransferReqData {
xmlns: XMLNS, xmlns: XMLNS,
name: name.into(), name: name.into(),
period: None, period,
auth_info: None, auth_info,
}, },
} }
} }