fastly_api/apis/
product_ai_accelerator_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
15/// struct for typed errors of method [`disable_product_ai_accelerator`]
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(untagged)]
18pub enum DisableProductAiAcceleratorError {
19    UnknownValue(serde_json::Value),
20}
21
22/// struct for typed errors of method [`enable_ai_accelerator`]
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum EnableAiAcceleratorError {
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_ai_accelerator`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetAiAcceleratorError {
33    UnknownValue(serde_json::Value),
34}
35
36
37/// Disable the AI Accelerator product
38pub async fn disable_product_ai_accelerator(configuration: &mut configuration::Configuration) -> Result<(), Error<DisableProductAiAcceleratorError>> {
39    let local_var_configuration = configuration;
40
41    // unbox the parameters
42
43
44    let local_var_client = &local_var_configuration.client;
45
46    let local_var_uri_str = format!("{}/enabled-products/v1/ai_accelerator", local_var_configuration.base_path);
47    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
48
49    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
50        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
51    }
52    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
53        let local_var_key = local_var_apikey.key.clone();
54        let local_var_value = match local_var_apikey.prefix {
55            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
56            None => local_var_key,
57        };
58        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
59    };
60
61    let local_var_req = local_var_req_builder.build()?;
62    let local_var_resp = local_var_client.execute(local_var_req).await?;
63
64    if "DELETE" != "GET" && "DELETE" != "HEAD" {
65      let headers = local_var_resp.headers();
66      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
67          Some(v) => v.to_str().unwrap().parse().unwrap(),
68          None => configuration::DEFAULT_RATELIMIT,
69      };
70      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
71          Some(v) => v.to_str().unwrap().parse().unwrap(),
72          None => 0,
73      };
74    }
75
76    let local_var_status = local_var_resp.status();
77    let local_var_content = local_var_resp.text().await?;
78
79    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
80        Ok(())
81    } else {
82        let local_var_entity: Option<DisableProductAiAcceleratorError> = serde_json::from_str(&local_var_content).ok();
83        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
84        Err(Error::ResponseError(local_var_error))
85    }
86}
87
88/// Enable the AI Accelerator product
89pub async fn enable_ai_accelerator(configuration: &mut configuration::Configuration) -> Result<crate::models::AiAcceleratorResponseBodyEnable, Error<EnableAiAcceleratorError>> {
90    let local_var_configuration = configuration;
91
92    // unbox the parameters
93
94
95    let local_var_client = &local_var_configuration.client;
96
97    let local_var_uri_str = format!("{}/enabled-products/v1/ai_accelerator", local_var_configuration.base_path);
98    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
99
100    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
101        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102    }
103    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
104        let local_var_key = local_var_apikey.key.clone();
105        let local_var_value = match local_var_apikey.prefix {
106            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
107            None => local_var_key,
108        };
109        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
110    };
111
112    let local_var_req = local_var_req_builder.build()?;
113    let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115    if "PUT" != "GET" && "PUT" != "HEAD" {
116      let headers = local_var_resp.headers();
117      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
118          Some(v) => v.to_str().unwrap().parse().unwrap(),
119          None => configuration::DEFAULT_RATELIMIT,
120      };
121      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
122          Some(v) => v.to_str().unwrap().parse().unwrap(),
123          None => 0,
124      };
125    }
126
127    let local_var_status = local_var_resp.status();
128    let local_var_content = local_var_resp.text().await?;
129
130    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131        serde_json::from_str(&local_var_content).map_err(Error::from)
132    } else {
133        let local_var_entity: Option<EnableAiAcceleratorError> = serde_json::from_str(&local_var_content).ok();
134        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135        Err(Error::ResponseError(local_var_error))
136    }
137}
138
139/// Get the enablement status of the AI Accelerator product
140pub async fn get_ai_accelerator(configuration: &mut configuration::Configuration) -> Result<crate::models::AiAcceleratorResponseBodyEnable, Error<GetAiAcceleratorError>> {
141    let local_var_configuration = configuration;
142
143    // unbox the parameters
144
145
146    let local_var_client = &local_var_configuration.client;
147
148    let local_var_uri_str = format!("{}/enabled-products/v1/ai_accelerator", local_var_configuration.base_path);
149    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
153    }
154    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
155        let local_var_key = local_var_apikey.key.clone();
156        let local_var_value = match local_var_apikey.prefix {
157            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
158            None => local_var_key,
159        };
160        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
161    };
162
163    let local_var_req = local_var_req_builder.build()?;
164    let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166    if "GET" != "GET" && "GET" != "HEAD" {
167      let headers = local_var_resp.headers();
168      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
169          Some(v) => v.to_str().unwrap().parse().unwrap(),
170          None => configuration::DEFAULT_RATELIMIT,
171      };
172      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
173          Some(v) => v.to_str().unwrap().parse().unwrap(),
174          None => 0,
175      };
176    }
177
178    let local_var_status = local_var_resp.status();
179    let local_var_content = local_var_resp.text().await?;
180
181    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
182        serde_json::from_str(&local_var_content).map_err(Error::from)
183    } else {
184        let local_var_entity: Option<GetAiAcceleratorError> = serde_json::from_str(&local_var_content).ok();
185        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
186        Err(Error::ResponseError(local_var_error))
187    }
188}
189