fastly_api/apis/
domain_inspector_historical_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_domain_inspector_historical`]
15#[derive(Clone, Debug, Default)]
16pub struct GetDomainInspectorHistoricalParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// A valid ISO-8601-formatted date and time, or UNIX timestamp, indicating the inclusive start of the query time range. If not provided, a default is chosen based on the provided `downsample` value.
20    pub start: Option<String>,
21    /// A valid ISO-8601-formatted date and time, or UNIX timestamp, indicating the exclusive end of the query time range. If not provided, a default is chosen based on the provided `downsample` value.
22    pub end: Option<String>,
23    /// Duration of sample windows.
24    pub downsample: Option<String>,
25    /// The metrics to retrieve. Multiple values should be comma-separated.
26    pub metric: Option<String>,
27    /// Dimensions to return in the query. Multiple dimensions may be separated by commas. For example, `group_by=domain` will return one timeseries for every domain, as a total across all datacenters (POPs). 
28    pub group_by: Option<String>,
29    /// Number of results per page. The maximum is 200.
30    pub limit: Option<String>,
31    /// Cursor value from the `next_cursor` field of a previous response, used to retrieve the next page. To request the first page, this should be empty.
32    pub cursor: Option<String>,
33    /// Limit query to one or more specific geographic regions. Values should be comma-separated. 
34    pub region: Option<String>,
35    /// Limit query to one or more specific POPs. Values should be comma-separated.
36    pub datacenter: Option<String>,
37    /// Limit query to one or more specific domains. Values should be comma-separated.
38    pub domain: Option<String>
39}
40
41
42/// struct for typed errors of method [`get_domain_inspector_historical`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetDomainInspectorHistoricalError {
46    UnknownValue(serde_json::Value),
47}
48
49
50/// Fetches historical domain metrics for a given Fastly service, optionally filtering and grouping the results by domain, region, or POP. 
51pub async fn get_domain_inspector_historical(configuration: &mut configuration::Configuration, params: GetDomainInspectorHistoricalParams) -> Result<crate::models::HistoricalDomainsResponse, Error<GetDomainInspectorHistoricalError>> {
52    let local_var_configuration = configuration;
53
54    // unbox the parameters
55    let service_id = params.service_id;
56    let start = params.start;
57    let end = params.end;
58    let downsample = params.downsample;
59    let metric = params.metric;
60    let group_by = params.group_by;
61    let limit = params.limit;
62    let cursor = params.cursor;
63    let region = params.region;
64    let datacenter = params.datacenter;
65    let domain = params.domain;
66
67
68    let local_var_client = &local_var_configuration.client;
69
70    let local_var_uri_str = format!("{}/metrics/domains/services/{service_id}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
71    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
72
73    if let Some(ref local_var_str) = start {
74        local_var_req_builder = local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
75    }
76    if let Some(ref local_var_str) = end {
77        local_var_req_builder = local_var_req_builder.query(&[("end", &local_var_str.to_string())]);
78    }
79    if let Some(ref local_var_str) = downsample {
80        local_var_req_builder = local_var_req_builder.query(&[("downsample", &local_var_str.to_string())]);
81    }
82    if let Some(ref local_var_str) = metric {
83        local_var_req_builder = local_var_req_builder.query(&[("metric", &local_var_str.to_string())]);
84    }
85    if let Some(ref local_var_str) = group_by {
86        local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
87    }
88    if let Some(ref local_var_str) = limit {
89        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
90    }
91    if let Some(ref local_var_str) = cursor {
92        local_var_req_builder = local_var_req_builder.query(&[("cursor", &local_var_str.to_string())]);
93    }
94    if let Some(ref local_var_str) = region {
95        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
96    }
97    if let Some(ref local_var_str) = datacenter {
98        local_var_req_builder = local_var_req_builder.query(&[("datacenter", &local_var_str.to_string())]);
99    }
100    if let Some(ref local_var_str) = domain {
101        local_var_req_builder = local_var_req_builder.query(&[("domain", &local_var_str.to_string())]);
102    }
103    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
104        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
105    }
106    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
107        let local_var_key = local_var_apikey.key.clone();
108        let local_var_value = match local_var_apikey.prefix {
109            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
110            None => local_var_key,
111        };
112        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
113    };
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    if "GET" != "GET" && "GET" != "HEAD" {
119      let headers = local_var_resp.headers();
120      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
121          Some(v) => v.to_str().unwrap().parse().unwrap(),
122          None => configuration::DEFAULT_RATELIMIT,
123      };
124      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
125          Some(v) => v.to_str().unwrap().parse().unwrap(),
126          None => 0,
127      };
128    }
129
130    let local_var_status = local_var_resp.status();
131    let local_var_content = local_var_resp.text().await?;
132
133    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
134        serde_json::from_str(&local_var_content).map_err(Error::from)
135    } else {
136        let local_var_entity: Option<GetDomainInspectorHistoricalError> = serde_json::from_str(&local_var_content).ok();
137        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
138        Err(Error::ResponseError(local_var_error))
139    }
140}
141