fastly_api/apis/
version_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 [`activate_service_version`]
15#[derive(Clone, Debug, Default)]
16pub struct ActivateServiceVersionParams {
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 [`activate_service_version_environment`]
24#[derive(Clone, Debug, Default)]
25pub struct ActivateServiceVersionEnvironmentParams {
26    /// Alphanumeric string identifying the service.
27    pub service_id: String,
28    /// Integer identifying a service version.
29    pub version_id: i32,
30    pub environment_name: crate::models::EnvironmentName
31}
32
33/// struct for passing parameters to the method [`clone_service_version`]
34#[derive(Clone, Debug, Default)]
35pub struct CloneServiceVersionParams {
36    /// Alphanumeric string identifying the service.
37    pub service_id: String,
38    /// Integer identifying a service version.
39    pub version_id: i32
40}
41
42/// struct for passing parameters to the method [`create_service_version`]
43#[derive(Clone, Debug, Default)]
44pub struct CreateServiceVersionParams {
45    /// Alphanumeric string identifying the service.
46    pub service_id: String
47}
48
49/// struct for passing parameters to the method [`deactivate_service_version`]
50#[derive(Clone, Debug, Default)]
51pub struct DeactivateServiceVersionParams {
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 [`deactivate_service_version_environment`]
59#[derive(Clone, Debug, Default)]
60pub struct DeactivateServiceVersionEnvironmentParams {
61    /// Alphanumeric string identifying the service.
62    pub service_id: String,
63    /// Integer identifying a service version.
64    pub version_id: i32,
65    pub environment_name: crate::models::EnvironmentName
66}
67
68/// struct for passing parameters to the method [`get_service_version`]
69#[derive(Clone, Debug, Default)]
70pub struct GetServiceVersionParams {
71    /// Alphanumeric string identifying the service.
72    pub service_id: String,
73    /// Integer identifying a service version.
74    pub version_id: i32
75}
76
77/// struct for passing parameters to the method [`list_service_versions`]
78#[derive(Clone, Debug, Default)]
79pub struct ListServiceVersionsParams {
80    /// Alphanumeric string identifying the service.
81    pub service_id: String
82}
83
84/// struct for passing parameters to the method [`lock_service_version`]
85#[derive(Clone, Debug, Default)]
86pub struct LockServiceVersionParams {
87    /// Alphanumeric string identifying the service.
88    pub service_id: String,
89    /// Integer identifying a service version.
90    pub version_id: i32
91}
92
93/// struct for passing parameters to the method [`update_service_version`]
94#[derive(Clone, Debug, Default)]
95pub struct UpdateServiceVersionParams {
96    /// Alphanumeric string identifying the service.
97    pub service_id: String,
98    /// Integer identifying a service version.
99    pub version_id: i32,
100    /// Whether this is the active version or not.
101    pub active: Option<bool>,
102    /// A freeform descriptive note.
103    pub comment: Option<String>,
104    /// Unused at this time.
105    pub deployed: Option<bool>,
106    /// Whether this version is locked or not. Objects can not be added or edited on locked versions.
107    pub locked: Option<bool>,
108    /// The number of this version.
109    pub number: Option<i32>,
110    /// Unused at this time.
111    pub staging: Option<bool>,
112    /// Unused at this time.
113    pub testing: Option<bool>
114}
115
116/// struct for passing parameters to the method [`validate_service_version`]
117#[derive(Clone, Debug, Default)]
118pub struct ValidateServiceVersionParams {
119    /// Alphanumeric string identifying the service.
120    pub service_id: String,
121    /// Integer identifying a service version.
122    pub version_id: i32
123}
124
125
126/// struct for typed errors of method [`activate_service_version`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum ActivateServiceVersionError {
130    UnknownValue(serde_json::Value),
131}
132
133/// struct for typed errors of method [`activate_service_version_environment`]
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum ActivateServiceVersionEnvironmentError {
137    UnknownValue(serde_json::Value),
138}
139
140/// struct for typed errors of method [`clone_service_version`]
141#[derive(Debug, Clone, Serialize, Deserialize)]
142#[serde(untagged)]
143pub enum CloneServiceVersionError {
144    UnknownValue(serde_json::Value),
145}
146
147/// struct for typed errors of method [`create_service_version`]
148#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(untagged)]
150pub enum CreateServiceVersionError {
151    UnknownValue(serde_json::Value),
152}
153
154/// struct for typed errors of method [`deactivate_service_version`]
155#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(untagged)]
157pub enum DeactivateServiceVersionError {
158    UnknownValue(serde_json::Value),
159}
160
161/// struct for typed errors of method [`deactivate_service_version_environment`]
162#[derive(Debug, Clone, Serialize, Deserialize)]
163#[serde(untagged)]
164pub enum DeactivateServiceVersionEnvironmentError {
165    UnknownValue(serde_json::Value),
166}
167
168/// struct for typed errors of method [`get_service_version`]
169#[derive(Debug, Clone, Serialize, Deserialize)]
170#[serde(untagged)]
171pub enum GetServiceVersionError {
172    UnknownValue(serde_json::Value),
173}
174
175/// struct for typed errors of method [`list_service_versions`]
176#[derive(Debug, Clone, Serialize, Deserialize)]
177#[serde(untagged)]
178pub enum ListServiceVersionsError {
179    UnknownValue(serde_json::Value),
180}
181
182/// struct for typed errors of method [`lock_service_version`]
183#[derive(Debug, Clone, Serialize, Deserialize)]
184#[serde(untagged)]
185pub enum LockServiceVersionError {
186    UnknownValue(serde_json::Value),
187}
188
189/// struct for typed errors of method [`update_service_version`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum UpdateServiceVersionError {
193    UnknownValue(serde_json::Value),
194}
195
196/// struct for typed errors of method [`validate_service_version`]
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum ValidateServiceVersionError {
200    UnknownValue(serde_json::Value),
201}
202
203
204/// Activate the current version.
205pub async fn activate_service_version(configuration: &mut configuration::Configuration, params: ActivateServiceVersionParams) -> Result<crate::models::VersionResponse, Error<ActivateServiceVersionError>> {
206    let local_var_configuration = configuration;
207
208    // unbox the parameters
209    let service_id = params.service_id;
210    let version_id = params.version_id;
211
212
213    let local_var_client = &local_var_configuration.client;
214
215    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/activate", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
216    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
217
218    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
219        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
220    }
221    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
222        let local_var_key = local_var_apikey.key.clone();
223        let local_var_value = match local_var_apikey.prefix {
224            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
225            None => local_var_key,
226        };
227        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
228    };
229
230    let local_var_req = local_var_req_builder.build()?;
231    let local_var_resp = local_var_client.execute(local_var_req).await?;
232
233    if "PUT" != "GET" && "PUT" != "HEAD" {
234      let headers = local_var_resp.headers();
235      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
236          Some(v) => v.to_str().unwrap().parse().unwrap(),
237          None => configuration::DEFAULT_RATELIMIT,
238      };
239      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
240          Some(v) => v.to_str().unwrap().parse().unwrap(),
241          None => 0,
242      };
243    }
244
245    let local_var_status = local_var_resp.status();
246    let local_var_content = local_var_resp.text().await?;
247
248    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249        serde_json::from_str(&local_var_content).map_err(Error::from)
250    } else {
251        let local_var_entity: Option<ActivateServiceVersionError> = serde_json::from_str(&local_var_content).ok();
252        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
253        Err(Error::ResponseError(local_var_error))
254    }
255}
256
257/// Activate a version on a given environment, i.e. \"staging\"
258pub async fn activate_service_version_environment(configuration: &mut configuration::Configuration, params: ActivateServiceVersionEnvironmentParams) -> Result<crate::models::VersionResponse, Error<ActivateServiceVersionEnvironmentError>> {
259    let local_var_configuration = configuration;
260
261    // unbox the parameters
262    let service_id = params.service_id;
263    let version_id = params.version_id;
264    let environment_name = params.environment_name;
265
266
267    let local_var_client = &local_var_configuration.client;
268
269    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/activate/{environment_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, environment_name=environment_name);
270    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
271
272    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
273        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274    }
275    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
276        let local_var_key = local_var_apikey.key.clone();
277        let local_var_value = match local_var_apikey.prefix {
278            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
279            None => local_var_key,
280        };
281        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
282    };
283
284    let local_var_req = local_var_req_builder.build()?;
285    let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287    if "PUT" != "GET" && "PUT" != "HEAD" {
288      let headers = local_var_resp.headers();
289      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
290          Some(v) => v.to_str().unwrap().parse().unwrap(),
291          None => configuration::DEFAULT_RATELIMIT,
292      };
293      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
294          Some(v) => v.to_str().unwrap().parse().unwrap(),
295          None => 0,
296      };
297    }
298
299    let local_var_status = local_var_resp.status();
300    let local_var_content = local_var_resp.text().await?;
301
302    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
303        serde_json::from_str(&local_var_content).map_err(Error::from)
304    } else {
305        let local_var_entity: Option<ActivateServiceVersionEnvironmentError> = serde_json::from_str(&local_var_content).ok();
306        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
307        Err(Error::ResponseError(local_var_error))
308    }
309}
310
311/// Clone the current configuration into a new version.
312pub async fn clone_service_version(configuration: &mut configuration::Configuration, params: CloneServiceVersionParams) -> Result<crate::models::Version, Error<CloneServiceVersionError>> {
313    let local_var_configuration = configuration;
314
315    // unbox the parameters
316    let service_id = params.service_id;
317    let version_id = params.version_id;
318
319
320    let local_var_client = &local_var_configuration.client;
321
322    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/clone", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
323    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
324
325    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
326        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
327    }
328    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
329        let local_var_key = local_var_apikey.key.clone();
330        let local_var_value = match local_var_apikey.prefix {
331            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
332            None => local_var_key,
333        };
334        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
335    };
336
337    let local_var_req = local_var_req_builder.build()?;
338    let local_var_resp = local_var_client.execute(local_var_req).await?;
339
340    if "PUT" != "GET" && "PUT" != "HEAD" {
341      let headers = local_var_resp.headers();
342      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
343          Some(v) => v.to_str().unwrap().parse().unwrap(),
344          None => configuration::DEFAULT_RATELIMIT,
345      };
346      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
347          Some(v) => v.to_str().unwrap().parse().unwrap(),
348          None => 0,
349      };
350    }
351
352    let local_var_status = local_var_resp.status();
353    let local_var_content = local_var_resp.text().await?;
354
355    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
356        serde_json::from_str(&local_var_content).map_err(Error::from)
357    } else {
358        let local_var_entity: Option<CloneServiceVersionError> = serde_json::from_str(&local_var_content).ok();
359        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
360        Err(Error::ResponseError(local_var_error))
361    }
362}
363
364/// Create a version for a particular service.
365pub async fn create_service_version(configuration: &mut configuration::Configuration, params: CreateServiceVersionParams) -> Result<crate::models::VersionCreateResponse, Error<CreateServiceVersionError>> {
366    let local_var_configuration = configuration;
367
368    // unbox the parameters
369    let service_id = params.service_id;
370
371
372    let local_var_client = &local_var_configuration.client;
373
374    let local_var_uri_str = format!("{}/service/{service_id}/version", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
375    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
376
377    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
378        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
379    }
380    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
381        let local_var_key = local_var_apikey.key.clone();
382        let local_var_value = match local_var_apikey.prefix {
383            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
384            None => local_var_key,
385        };
386        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
387    };
388
389    let local_var_req = local_var_req_builder.build()?;
390    let local_var_resp = local_var_client.execute(local_var_req).await?;
391
392    if "POST" != "GET" && "POST" != "HEAD" {
393      let headers = local_var_resp.headers();
394      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
395          Some(v) => v.to_str().unwrap().parse().unwrap(),
396          None => configuration::DEFAULT_RATELIMIT,
397      };
398      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
399          Some(v) => v.to_str().unwrap().parse().unwrap(),
400          None => 0,
401      };
402    }
403
404    let local_var_status = local_var_resp.status();
405    let local_var_content = local_var_resp.text().await?;
406
407    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
408        serde_json::from_str(&local_var_content).map_err(Error::from)
409    } else {
410        let local_var_entity: Option<CreateServiceVersionError> = serde_json::from_str(&local_var_content).ok();
411        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
412        Err(Error::ResponseError(local_var_error))
413    }
414}
415
416/// Deactivate the current version.
417pub async fn deactivate_service_version(configuration: &mut configuration::Configuration, params: DeactivateServiceVersionParams) -> Result<crate::models::VersionResponse, Error<DeactivateServiceVersionError>> {
418    let local_var_configuration = configuration;
419
420    // unbox the parameters
421    let service_id = params.service_id;
422    let version_id = params.version_id;
423
424
425    let local_var_client = &local_var_configuration.client;
426
427    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/deactivate", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
428    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
429
430    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
431        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
432    }
433    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
434        let local_var_key = local_var_apikey.key.clone();
435        let local_var_value = match local_var_apikey.prefix {
436            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
437            None => local_var_key,
438        };
439        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
440    };
441
442    let local_var_req = local_var_req_builder.build()?;
443    let local_var_resp = local_var_client.execute(local_var_req).await?;
444
445    if "PUT" != "GET" && "PUT" != "HEAD" {
446      let headers = local_var_resp.headers();
447      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
448          Some(v) => v.to_str().unwrap().parse().unwrap(),
449          None => configuration::DEFAULT_RATELIMIT,
450      };
451      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
452          Some(v) => v.to_str().unwrap().parse().unwrap(),
453          None => 0,
454      };
455    }
456
457    let local_var_status = local_var_resp.status();
458    let local_var_content = local_var_resp.text().await?;
459
460    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
461        serde_json::from_str(&local_var_content).map_err(Error::from)
462    } else {
463        let local_var_entity: Option<DeactivateServiceVersionError> = serde_json::from_str(&local_var_content).ok();
464        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
465        Err(Error::ResponseError(local_var_error))
466    }
467}
468
469/// Deactivate the current version on a given environment, i.e. \"staging\"
470pub async fn deactivate_service_version_environment(configuration: &mut configuration::Configuration, params: DeactivateServiceVersionEnvironmentParams) -> Result<crate::models::VersionResponse, Error<DeactivateServiceVersionEnvironmentError>> {
471    let local_var_configuration = configuration;
472
473    // unbox the parameters
474    let service_id = params.service_id;
475    let version_id = params.version_id;
476    let environment_name = params.environment_name;
477
478
479    let local_var_client = &local_var_configuration.client;
480
481    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/deactivate/{environment_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, environment_name=environment_name);
482    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
483
484    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
485        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
486    }
487    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
488        let local_var_key = local_var_apikey.key.clone();
489        let local_var_value = match local_var_apikey.prefix {
490            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
491            None => local_var_key,
492        };
493        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
494    };
495
496    let local_var_req = local_var_req_builder.build()?;
497    let local_var_resp = local_var_client.execute(local_var_req).await?;
498
499    if "PUT" != "GET" && "PUT" != "HEAD" {
500      let headers = local_var_resp.headers();
501      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
502          Some(v) => v.to_str().unwrap().parse().unwrap(),
503          None => configuration::DEFAULT_RATELIMIT,
504      };
505      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
506          Some(v) => v.to_str().unwrap().parse().unwrap(),
507          None => 0,
508      };
509    }
510
511    let local_var_status = local_var_resp.status();
512    let local_var_content = local_var_resp.text().await?;
513
514    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
515        serde_json::from_str(&local_var_content).map_err(Error::from)
516    } else {
517        let local_var_entity: Option<DeactivateServiceVersionEnvironmentError> = serde_json::from_str(&local_var_content).ok();
518        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
519        Err(Error::ResponseError(local_var_error))
520    }
521}
522
523/// Get the version for a particular service.
524pub async fn get_service_version(configuration: &mut configuration::Configuration, params: GetServiceVersionParams) -> Result<crate::models::VersionResponse, Error<GetServiceVersionError>> {
525    let local_var_configuration = configuration;
526
527    // unbox the parameters
528    let service_id = params.service_id;
529    let version_id = params.version_id;
530
531
532    let local_var_client = &local_var_configuration.client;
533
534    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
535    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
536
537    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
538        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
539    }
540    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
541        let local_var_key = local_var_apikey.key.clone();
542        let local_var_value = match local_var_apikey.prefix {
543            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
544            None => local_var_key,
545        };
546        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
547    };
548
549    let local_var_req = local_var_req_builder.build()?;
550    let local_var_resp = local_var_client.execute(local_var_req).await?;
551
552    if "GET" != "GET" && "GET" != "HEAD" {
553      let headers = local_var_resp.headers();
554      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
555          Some(v) => v.to_str().unwrap().parse().unwrap(),
556          None => configuration::DEFAULT_RATELIMIT,
557      };
558      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
559          Some(v) => v.to_str().unwrap().parse().unwrap(),
560          None => 0,
561      };
562    }
563
564    let local_var_status = local_var_resp.status();
565    let local_var_content = local_var_resp.text().await?;
566
567    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
568        serde_json::from_str(&local_var_content).map_err(Error::from)
569    } else {
570        let local_var_entity: Option<GetServiceVersionError> = serde_json::from_str(&local_var_content).ok();
571        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
572        Err(Error::ResponseError(local_var_error))
573    }
574}
575
576/// List the versions for a particular service.
577pub async fn list_service_versions(configuration: &mut configuration::Configuration, params: ListServiceVersionsParams) -> Result<Vec<crate::models::VersionResponse>, Error<ListServiceVersionsError>> {
578    let local_var_configuration = configuration;
579
580    // unbox the parameters
581    let service_id = params.service_id;
582
583
584    let local_var_client = &local_var_configuration.client;
585
586    let local_var_uri_str = format!("{}/service/{service_id}/version", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
587    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
588
589    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
590        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
591    }
592    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
593        let local_var_key = local_var_apikey.key.clone();
594        let local_var_value = match local_var_apikey.prefix {
595            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
596            None => local_var_key,
597        };
598        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
599    };
600
601    let local_var_req = local_var_req_builder.build()?;
602    let local_var_resp = local_var_client.execute(local_var_req).await?;
603
604    if "GET" != "GET" && "GET" != "HEAD" {
605      let headers = local_var_resp.headers();
606      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
607          Some(v) => v.to_str().unwrap().parse().unwrap(),
608          None => configuration::DEFAULT_RATELIMIT,
609      };
610      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
611          Some(v) => v.to_str().unwrap().parse().unwrap(),
612          None => 0,
613      };
614    }
615
616    let local_var_status = local_var_resp.status();
617    let local_var_content = local_var_resp.text().await?;
618
619    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
620        serde_json::from_str(&local_var_content).map_err(Error::from)
621    } else {
622        let local_var_entity: Option<ListServiceVersionsError> = serde_json::from_str(&local_var_content).ok();
623        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
624        Err(Error::ResponseError(local_var_error))
625    }
626}
627
628/// Locks the specified version.
629pub async fn lock_service_version(configuration: &mut configuration::Configuration, params: LockServiceVersionParams) -> Result<crate::models::Version, Error<LockServiceVersionError>> {
630    let local_var_configuration = configuration;
631
632    // unbox the parameters
633    let service_id = params.service_id;
634    let version_id = params.version_id;
635
636
637    let local_var_client = &local_var_configuration.client;
638
639    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/lock", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
640    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
641
642    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
643        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
644    }
645    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
646        let local_var_key = local_var_apikey.key.clone();
647        let local_var_value = match local_var_apikey.prefix {
648            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
649            None => local_var_key,
650        };
651        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
652    };
653
654    let local_var_req = local_var_req_builder.build()?;
655    let local_var_resp = local_var_client.execute(local_var_req).await?;
656
657    if "PUT" != "GET" && "PUT" != "HEAD" {
658      let headers = local_var_resp.headers();
659      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
660          Some(v) => v.to_str().unwrap().parse().unwrap(),
661          None => configuration::DEFAULT_RATELIMIT,
662      };
663      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
664          Some(v) => v.to_str().unwrap().parse().unwrap(),
665          None => 0,
666      };
667    }
668
669    let local_var_status = local_var_resp.status();
670    let local_var_content = local_var_resp.text().await?;
671
672    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
673        serde_json::from_str(&local_var_content).map_err(Error::from)
674    } else {
675        let local_var_entity: Option<LockServiceVersionError> = serde_json::from_str(&local_var_content).ok();
676        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
677        Err(Error::ResponseError(local_var_error))
678    }
679}
680
681/// Update a particular version for a particular service.
682pub async fn update_service_version(configuration: &mut configuration::Configuration, params: UpdateServiceVersionParams) -> Result<crate::models::VersionResponse, Error<UpdateServiceVersionError>> {
683    let local_var_configuration = configuration;
684
685    // unbox the parameters
686    let service_id = params.service_id;
687    let version_id = params.version_id;
688    let active = params.active;
689    let comment = params.comment;
690    let deployed = params.deployed;
691    let locked = params.locked;
692    let number = params.number;
693    let staging = params.staging;
694    let testing = params.testing;
695
696
697    let local_var_client = &local_var_configuration.client;
698
699    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
700    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
701
702    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
703        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
704    }
705    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
706        let local_var_key = local_var_apikey.key.clone();
707        let local_var_value = match local_var_apikey.prefix {
708            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
709            None => local_var_key,
710        };
711        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
712    };
713    let mut local_var_form_params = std::collections::HashMap::new();
714    if let Some(local_var_param_value) = active {
715        local_var_form_params.insert("active", local_var_param_value.to_string());
716    }
717    if let Some(local_var_param_value) = comment {
718        local_var_form_params.insert("comment", local_var_param_value.to_string());
719    }
720    if let Some(local_var_param_value) = deployed {
721        local_var_form_params.insert("deployed", local_var_param_value.to_string());
722    }
723    if let Some(local_var_param_value) = locked {
724        local_var_form_params.insert("locked", local_var_param_value.to_string());
725    }
726    if let Some(local_var_param_value) = number {
727        local_var_form_params.insert("number", local_var_param_value.to_string());
728    }
729    if let Some(local_var_param_value) = staging {
730        local_var_form_params.insert("staging", local_var_param_value.to_string());
731    }
732    if let Some(local_var_param_value) = testing {
733        local_var_form_params.insert("testing", local_var_param_value.to_string());
734    }
735    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
736
737    let local_var_req = local_var_req_builder.build()?;
738    let local_var_resp = local_var_client.execute(local_var_req).await?;
739
740    if "PUT" != "GET" && "PUT" != "HEAD" {
741      let headers = local_var_resp.headers();
742      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
743          Some(v) => v.to_str().unwrap().parse().unwrap(),
744          None => configuration::DEFAULT_RATELIMIT,
745      };
746      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
747          Some(v) => v.to_str().unwrap().parse().unwrap(),
748          None => 0,
749      };
750    }
751
752    let local_var_status = local_var_resp.status();
753    let local_var_content = local_var_resp.text().await?;
754
755    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
756        serde_json::from_str(&local_var_content).map_err(Error::from)
757    } else {
758        let local_var_entity: Option<UpdateServiceVersionError> = serde_json::from_str(&local_var_content).ok();
759        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
760        Err(Error::ResponseError(local_var_error))
761    }
762}
763
764/// Validate the version for a particular service and version.
765pub async fn validate_service_version(configuration: &mut configuration::Configuration, params: ValidateServiceVersionParams) -> Result<crate::models::InlineResponse200, Error<ValidateServiceVersionError>> {
766    let local_var_configuration = configuration;
767
768    // unbox the parameters
769    let service_id = params.service_id;
770    let version_id = params.version_id;
771
772
773    let local_var_client = &local_var_configuration.client;
774
775    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/validate", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
776    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
777
778    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
779        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
780    }
781    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
782        let local_var_key = local_var_apikey.key.clone();
783        let local_var_value = match local_var_apikey.prefix {
784            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
785            None => local_var_key,
786        };
787        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
788    };
789
790    let local_var_req = local_var_req_builder.build()?;
791    let local_var_resp = local_var_client.execute(local_var_req).await?;
792
793    if "GET" != "GET" && "GET" != "HEAD" {
794      let headers = local_var_resp.headers();
795      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
796          Some(v) => v.to_str().unwrap().parse().unwrap(),
797          None => configuration::DEFAULT_RATELIMIT,
798      };
799      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
800          Some(v) => v.to_str().unwrap().parse().unwrap(),
801          None => 0,
802      };
803    }
804
805    let local_var_status = local_var_resp.status();
806    let local_var_content = local_var_resp.text().await?;
807
808    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
809        serde_json::from_str(&local_var_content).map_err(Error::from)
810    } else {
811        let local_var_entity: Option<ValidateServiceVersionError> = serde_json::from_str(&local_var_content).ok();
812        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
813        Err(Error::ResponseError(local_var_error))
814    }
815}
816