simply_dns/api.rs
1use serde::{Deserialize, Serialize};
2
3/// Represents a DNS record as returned by the Simply.com DNS API.
4///
5/// Fields map directly to the API response schema. For details, refer to the official API docs.
6/// See: https://www.simply.com/en/docs/api/
7#[derive(Debug, serde::Deserialize)]
8pub struct DnsRecord {
9 /// Unique identifier for the DNS record.
10 pub record_id: DnsRecordId,
11 /// The DNS record name (subdomain), e.g. "hello" in "hello.example.com".
12 pub name: String,
13 /// Time to live (TTL) in seconds for the DNS record.
14 pub ttl: u32,
15 /// Data field for the DNS record (e.g., IP address for "A" record, target domain for "CNAME", etc.).
16 pub data: String,
17 /// Type of DNS record ("A", "CNAME", "MX", etc.).
18 #[serde(rename = "type")]
19 pub record_type: String,
20 /// Priority value for records that require it (e.g., MX, SRV); optional.
21 pub priority: Option<u32>,
22 /// Optional comment or metadata for the record.
23 pub comment: Option<String>,
24}
25
26impl From<DnsRecordResponse> for DnsRecord {
27 fn from(value: DnsRecordResponse) -> Self {
28 DnsRecord {
29 record_id: DnsRecordId {
30 id: value.record_id,
31 },
32 name: value.name,
33 ttl: value.ttl,
34 data: value.data,
35 record_type: value.record_type,
36 priority: value.priority,
37 comment: value.comment,
38 }
39 }
40}
41
42#[derive(Debug, serde::Deserialize)]
43pub(crate) struct DnsRecordResponse {
44 /// Unique identifier for the DNS record.
45 pub record_id: u32,
46 /// The DNS record name (subdomain), e.g. "hello" in "hello.example.com".
47 pub name: String,
48 /// Time to live (TTL) in seconds for the DNS record.
49 pub ttl: u32,
50 /// Data field for the DNS record (e.g., IP address for "A" record, target domain for "CNAME", etc.).
51 pub data: String,
52 /// Type of DNS record ("A", "CNAME", "MX", etc.).
53 #[serde(rename = "type")]
54 pub record_type: String,
55 /// Priority value for records that require it (e.g., MX, SRV); optional.
56 pub priority: Option<u32>,
57 /// Optional comment or metadata for the record.
58 pub comment: Option<String>,
59}
60
61/// Response for listing DNS records from the API.
62#[derive(Debug, Deserialize)]
63pub(crate) struct ListDnsRecordsResponse {
64 /// The list of DNS records returned for a domain.
65 pub records: Vec<DnsRecordResponse>,
66}
67
68/// Request payload for creating a DNS record via the API.
69#[derive(Debug, Serialize)]
70pub struct CreateDnsRecordRequest {
71 /// Type of DNS record to create ("A", "CNAME", "MX", etc.).
72 #[serde(rename = "type")]
73 pub record_type: String,
74 /// The DNS record name (subdomain), e.g. "hello" in "hello.example.com".
75 pub name: String,
76 /// Data (e.g., IP address or target value).
77 pub data: String,
78 /// Priority value for records that require it.
79 pub priority: Option<u32>,
80 /// Time to live (TTL) for the record, in seconds.
81 pub ttl: Option<u32>,
82 /// Optional comment or metadata for the record.
83 pub comment: Option<String>,
84}
85
86/// Response for creating a DNS record via the API.
87#[derive(Debug, Deserialize)]
88pub(crate) struct CreateDnsRecordResponse {
89 /// List of created record IDs (if any).
90 pub record: Option<Vec<DnsRecordId>>, // Record id(s) created
91}
92
93/// Structure representing the ID of a newly created DNS record.
94#[derive(Debug, Deserialize)]
95pub struct DnsRecordId {
96 /// ID of the added DNS record.
97 pub(crate) id: u32,
98}
99
100/// Request payload for updating an existing DNS record via the API.
101#[derive(Debug, Serialize)]
102pub struct UpdateDnsRecordRequest {
103 /// Type of DNS record to update ("A", "CNAME", "MX", etc.).
104 #[serde(rename = "type")]
105 pub record_type: String,
106 /// The DNS record name (subdomain), e.g. "hello" in "hello.example.com".
107 pub name: String,
108 /// New data for the record (IP, target, etc.).
109 pub data: String,
110 /// Priority value for records that require it.
111 pub priority: Option<u32>,
112 /// Time to live (TTL) for the record, in seconds.
113 pub ttl: Option<u32>,
114 /// Optional comment or metadata for the record.
115 pub comment: Option<String>,
116}
117
118/// Response for deleting a DNS record via the API.
119#[derive(Debug, Deserialize)]
120pub(crate) struct GeneralResponse {
121 /// Message from the API, e.g. "success" or error details.
122 pub message: Option<String>,
123}