1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use crate::client::NoBody;
use crate::client::scope::{Domains, Scoped};
use crate::{Error, Page, types::*, util::urlish};
impl<S: Domains> Scoped<'_, S> {
/// POST `{scope}/domains`, add a sending domain. The response carries the
/// DNS [`VerificationRecord`]s to publish.
pub async fn create_domain(&self, domain: CreateDomain) -> Result<Domain, Error> {
self.client
.request(
reqwest::Method::POST,
&format!("{}/domains", self.base()),
&[],
Some(&domain),
)
.await
}
/// GET `{scope}/domains`, one page.
pub async fn list_domains(&self, page: Page) -> Result<DomainList, Error> {
self.client
.request(
reqwest::Method::GET,
&format!("{}/domains", self.base()),
&page.query(),
None::<&NoBody>,
)
.await
}
/// Every domain, draining pagination.
pub async fn list_all_domains(&self) -> Result<Vec<Domain>, Error> {
let mut out = Vec::new();
let mut token = None;
loop {
let resp = self
.list_domains(Page {
limit: None,
page_token: token,
})
.await?;
let next = resp.next_page_token;
out.extend(resp.domains);
match next {
Some(t) => token = Some(t),
None => return Ok(out),
}
}
}
/// GET `{scope}/domains/{domain_id}`.
pub async fn get_domain(&self, domain_id: &str) -> Result<Domain, Error> {
self.client
.request(
reqwest::Method::GET,
&format!("{}/domains/{}", self.base(), urlish(domain_id)),
&[],
None::<&NoBody>,
)
.await
}
/// PATCH `{scope}/domains/{domain_id}`, toggle feedback and subdomain
/// settings.
pub async fn update_domain(
&self,
domain_id: &str,
update: UpdateDomain,
) -> Result<Domain, Error> {
self.client
.request(
reqwest::Method::PATCH,
&format!("{}/domains/{}", self.base(), urlish(domain_id)),
&[],
Some(&update),
)
.await
}
/// DELETE `{scope}/domains/{domain_id}`.
pub async fn delete_domain(&self, domain_id: &str) -> Result<(), Error> {
self.client
.request(
reqwest::Method::DELETE,
&format!("{}/domains/{}", self.base(), urlish(domain_id)),
&[],
None::<&NoBody>,
)
.await
}
/// POST `{scope}/domains/{domain_id}/verify`, ask the API to re-check the
/// DNS records; poll [`Scoped::get_domain`] for the resulting status.
pub async fn verify_domain(&self, domain_id: &str) -> Result<(), Error> {
self.client
.request(
reqwest::Method::POST,
&format!("{}/domains/{}/verify", self.base(), urlish(domain_id)),
&[],
None::<&NoBody>,
)
.await
}
/// GET `{scope}/domains/{domain_id}/zone-file`, the DNS records as a
/// ready-to-import zone file (plain text, not JSON).
pub async fn get_domain_zone_file(&self, domain_id: &str) -> Result<String, Error> {
self.client
.request_text(
reqwest::Method::GET,
&format!("{}/domains/{}/zone-file", self.base(), urlish(domain_id)),
)
.await
}
}
/// Provider setup links exist only at the organization scope.
impl Scoped<'_, crate::client::scope::OrgScope> {
/// GET `/v0/domains/{domain_id}/setup-link`, a one-click DNS setup flow
/// for the domain's provider, when one is [`DomainSetupLink::supported`].
pub async fn get_domain_setup_link(&self, domain_id: &str) -> Result<DomainSetupLink, Error> {
self.client
.request(
reqwest::Method::GET,
&format!("/v0/domains/{}/setup-link", urlish(domain_id)),
&[],
None::<&NoBody>,
)
.await
}
}