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 */
789use reqwest;
1011use crate::apis::ResponseContent;
12use super::{Error, configuration};
1314/// struct for passing parameters to the method [`diff_service_versions`]
15#[derive(Clone, Debug, Default)]
16pub struct DiffServiceVersionsParams {
17/// Alphanumeric string identifying the service.
18pub service_id: String,
19/// The version number of the service to which changes in the generated VCL are being compared. Can either be a positive number from 1 to your maximum version or a negative number from -1 down (-1 is latest version etc).
20pub from_version_id: i32,
21/// The version number of the service from which changes in the generated VCL are being compared. Uses same numbering scheme as `from`.
22pub to_version_id: i32,
23/// Optional method to format the diff field.
24pub format: Option<String>
25}
262728/// struct for typed errors of method [`diff_service_versions`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DiffServiceVersionsError {
32 UnknownValue(serde_json::Value),
33}
343536/// Get diff between two versions.
37pub async fn diff_service_versions(configuration: &mut configuration::Configuration, params: DiffServiceVersionsParams) -> Result<crate::models::DiffResponse, Error<DiffServiceVersionsError>> {
38let local_var_configuration = configuration;
3940// unbox the parameters
41let service_id = params.service_id;
42let from_version_id = params.from_version_id;
43let to_version_id = params.to_version_id;
44let format = params.format;
454647let local_var_client = &local_var_configuration.client;
4849let local_var_uri_str = format!("{}/service/{service_id}/diff/from/{from_version_id}/to/{to_version_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), from_version_id=from_version_id, to_version_id=to_version_id);
50let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
5152if let Some(ref local_var_str) = format {
53 local_var_req_builder = local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
54 }
55if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
56 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
57 }
58if let Some(ref local_var_apikey) = local_var_configuration.api_key {
59let local_var_key = local_var_apikey.key.clone();
60let local_var_value = match local_var_apikey.prefix {
61Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
62None => local_var_key,
63 };
64 local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
65 };
6667let local_var_req = local_var_req_builder.build()?;
68let local_var_resp = local_var_client.execute(local_var_req).await?;
6970if "GET" != "GET" && "GET" != "HEAD" {
71let headers = local_var_resp.headers();
72 local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
73Some(v) => v.to_str().unwrap().parse().unwrap(),
74None => configuration::DEFAULT_RATELIMIT,
75 };
76 local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
77Some(v) => v.to_str().unwrap().parse().unwrap(),
78None => 0,
79 };
80 }
8182let local_var_status = local_var_resp.status();
83let local_var_content = local_var_resp.text().await?;
8485if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
86 serde_json::from_str(&local_var_content).map_err(Error::from)
87 } else {
88let local_var_entity: Option<DiffServiceVersionsError> = serde_json::from_str(&local_var_content).ok();
89let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
90Err(Error::ResponseError(local_var_error))
91 }
92}
93