Skip to main content

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