fastly_api/apis/
domain_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`check_domain`]
15#[derive(Clone, Debug, Default)]
16pub struct CheckDomainParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// The name of the domain or domains associated with this service.
22    pub domain_name: String
23}
24
25/// struct for passing parameters to the method [`create_domain`]
26#[derive(Clone, Debug, Default)]
27pub struct CreateDomainParams {
28    /// Alphanumeric string identifying the service.
29    pub service_id: String,
30    /// Integer identifying a service version.
31    pub version_id: i32,
32    /// A freeform descriptive note.
33    pub comment: Option<String>,
34    /// The name of the domain or domains associated with this service.
35    pub name: Option<String>
36}
37
38/// struct for passing parameters to the method [`delete_domain`]
39#[derive(Clone, Debug, Default)]
40pub struct DeleteDomainParams {
41    /// Alphanumeric string identifying the service.
42    pub service_id: String,
43    /// Integer identifying a service version.
44    pub version_id: i32,
45    /// The name of the domain or domains associated with this service.
46    pub domain_name: String
47}
48
49/// struct for passing parameters to the method [`get_domain`]
50#[derive(Clone, Debug, Default)]
51pub struct GetDomainParams {
52    /// Alphanumeric string identifying the service.
53    pub service_id: String,
54    /// Integer identifying a service version.
55    pub version_id: i32,
56    /// The name of the domain or domains associated with this service.
57    pub domain_name: String
58}
59
60/// struct for passing parameters to the method [`list_domains`]
61#[derive(Clone, Debug, Default)]
62pub struct ListDomainsParams {
63    /// Alphanumeric string identifying the service.
64    pub service_id: String,
65    /// Integer identifying a service version.
66    pub version_id: i32
67}
68
69/// struct for passing parameters to the method [`update_domain`]
70#[derive(Clone, Debug, Default)]
71pub struct UpdateDomainParams {
72    /// Alphanumeric string identifying the service.
73    pub service_id: String,
74    /// Integer identifying a service version.
75    pub version_id: i32,
76    /// The name of the domain or domains associated with this service.
77    pub domain_name: String,
78    /// A freeform descriptive note.
79    pub comment: Option<String>,
80    /// The name of the domain or domains associated with this service.
81    pub name: Option<String>
82}
83
84
85/// struct for typed errors of method [`check_domain`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum CheckDomainError {
89    UnknownValue(serde_json::Value),
90}
91
92/// struct for typed errors of method [`create_domain`]
93#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum CreateDomainError {
96    UnknownValue(serde_json::Value),
97}
98
99/// struct for typed errors of method [`delete_domain`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum DeleteDomainError {
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`get_domain`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum GetDomainError {
110    UnknownValue(serde_json::Value),
111}
112
113/// struct for typed errors of method [`list_domains`]
114#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum ListDomainsError {
117    UnknownValue(serde_json::Value),
118}
119
120/// struct for typed errors of method [`update_domain`]
121#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum UpdateDomainError {
124    UnknownValue(serde_json::Value),
125}
126
127
128/// Checks the status of a specific domain's DNS record for a Service Version. Returns an array in the same format as domain/check_all.
129pub async fn check_domain(configuration: &mut configuration::Configuration, params: CheckDomainParams) -> Result<Vec<serde_json::Value>, Error<CheckDomainError>> {
130    let local_var_configuration = configuration;
131
132    // unbox the parameters
133    let service_id = params.service_id;
134    let version_id = params.version_id;
135    let domain_name = params.domain_name;
136
137
138    let local_var_client = &local_var_configuration.client;
139
140    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/domain/{domain_name}/check", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, domain_name=crate::apis::urlencode(domain_name));
141    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
142
143    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
144        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
145    }
146    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
147        let local_var_key = local_var_apikey.key.clone();
148        let local_var_value = match local_var_apikey.prefix {
149            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
150            None => local_var_key,
151        };
152        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
153    };
154
155    let local_var_req = local_var_req_builder.build()?;
156    let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158    if "GET" != "GET" && "GET" != "HEAD" {
159      let headers = local_var_resp.headers();
160      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
161          Some(v) => v.to_str().unwrap().parse().unwrap(),
162          None => configuration::DEFAULT_RATELIMIT,
163      };
164      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
165          Some(v) => v.to_str().unwrap().parse().unwrap(),
166          None => 0,
167      };
168    }
169
170    let local_var_status = local_var_resp.status();
171    let local_var_content = local_var_resp.text().await?;
172
173    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174        serde_json::from_str(&local_var_content).map_err(Error::from)
175    } else {
176        let local_var_entity: Option<CheckDomainError> = serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182/// Create a domain for a particular service and version.
183pub async fn create_domain(configuration: &mut configuration::Configuration, params: CreateDomainParams) -> Result<crate::models::DomainResponse, Error<CreateDomainError>> {
184    let local_var_configuration = configuration;
185
186    // unbox the parameters
187    let service_id = params.service_id;
188    let version_id = params.version_id;
189    let comment = params.comment;
190    let name = params.name;
191
192
193    let local_var_client = &local_var_configuration.client;
194
195    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/domain", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
196    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
197
198    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
199        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
200    }
201    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
202        let local_var_key = local_var_apikey.key.clone();
203        let local_var_value = match local_var_apikey.prefix {
204            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
205            None => local_var_key,
206        };
207        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
208    };
209    let mut local_var_form_params = std::collections::HashMap::new();
210    if let Some(local_var_param_value) = comment {
211        local_var_form_params.insert("comment", local_var_param_value.to_string());
212    }
213    if let Some(local_var_param_value) = name {
214        local_var_form_params.insert("name", local_var_param_value.to_string());
215    }
216    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
217
218    let local_var_req = local_var_req_builder.build()?;
219    let local_var_resp = local_var_client.execute(local_var_req).await?;
220
221    if "POST" != "GET" && "POST" != "HEAD" {
222      let headers = local_var_resp.headers();
223      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
224          Some(v) => v.to_str().unwrap().parse().unwrap(),
225          None => configuration::DEFAULT_RATELIMIT,
226      };
227      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
228          Some(v) => v.to_str().unwrap().parse().unwrap(),
229          None => 0,
230      };
231    }
232
233    let local_var_status = local_var_resp.status();
234    let local_var_content = local_var_resp.text().await?;
235
236    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237        serde_json::from_str(&local_var_content).map_err(Error::from)
238    } else {
239        let local_var_entity: Option<CreateDomainError> = serde_json::from_str(&local_var_content).ok();
240        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
241        Err(Error::ResponseError(local_var_error))
242    }
243}
244
245/// Delete the domain for a particular service and versions.
246pub async fn delete_domain(configuration: &mut configuration::Configuration, params: DeleteDomainParams) -> Result<crate::models::InlineResponse200, Error<DeleteDomainError>> {
247    let local_var_configuration = configuration;
248
249    // unbox the parameters
250    let service_id = params.service_id;
251    let version_id = params.version_id;
252    let domain_name = params.domain_name;
253
254
255    let local_var_client = &local_var_configuration.client;
256
257    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/domain/{domain_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, domain_name=crate::apis::urlencode(domain_name));
258    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
259
260    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
261        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
262    }
263    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
264        let local_var_key = local_var_apikey.key.clone();
265        let local_var_value = match local_var_apikey.prefix {
266            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
267            None => local_var_key,
268        };
269        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
270    };
271
272    let local_var_req = local_var_req_builder.build()?;
273    let local_var_resp = local_var_client.execute(local_var_req).await?;
274
275    if "DELETE" != "GET" && "DELETE" != "HEAD" {
276      let headers = local_var_resp.headers();
277      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
278          Some(v) => v.to_str().unwrap().parse().unwrap(),
279          None => configuration::DEFAULT_RATELIMIT,
280      };
281      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
282          Some(v) => v.to_str().unwrap().parse().unwrap(),
283          None => 0,
284      };
285    }
286
287    let local_var_status = local_var_resp.status();
288    let local_var_content = local_var_resp.text().await?;
289
290    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291        serde_json::from_str(&local_var_content).map_err(Error::from)
292    } else {
293        let local_var_entity: Option<DeleteDomainError> = serde_json::from_str(&local_var_content).ok();
294        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
295        Err(Error::ResponseError(local_var_error))
296    }
297}
298
299/// Get the domain for a particular service and version.
300pub async fn get_domain(configuration: &mut configuration::Configuration, params: GetDomainParams) -> Result<crate::models::DomainResponse, Error<GetDomainError>> {
301    let local_var_configuration = configuration;
302
303    // unbox the parameters
304    let service_id = params.service_id;
305    let version_id = params.version_id;
306    let domain_name = params.domain_name;
307
308
309    let local_var_client = &local_var_configuration.client;
310
311    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/domain/{domain_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, domain_name=crate::apis::urlencode(domain_name));
312    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
313
314    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
315        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
316    }
317    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
318        let local_var_key = local_var_apikey.key.clone();
319        let local_var_value = match local_var_apikey.prefix {
320            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
321            None => local_var_key,
322        };
323        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
324    };
325
326    let local_var_req = local_var_req_builder.build()?;
327    let local_var_resp = local_var_client.execute(local_var_req).await?;
328
329    if "GET" != "GET" && "GET" != "HEAD" {
330      let headers = local_var_resp.headers();
331      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
332          Some(v) => v.to_str().unwrap().parse().unwrap(),
333          None => configuration::DEFAULT_RATELIMIT,
334      };
335      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
336          Some(v) => v.to_str().unwrap().parse().unwrap(),
337          None => 0,
338      };
339    }
340
341    let local_var_status = local_var_resp.status();
342    let local_var_content = local_var_resp.text().await?;
343
344    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
345        serde_json::from_str(&local_var_content).map_err(Error::from)
346    } else {
347        let local_var_entity: Option<GetDomainError> = serde_json::from_str(&local_var_content).ok();
348        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
349        Err(Error::ResponseError(local_var_error))
350    }
351}
352
353/// List all the domains for a particular service and version.
354pub async fn list_domains(configuration: &mut configuration::Configuration, params: ListDomainsParams) -> Result<Vec<crate::models::DomainResponse>, Error<ListDomainsError>> {
355    let local_var_configuration = configuration;
356
357    // unbox the parameters
358    let service_id = params.service_id;
359    let version_id = params.version_id;
360
361
362    let local_var_client = &local_var_configuration.client;
363
364    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/domain", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
365    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
366
367    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
368        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
369    }
370    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
371        let local_var_key = local_var_apikey.key.clone();
372        let local_var_value = match local_var_apikey.prefix {
373            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
374            None => local_var_key,
375        };
376        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
377    };
378
379    let local_var_req = local_var_req_builder.build()?;
380    let local_var_resp = local_var_client.execute(local_var_req).await?;
381
382    if "GET" != "GET" && "GET" != "HEAD" {
383      let headers = local_var_resp.headers();
384      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
385          Some(v) => v.to_str().unwrap().parse().unwrap(),
386          None => configuration::DEFAULT_RATELIMIT,
387      };
388      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
389          Some(v) => v.to_str().unwrap().parse().unwrap(),
390          None => 0,
391      };
392    }
393
394    let local_var_status = local_var_resp.status();
395    let local_var_content = local_var_resp.text().await?;
396
397    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
398        serde_json::from_str(&local_var_content).map_err(Error::from)
399    } else {
400        let local_var_entity: Option<ListDomainsError> = serde_json::from_str(&local_var_content).ok();
401        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
402        Err(Error::ResponseError(local_var_error))
403    }
404}
405
406/// Update the domain for a particular service and version.
407pub async fn update_domain(configuration: &mut configuration::Configuration, params: UpdateDomainParams) -> Result<crate::models::DomainResponse, Error<UpdateDomainError>> {
408    let local_var_configuration = configuration;
409
410    // unbox the parameters
411    let service_id = params.service_id;
412    let version_id = params.version_id;
413    let domain_name = params.domain_name;
414    let comment = params.comment;
415    let name = params.name;
416
417
418    let local_var_client = &local_var_configuration.client;
419
420    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/domain/{domain_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, domain_name=crate::apis::urlencode(domain_name));
421    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
422
423    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
424        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
425    }
426    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
427        let local_var_key = local_var_apikey.key.clone();
428        let local_var_value = match local_var_apikey.prefix {
429            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
430            None => local_var_key,
431        };
432        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
433    };
434    let mut local_var_form_params = std::collections::HashMap::new();
435    if let Some(local_var_param_value) = comment {
436        local_var_form_params.insert("comment", local_var_param_value.to_string());
437    }
438    if let Some(local_var_param_value) = name {
439        local_var_form_params.insert("name", local_var_param_value.to_string());
440    }
441    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
442
443    let local_var_req = local_var_req_builder.build()?;
444    let local_var_resp = local_var_client.execute(local_var_req).await?;
445
446    if "PUT" != "GET" && "PUT" != "HEAD" {
447      let headers = local_var_resp.headers();
448      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
449          Some(v) => v.to_str().unwrap().parse().unwrap(),
450          None => configuration::DEFAULT_RATELIMIT,
451      };
452      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
453          Some(v) => v.to_str().unwrap().parse().unwrap(),
454          None => 0,
455      };
456    }
457
458    let local_var_status = local_var_resp.status();
459    let local_var_content = local_var_resp.text().await?;
460
461    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
462        serde_json::from_str(&local_var_content).map_err(Error::from)
463    } else {
464        let local_var_entity: Option<UpdateDomainError> = serde_json::from_str(&local_var_content).ok();
465        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
466        Err(Error::ResponseError(local_var_error))
467    }
468}
469