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