fastly_api/apis/
image_optimizer_default_settings_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 [`get_default_settings`]
15#[derive(Clone, Debug, Default)]
16pub struct GetDefaultSettingsParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32
21}
22
23/// struct for passing parameters to the method [`update_default_settings`]
24#[derive(Clone, Debug, Default)]
25pub struct UpdateDefaultSettingsParams {
26    /// Alphanumeric string identifying the service.
27    pub service_id: String,
28    /// Integer identifying a service version.
29    pub version_id: i32,
30    pub default_settings: Option<crate::models::DefaultSettings>
31}
32
33
34/// struct for typed errors of method [`get_default_settings`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetDefaultSettingsError {
38    Status404(crate::models::DefaultSettingsError),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`update_default_settings`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum UpdateDefaultSettingsError {
46    Status400(crate::models::DefaultSettingsError),
47    Status403(crate::models::DefaultSettingsError),
48    UnknownValue(serde_json::Value),
49}
50
51
52/// Retrieve the current Image Optimizer default settings. All properties in the response will be populated. 
53pub async fn get_default_settings(configuration: &mut configuration::Configuration, params: GetDefaultSettingsParams) -> Result<crate::models::DefaultSettingsResponse, Error<GetDefaultSettingsError>> {
54    let local_var_configuration = configuration;
55
56    // unbox the parameters
57    let service_id = params.service_id;
58    let version_id = params.version_id;
59
60
61    let local_var_client = &local_var_configuration.client;
62
63    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/image_optimizer_default_settings", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
64    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
65
66    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
67        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
68    }
69    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
70        let local_var_key = local_var_apikey.key.clone();
71        let local_var_value = match local_var_apikey.prefix {
72            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
73            None => local_var_key,
74        };
75        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
76    };
77
78    let local_var_req = local_var_req_builder.build()?;
79    let local_var_resp = local_var_client.execute(local_var_req).await?;
80
81    if "GET" != "GET" && "GET" != "HEAD" {
82      let headers = local_var_resp.headers();
83      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
84          Some(v) => v.to_str().unwrap().parse().unwrap(),
85          None => configuration::DEFAULT_RATELIMIT,
86      };
87      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
88          Some(v) => v.to_str().unwrap().parse().unwrap(),
89          None => 0,
90      };
91    }
92
93    let local_var_status = local_var_resp.status();
94    let local_var_content = local_var_resp.text().await?;
95
96    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
97        serde_json::from_str(&local_var_content).map_err(Error::from)
98    } else {
99        let local_var_entity: Option<GetDefaultSettingsError> = serde_json::from_str(&local_var_content).ok();
100        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
101        Err(Error::ResponseError(local_var_error))
102    }
103}
104
105/// Update one or more default settings. A minimum of one property is required. The endpoint will respond with the new Image Optimizer default settings, with all properties populated. 
106pub async fn update_default_settings(configuration: &mut configuration::Configuration, params: UpdateDefaultSettingsParams) -> Result<crate::models::DefaultSettingsResponse, Error<UpdateDefaultSettingsError>> {
107    let local_var_configuration = configuration;
108
109    // unbox the parameters
110    let service_id = params.service_id;
111    let version_id = params.version_id;
112    let default_settings = params.default_settings;
113
114
115    let local_var_client = &local_var_configuration.client;
116
117    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/image_optimizer_default_settings", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
118    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
119
120    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
121        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
122    }
123    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
124        let local_var_key = local_var_apikey.key.clone();
125        let local_var_value = match local_var_apikey.prefix {
126            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
127            None => local_var_key,
128        };
129        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
130    };
131    local_var_req_builder = local_var_req_builder.json(&default_settings);
132
133    let local_var_req = local_var_req_builder.build()?;
134    let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136    if "PATCH" != "GET" && "PATCH" != "HEAD" {
137      let headers = local_var_resp.headers();
138      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
139          Some(v) => v.to_str().unwrap().parse().unwrap(),
140          None => configuration::DEFAULT_RATELIMIT,
141      };
142      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
143          Some(v) => v.to_str().unwrap().parse().unwrap(),
144          None => 0,
145      };
146    }
147
148    let local_var_status = local_var_resp.status();
149    let local_var_content = local_var_resp.text().await?;
150
151    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
152        serde_json::from_str(&local_var_content).map_err(Error::from)
153    } else {
154        let local_var_entity: Option<UpdateDefaultSettingsError> = serde_json::from_str(&local_var_content).ok();
155        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
156        Err(Error::ResponseError(local_var_error))
157    }
158}
159