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