fastly_api/apis/
diff_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 [`diff_service_versions`]
15#[derive(Clone, Debug, Default)]
16pub struct DiffServiceVersionsParams {
17    /// Alphanumeric string identifying the service.
18    pub 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).
20    pub 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`.
22    pub to_version_id: i32,
23    /// Optional method to format the diff field.
24    pub format: Option<String>
25}
26
27
28/// 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}
34
35
36/// Get diff between two versions.
37pub async fn diff_service_versions(configuration: &mut configuration::Configuration, params: DiffServiceVersionsParams) -> Result<crate::models::DiffResponse, Error<DiffServiceVersionsError>> {
38    let local_var_configuration = configuration;
39
40    // unbox the parameters
41    let service_id = params.service_id;
42    let from_version_id = params.from_version_id;
43    let to_version_id = params.to_version_id;
44    let format = params.format;
45
46
47    let local_var_client = &local_var_configuration.client;
48
49    let 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);
50    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
51
52    if let Some(ref local_var_str) = format {
53        local_var_req_builder = local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
54    }
55    if 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    }
58    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
59        let local_var_key = local_var_apikey.key.clone();
60        let local_var_value = match local_var_apikey.prefix {
61            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
62            None => local_var_key,
63        };
64        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
65    };
66
67    let local_var_req = local_var_req_builder.build()?;
68    let local_var_resp = local_var_client.execute(local_var_req).await?;
69
70    if "GET" != "GET" && "GET" != "HEAD" {
71      let headers = local_var_resp.headers();
72      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
73          Some(v) => v.to_str().unwrap().parse().unwrap(),
74          None => configuration::DEFAULT_RATELIMIT,
75      };
76      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
77          Some(v) => v.to_str().unwrap().parse().unwrap(),
78          None => 0,
79      };
80    }
81
82    let local_var_status = local_var_resp.status();
83    let local_var_content = local_var_resp.text().await?;
84
85    if !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 {
88        let local_var_entity: Option<DiffServiceVersionsError> = serde_json::from_str(&local_var_content).ok();
89        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
90        Err(Error::ResponseError(local_var_error))
91    }
92}
93