cloudflare/endpoints/
zone.rs1use surf::http::Method;
2
3use crate::endpoints::{account::AccountDetails, plan::Plan};
4use crate::framework::{endpoint::Endpoint, ApiResultTraits};
5use crate::framework::{OrderDirection, SearchMatch};
6use chrono::offset::Utc;
7use chrono::DateTime;
8
9#[derive(Debug)]
13pub struct ListZones {
14 pub params: ListZonesParams,
15}
16
17impl Endpoint<Vec<Zone>, ListZonesParams> for ListZones {
18 fn method(&self) -> Method {
19 Method::Get
20 }
21 fn path(&self) -> String {
22 "zones".to_string()
23 }
24 fn query(&self) -> Option<ListZonesParams> {
25 Some(self.params.clone())
26 }
27}
28
29#[derive(Debug)]
32pub struct ZoneDetails<'a> {
33 pub identifier: &'a str,
34}
35impl<'a> Endpoint<Zone> for ZoneDetails<'a> {
36 fn method(&self) -> Method {
37 Method::Get
38 }
39 fn path(&self) -> String {
40 format!("zones/{}", self.identifier)
41 }
42}
43
44pub struct CreateZone<'a> {
47 pub params: CreateZoneParams<'a>,
48}
49impl<'a> Endpoint<(), (), CreateZoneParams<'a>> for CreateZone<'a> {
50 fn method(&self) -> Method {
51 Method::Post
52 }
53
54 fn path(&self) -> String {
55 "zones".to_string()
56 }
57
58 fn body(&self) -> Option<CreateZoneParams<'a>> {
59 Some(self.params.clone())
60 }
61}
62
63#[derive(Serialize, Clone, Debug, Default)]
64pub struct CreateZoneParams<'a> {
65 pub name: &'a str,
66 pub account: &'a str,
67 pub jump_start: Option<bool>,
68 #[serde(rename = "type")]
69 pub zone_type: Option<Type>,
70}
71
72#[derive(Serialize, Clone, Debug, Default)]
73pub struct ListZonesParams {
74 pub name: Option<String>,
75 pub status: Option<Status>,
76 pub page: Option<u32>,
77 pub per_page: Option<u32>,
78 pub order: Option<ListZonesOrder>,
79 pub direction: Option<OrderDirection>,
80 #[serde(rename = "match")]
81 pub search_match: Option<SearchMatch>,
82}
83
84#[derive(Serialize, Clone, Debug)]
85#[serde(rename_all = "lowercase")]
86pub enum ListZonesOrder {
87 Name,
88 Status,
89 Email,
90}
91
92#[derive(Clone, Debug, Deserialize, Serialize)]
93#[serde(rename = "status", rename_all = "lowercase")]
94pub enum Status {
95 Active,
96 Pending,
97 Initializing,
98 Moved,
99 Deleted,
100 Deactivated,
101}
102
103#[derive(Deserialize, Debug)]
104#[serde(rename_all = "lowercase", tag = "type")]
105pub enum Owner {
106 User { id: String, email: String },
107 Organization { id: String, name: String },
108}
109
110#[derive(Serialize, Deserialize, Debug, Clone)]
111#[serde(rename_all = "lowercase")]
112pub enum Type {
113 Full,
114 Partial,
115}
116
117#[derive(Deserialize, Debug)]
118pub struct HostingPartner {
119 pub name: String,
121 pub website: String,
123}
124
125#[derive(Deserialize, Debug)]
126pub struct Meta {
127 pub custom_certificate_quota: u32,
129 pub page_rule_quota: u32,
131 pub wildcard_proxiable: bool,
134 pub phishing_detected: bool,
136 pub multiple_railguns_allowed: bool,
138}
139
140#[derive(Deserialize, Debug)]
143pub struct Zone {
144 pub id: String,
146 pub name: String,
148 pub account: AccountDetails,
150 pub betas: Option<Vec<String>>,
152 pub created_on: DateTime<Utc>,
154 pub deactivation_reason: Option<String>,
157 pub development_mode: i32,
161 pub host: Option<HostingPartner>,
163 pub meta: Meta,
165 pub modified_on: DateTime<Utc>,
167 pub name_servers: Vec<String>,
169 pub original_dnshost: Option<String>,
171 pub original_name_servers: Option<Vec<String>>,
173 pub original_registrar: Option<String>,
175 pub owner: Owner,
177 pub paused: bool,
180 pub permissions: Vec<String>,
182 pub plan: Option<Plan>,
184 pub plan_pending: Option<Plan>,
186 pub status: Status,
188 pub vanity_name_servers: Option<Vec<String>>,
191 #[serde(rename = "type")]
194 pub zone_type: Type,
195}
196
197impl ApiResultTraits for Zone {}
199impl ApiResultTraits for Vec<Zone> {}