netcup_client/actions/
dnszone.rs1use serde::Serialize;
2
3use crate::prelude::DnsZone;
4
5#[derive(Serialize)]
6pub struct InfoDnsZoneAction {
7 #[serde(rename(serialize = "customernumber"))]
8 customer_no: u64,
9 #[serde(rename(serialize = "apikey"))]
10 api_key: String,
11 #[serde(rename(serialize = "apisessionid"))]
12 api_session_id: String,
13 #[serde(rename(serialize = "domainname"))]
14 domain_name: String,
15}
16
17impl InfoDnsZoneAction {
18 pub fn new(customer_no: u64, api_key: &str, api_session_id: &str, domain_name: &str) -> Self {
19 Self {
20 customer_no,
21 api_key: api_key.to_owned(),
22 api_session_id: api_session_id.to_owned(),
23 domain_name: domain_name.to_owned(),
24 }
25 }
26}
27
28#[derive(Serialize)]
29pub struct UpdateDnsZoneAction {
30 #[serde(rename(serialize = "customernumber"))]
31 customer_no: u64,
32 #[serde(rename(serialize = "apikey"))]
33 api_key: String,
34 #[serde(rename(serialize = "apisessionid"))]
35 api_session_id: String,
36 #[serde(rename(serialize = "domainname"))]
37 domain_name: String,
38 #[serde(rename(serialize = "dnszone"))]
39 dns_zone: DnsZone,
40}
41
42impl UpdateDnsZoneAction {
43 pub fn new(customer_no: u64, api_key: &str, api_session_id: &str, dns_zone: DnsZone) -> Self {
44 Self {
45 customer_no,
46 api_key: api_key.to_owned(),
47 api_session_id: api_session_id.to_owned(),
48 domain_name: dns_zone.name.to_owned(),
49 dns_zone,
50 }
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use crate::{
57 actions::{dnszone::*, request::RequestActionBuilder},
58 prelude::DnsZone,
59 };
60
61 #[test]
62 fn infodnszone_action_request() {
63 let param = InfoDnsZoneAction::new(4711, "abc123", "session4711", "example.tld");
64 let request = RequestActionBuilder::build("infodnszone", param);
65 let json = serde_json::to_string(&request);
66 assert_eq!("{\"action\":\"infodnszone\",\"param\":{\"customernumber\":4711,\"apikey\":\"abc123\",\"apisessionid\":\"session4711\",\"domainname\":\"example.tld\"}}", json.unwrap());
67 }
68
69 #[test]
70 fn updatednszone_action_request() {
71 let dns_zone = DnsZone {
72 name: "example.tld".to_string(),
73 ttl: "86400".to_string(),
74 serial: "1234567".to_string(),
75 refresh: "28800".to_string(),
76 retry: "7200".to_string(),
77 expire: "1209600".to_string(),
78 dns_sec_status: false,
79 };
80 let param = UpdateDnsZoneAction::new(4711, "abc123", "session4711", dns_zone);
81 let request = RequestActionBuilder::build("updatednszone", param);
82 let json = serde_json::to_string(&request);
83 assert_eq!("{\"action\":\"updatednszone\",\"param\":{\"customernumber\":4711,\"apikey\":\"abc123\",\"apisessionid\":\"session4711\",\"domainname\":\"example.tld\",\"dnszone\":{\"name\":\"example.tld\",\"ttl\":\"86400\",\"serial\":\"1234567\",\"refresh\":\"28800\",\"retry\":\"7200\",\"expire\":\"1209600\",\"dnssecstatus\":false}}}", json.unwrap());
84 }
85}