fastly_api/apis/
apex_redirect_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 [`create_apex_redirect`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateApexRedirectParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    pub service_id2: Option<String>,
22    pub version: Option<i32>,
23    /// Date and time in ISO 8601 format.
24    pub created_at: Option<String>,
25    /// Date and time in ISO 8601 format.
26    pub deleted_at: Option<String>,
27    /// Date and time in ISO 8601 format.
28    pub updated_at: Option<String>,
29    /// HTTP status code used to redirect the client.
30    pub status_code: Option<i32>,
31    /// Array of apex domains that should redirect to their WWW subdomain.
32    pub domains: Option<Vec<String>>,
33    /// Revision number of the apex redirect feature implementation. Defaults to the most recent revision.
34    pub feature_revision: Option<i32>
35}
36
37/// struct for passing parameters to the method [`delete_apex_redirect`]
38#[derive(Clone, Debug, Default)]
39pub struct DeleteApexRedirectParams {
40    pub apex_redirect_id: String
41}
42
43/// struct for passing parameters to the method [`get_apex_redirect`]
44#[derive(Clone, Debug, Default)]
45pub struct GetApexRedirectParams {
46    pub apex_redirect_id: String
47}
48
49/// struct for passing parameters to the method [`list_apex_redirects`]
50#[derive(Clone, Debug, Default)]
51pub struct ListApexRedirectsParams {
52    /// Alphanumeric string identifying the service.
53    pub service_id: String,
54    /// Integer identifying a service version.
55    pub version_id: i32
56}
57
58/// struct for passing parameters to the method [`update_apex_redirect`]
59#[derive(Clone, Debug, Default)]
60pub struct UpdateApexRedirectParams {
61    pub apex_redirect_id: String,
62    pub service_id: Option<String>,
63    pub version: Option<i32>,
64    /// Date and time in ISO 8601 format.
65    pub created_at: Option<String>,
66    /// Date and time in ISO 8601 format.
67    pub deleted_at: Option<String>,
68    /// Date and time in ISO 8601 format.
69    pub updated_at: Option<String>,
70    /// HTTP status code used to redirect the client.
71    pub status_code: Option<i32>,
72    /// Array of apex domains that should redirect to their WWW subdomain.
73    pub domains: Option<Vec<String>>,
74    /// Revision number of the apex redirect feature implementation. Defaults to the most recent revision.
75    pub feature_revision: Option<i32>
76}
77
78
79/// struct for typed errors of method [`create_apex_redirect`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum CreateApexRedirectError {
83    UnknownValue(serde_json::Value),
84}
85
86/// struct for typed errors of method [`delete_apex_redirect`]
87#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum DeleteApexRedirectError {
90    UnknownValue(serde_json::Value),
91}
92
93/// struct for typed errors of method [`get_apex_redirect`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum GetApexRedirectError {
97    UnknownValue(serde_json::Value),
98}
99
100/// struct for typed errors of method [`list_apex_redirects`]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[serde(untagged)]
103pub enum ListApexRedirectsError {
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`update_apex_redirect`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum UpdateApexRedirectError {
111    UnknownValue(serde_json::Value),
112}
113
114
115/// Create an apex redirect for a particular service and version.
116pub async fn create_apex_redirect(configuration: &mut configuration::Configuration, params: CreateApexRedirectParams) -> Result<crate::models::ApexRedirect, Error<CreateApexRedirectError>> {
117    let local_var_configuration = configuration;
118
119    // unbox the parameters
120    let service_id = params.service_id;
121    let version_id = params.version_id;
122    let service_id2 = params.service_id2;
123    let version = params.version;
124    let created_at = params.created_at;
125    let deleted_at = params.deleted_at;
126    let updated_at = params.updated_at;
127    let status_code = params.status_code;
128    let domains = params.domains;
129    let feature_revision = params.feature_revision;
130
131
132    let local_var_client = &local_var_configuration.client;
133
134    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/apex-redirects", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
135    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
136
137    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
138        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
139    }
140    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
141        let local_var_key = local_var_apikey.key.clone();
142        let local_var_value = match local_var_apikey.prefix {
143            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
144            None => local_var_key,
145        };
146        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
147    };
148    let mut local_var_form_params = std::collections::HashMap::new();
149    if let Some(local_var_param_value) = service_id2 {
150        local_var_form_params.insert("service_id", local_var_param_value.to_string());
151    }
152    if let Some(local_var_param_value) = version {
153        local_var_form_params.insert("version", local_var_param_value.to_string());
154    }
155    if let Some(local_var_param_value) = created_at {
156        local_var_form_params.insert("created_at", local_var_param_value.to_string());
157    }
158    if let Some(local_var_param_value) = deleted_at {
159        local_var_form_params.insert("deleted_at", local_var_param_value.to_string());
160    }
161    if let Some(local_var_param_value) = updated_at {
162        local_var_form_params.insert("updated_at", local_var_param_value.to_string());
163    }
164    if let Some(local_var_param_value) = status_code {
165        local_var_form_params.insert("status_code", local_var_param_value.to_string());
166    }
167    if let Some(local_var_param_value) = domains {
168        local_var_form_params.insert("domains[]", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
169    }
170    if let Some(local_var_param_value) = feature_revision {
171        local_var_form_params.insert("feature_revision", local_var_param_value.to_string());
172    }
173    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
174
175    let local_var_req = local_var_req_builder.build()?;
176    let local_var_resp = local_var_client.execute(local_var_req).await?;
177
178    if "POST" != "GET" && "POST" != "HEAD" {
179      let headers = local_var_resp.headers();
180      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
181          Some(v) => v.to_str().unwrap().parse().unwrap(),
182          None => configuration::DEFAULT_RATELIMIT,
183      };
184      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
185          Some(v) => v.to_str().unwrap().parse().unwrap(),
186          None => 0,
187      };
188    }
189
190    let local_var_status = local_var_resp.status();
191    let local_var_content = local_var_resp.text().await?;
192
193    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
194        serde_json::from_str(&local_var_content).map_err(Error::from)
195    } else {
196        let local_var_entity: Option<CreateApexRedirectError> = serde_json::from_str(&local_var_content).ok();
197        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
198        Err(Error::ResponseError(local_var_error))
199    }
200}
201
202/// Delete an apex redirect by its ID.
203pub async fn delete_apex_redirect(configuration: &mut configuration::Configuration, params: DeleteApexRedirectParams) -> Result<crate::models::InlineResponse200, Error<DeleteApexRedirectError>> {
204    let local_var_configuration = configuration;
205
206    // unbox the parameters
207    let apex_redirect_id = params.apex_redirect_id;
208
209
210    let local_var_client = &local_var_configuration.client;
211
212    let local_var_uri_str = format!("{}/apex-redirects/{apex_redirect_id}", local_var_configuration.base_path, apex_redirect_id=crate::apis::urlencode(apex_redirect_id));
213    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
214
215    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
216        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
217    }
218    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
219        let local_var_key = local_var_apikey.key.clone();
220        let local_var_value = match local_var_apikey.prefix {
221            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
222            None => local_var_key,
223        };
224        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
225    };
226
227    let local_var_req = local_var_req_builder.build()?;
228    let local_var_resp = local_var_client.execute(local_var_req).await?;
229
230    if "DELETE" != "GET" && "DELETE" != "HEAD" {
231      let headers = local_var_resp.headers();
232      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
233          Some(v) => v.to_str().unwrap().parse().unwrap(),
234          None => configuration::DEFAULT_RATELIMIT,
235      };
236      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
237          Some(v) => v.to_str().unwrap().parse().unwrap(),
238          None => 0,
239      };
240    }
241
242    let local_var_status = local_var_resp.status();
243    let local_var_content = local_var_resp.text().await?;
244
245    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246        serde_json::from_str(&local_var_content).map_err(Error::from)
247    } else {
248        let local_var_entity: Option<DeleteApexRedirectError> = serde_json::from_str(&local_var_content).ok();
249        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
250        Err(Error::ResponseError(local_var_error))
251    }
252}
253
254/// Get an apex redirect by its ID.
255pub async fn get_apex_redirect(configuration: &mut configuration::Configuration, params: GetApexRedirectParams) -> Result<crate::models::ApexRedirect, Error<GetApexRedirectError>> {
256    let local_var_configuration = configuration;
257
258    // unbox the parameters
259    let apex_redirect_id = params.apex_redirect_id;
260
261
262    let local_var_client = &local_var_configuration.client;
263
264    let local_var_uri_str = format!("{}/apex-redirects/{apex_redirect_id}", local_var_configuration.base_path, apex_redirect_id=crate::apis::urlencode(apex_redirect_id));
265    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
266
267    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
268        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
269    }
270    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
271        let local_var_key = local_var_apikey.key.clone();
272        let local_var_value = match local_var_apikey.prefix {
273            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
274            None => local_var_key,
275        };
276        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
277    };
278
279    let local_var_req = local_var_req_builder.build()?;
280    let local_var_resp = local_var_client.execute(local_var_req).await?;
281
282    if "GET" != "GET" && "GET" != "HEAD" {
283      let headers = local_var_resp.headers();
284      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
285          Some(v) => v.to_str().unwrap().parse().unwrap(),
286          None => configuration::DEFAULT_RATELIMIT,
287      };
288      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
289          Some(v) => v.to_str().unwrap().parse().unwrap(),
290          None => 0,
291      };
292    }
293
294    let local_var_status = local_var_resp.status();
295    let local_var_content = local_var_resp.text().await?;
296
297    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
298        serde_json::from_str(&local_var_content).map_err(Error::from)
299    } else {
300        let local_var_entity: Option<GetApexRedirectError> = serde_json::from_str(&local_var_content).ok();
301        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
302        Err(Error::ResponseError(local_var_error))
303    }
304}
305
306/// List all apex redirects for a particular service and version.
307pub async fn list_apex_redirects(configuration: &mut configuration::Configuration, params: ListApexRedirectsParams) -> Result<Vec<crate::models::ApexRedirect>, Error<ListApexRedirectsError>> {
308    let local_var_configuration = configuration;
309
310    // unbox the parameters
311    let service_id = params.service_id;
312    let version_id = params.version_id;
313
314
315    let local_var_client = &local_var_configuration.client;
316
317    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/apex-redirects", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
318    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
319
320    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
321        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
322    }
323    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
324        let local_var_key = local_var_apikey.key.clone();
325        let local_var_value = match local_var_apikey.prefix {
326            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
327            None => local_var_key,
328        };
329        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
330    };
331
332    let local_var_req = local_var_req_builder.build()?;
333    let local_var_resp = local_var_client.execute(local_var_req).await?;
334
335    if "GET" != "GET" && "GET" != "HEAD" {
336      let headers = local_var_resp.headers();
337      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
338          Some(v) => v.to_str().unwrap().parse().unwrap(),
339          None => configuration::DEFAULT_RATELIMIT,
340      };
341      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
342          Some(v) => v.to_str().unwrap().parse().unwrap(),
343          None => 0,
344      };
345    }
346
347    let local_var_status = local_var_resp.status();
348    let local_var_content = local_var_resp.text().await?;
349
350    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
351        serde_json::from_str(&local_var_content).map_err(Error::from)
352    } else {
353        let local_var_entity: Option<ListApexRedirectsError> = serde_json::from_str(&local_var_content).ok();
354        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
355        Err(Error::ResponseError(local_var_error))
356    }
357}
358
359/// Update an apex redirect by its ID.
360pub async fn update_apex_redirect(configuration: &mut configuration::Configuration, params: UpdateApexRedirectParams) -> Result<crate::models::ApexRedirect, Error<UpdateApexRedirectError>> {
361    let local_var_configuration = configuration;
362
363    // unbox the parameters
364    let apex_redirect_id = params.apex_redirect_id;
365    let service_id = params.service_id;
366    let version = params.version;
367    let created_at = params.created_at;
368    let deleted_at = params.deleted_at;
369    let updated_at = params.updated_at;
370    let status_code = params.status_code;
371    let domains = params.domains;
372    let feature_revision = params.feature_revision;
373
374
375    let local_var_client = &local_var_configuration.client;
376
377    let local_var_uri_str = format!("{}/apex-redirects/{apex_redirect_id}", local_var_configuration.base_path, apex_redirect_id=crate::apis::urlencode(apex_redirect_id));
378    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
379
380    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
381        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
382    }
383    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
384        let local_var_key = local_var_apikey.key.clone();
385        let local_var_value = match local_var_apikey.prefix {
386            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
387            None => local_var_key,
388        };
389        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
390    };
391    let mut local_var_form_params = std::collections::HashMap::new();
392    if let Some(local_var_param_value) = service_id {
393        local_var_form_params.insert("service_id", local_var_param_value.to_string());
394    }
395    if let Some(local_var_param_value) = version {
396        local_var_form_params.insert("version", local_var_param_value.to_string());
397    }
398    if let Some(local_var_param_value) = created_at {
399        local_var_form_params.insert("created_at", local_var_param_value.to_string());
400    }
401    if let Some(local_var_param_value) = deleted_at {
402        local_var_form_params.insert("deleted_at", local_var_param_value.to_string());
403    }
404    if let Some(local_var_param_value) = updated_at {
405        local_var_form_params.insert("updated_at", local_var_param_value.to_string());
406    }
407    if let Some(local_var_param_value) = status_code {
408        local_var_form_params.insert("status_code", local_var_param_value.to_string());
409    }
410    if let Some(local_var_param_value) = domains {
411        local_var_form_params.insert("domains[]", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
412    }
413    if let Some(local_var_param_value) = feature_revision {
414        local_var_form_params.insert("feature_revision", local_var_param_value.to_string());
415    }
416    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
417
418    let local_var_req = local_var_req_builder.build()?;
419    let local_var_resp = local_var_client.execute(local_var_req).await?;
420
421    if "PUT" != "GET" && "PUT" != "HEAD" {
422      let headers = local_var_resp.headers();
423      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
424          Some(v) => v.to_str().unwrap().parse().unwrap(),
425          None => configuration::DEFAULT_RATELIMIT,
426      };
427      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
428          Some(v) => v.to_str().unwrap().parse().unwrap(),
429          None => 0,
430      };
431    }
432
433    let local_var_status = local_var_resp.status();
434    let local_var_content = local_var_resp.text().await?;
435
436    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
437        serde_json::from_str(&local_var_content).map_err(Error::from)
438    } else {
439        let local_var_entity: Option<UpdateApexRedirectError> = serde_json::from_str(&local_var_content).ok();
440        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
441        Err(Error::ResponseError(local_var_error))
442    }
443}
444