fastly_api/apis/
events_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_event`]
15#[derive(Clone, Debug, Default)]
16pub struct GetEventParams {
17    /// Alphanumeric string identifying an event.
18    pub event_id: String
19}
20
21/// struct for passing parameters to the method [`list_events`]
22#[derive(Clone, Debug, Default)]
23pub struct ListEventsParams {
24    /// Limit the results returned to a specific customer.
25    pub filter_customer_id: Option<String>,
26    /// Limit the returned events to a specific `event_type`.
27    pub filter_event_type: Option<String>,
28    /// Limit the results returned to a specific service.
29    pub filter_service_id: Option<String>,
30    /// Limit the results returned to a specific user.
31    pub filter_user_id: Option<String>,
32    /// Limit the returned events to a specific token.
33    pub filter_token_id: Option<String>,
34    /// Limit the returned events to a specific time frame. Accepts sub-parameters: lt, lte, gt, gte (e.g., filter[created_at][gt]=2022-01-12). 
35    pub filter_created_at: Option<String>,
36    /// Return events on and before a date and time in ISO 8601 format. 
37    pub filter_created_at_lte: Option<String>,
38    /// Return events before a date and time in ISO 8601 format. 
39    pub filter_created_at_lt: Option<String>,
40    /// Return events on and after a date and time in ISO 8601 format. 
41    pub filter_created_at_gte: Option<String>,
42    /// Return events after a date and time in ISO 8601 format. 
43    pub filter_created_at_gt: Option<String>,
44    /// Current page.
45    pub page_number: Option<i32>,
46    /// Number of records per page.
47    pub page_size: Option<i32>,
48    /// The order in which to list the results by creation date.
49    pub sort: Option<String>
50}
51
52
53/// struct for typed errors of method [`get_event`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetEventError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`list_events`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ListEventsError {
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Get a specific event.
69pub async fn get_event(configuration: &mut configuration::Configuration, params: GetEventParams) -> Result<crate::models::EventResponse, Error<GetEventError>> {
70    let local_var_configuration = configuration;
71
72    // unbox the parameters
73    let event_id = params.event_id;
74
75
76    let local_var_client = &local_var_configuration.client;
77
78    let local_var_uri_str = format!("{}/events/{event_id}", local_var_configuration.base_path, event_id=crate::apis::urlencode(event_id));
79    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
80
81    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
82        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
85        let local_var_key = local_var_apikey.key.clone();
86        let local_var_value = match local_var_apikey.prefix {
87            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
88            None => local_var_key,
89        };
90        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
91    };
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    if "GET" != "GET" && "GET" != "HEAD" {
97      let headers = local_var_resp.headers();
98      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
99          Some(v) => v.to_str().unwrap().parse().unwrap(),
100          None => configuration::DEFAULT_RATELIMIT,
101      };
102      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
103          Some(v) => v.to_str().unwrap().parse().unwrap(),
104          None => 0,
105      };
106    }
107
108    let local_var_status = local_var_resp.status();
109    let local_var_content = local_var_resp.text().await?;
110
111    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
112        serde_json::from_str(&local_var_content).map_err(Error::from)
113    } else {
114        let local_var_entity: Option<GetEventError> = serde_json::from_str(&local_var_content).ok();
115        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
116        Err(Error::ResponseError(local_var_error))
117    }
118}
119
120/// List all events for a particular customer. Events can be filtered by user, customer and event type. Events can be sorted by date.
121pub async fn list_events(configuration: &mut configuration::Configuration, params: ListEventsParams) -> Result<crate::models::EventsResponse, Error<ListEventsError>> {
122    let local_var_configuration = configuration;
123
124    // unbox the parameters
125    let filter_customer_id = params.filter_customer_id;
126    let filter_event_type = params.filter_event_type;
127    let filter_service_id = params.filter_service_id;
128    let filter_user_id = params.filter_user_id;
129    let filter_token_id = params.filter_token_id;
130    let filter_created_at = params.filter_created_at;
131    let filter_created_at_lte = params.filter_created_at_lte;
132    let filter_created_at_lt = params.filter_created_at_lt;
133    let filter_created_at_gte = params.filter_created_at_gte;
134    let filter_created_at_gt = params.filter_created_at_gt;
135    let page_number = params.page_number;
136    let page_size = params.page_size;
137    let sort = params.sort;
138
139
140    let local_var_client = &local_var_configuration.client;
141
142    let local_var_uri_str = format!("{}/events", local_var_configuration.base_path);
143    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
144
145    if let Some(ref local_var_str) = filter_customer_id {
146        local_var_req_builder = local_var_req_builder.query(&[("filter[customer_id]", &local_var_str.to_string())]);
147    }
148    if let Some(ref local_var_str) = filter_event_type {
149        local_var_req_builder = local_var_req_builder.query(&[("filter[event_type]", &local_var_str.to_string())]);
150    }
151    if let Some(ref local_var_str) = filter_service_id {
152        local_var_req_builder = local_var_req_builder.query(&[("filter[service_id]", &local_var_str.to_string())]);
153    }
154    if let Some(ref local_var_str) = filter_user_id {
155        local_var_req_builder = local_var_req_builder.query(&[("filter[user_id]", &local_var_str.to_string())]);
156    }
157    if let Some(ref local_var_str) = filter_token_id {
158        local_var_req_builder = local_var_req_builder.query(&[("filter[token_id]", &local_var_str.to_string())]);
159    }
160    if let Some(ref local_var_str) = filter_created_at {
161        local_var_req_builder = local_var_req_builder.query(&[("filter[created_at]", &local_var_str.to_string())]);
162    }
163    if let Some(ref local_var_str) = filter_created_at_lte {
164        local_var_req_builder = local_var_req_builder.query(&[("filter[created_at][lte]", &local_var_str.to_string())]);
165    }
166    if let Some(ref local_var_str) = filter_created_at_lt {
167        local_var_req_builder = local_var_req_builder.query(&[("filter[created_at][lt]", &local_var_str.to_string())]);
168    }
169    if let Some(ref local_var_str) = filter_created_at_gte {
170        local_var_req_builder = local_var_req_builder.query(&[("filter[created_at][gte]", &local_var_str.to_string())]);
171    }
172    if let Some(ref local_var_str) = filter_created_at_gt {
173        local_var_req_builder = local_var_req_builder.query(&[("filter[created_at][gt]", &local_var_str.to_string())]);
174    }
175    if let Some(ref local_var_str) = page_number {
176        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
177    }
178    if let Some(ref local_var_str) = page_size {
179        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
180    }
181    if let Some(ref local_var_str) = sort {
182        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
183    }
184    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
185        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
186    }
187    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
188        let local_var_key = local_var_apikey.key.clone();
189        let local_var_value = match local_var_apikey.prefix {
190            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
191            None => local_var_key,
192        };
193        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
194    };
195
196    let local_var_req = local_var_req_builder.build()?;
197    let local_var_resp = local_var_client.execute(local_var_req).await?;
198
199    if "GET" != "GET" && "GET" != "HEAD" {
200      let headers = local_var_resp.headers();
201      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
202          Some(v) => v.to_str().unwrap().parse().unwrap(),
203          None => configuration::DEFAULT_RATELIMIT,
204      };
205      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
206          Some(v) => v.to_str().unwrap().parse().unwrap(),
207          None => 0,
208      };
209    }
210
211    let local_var_status = local_var_resp.status();
212    let local_var_content = local_var_resp.text().await?;
213
214    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
215        serde_json::from_str(&local_var_content).map_err(Error::from)
216    } else {
217        let local_var_entity: Option<ListEventsError> = serde_json::from_str(&local_var_content).ok();
218        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
219        Err(Error::ResponseError(local_var_error))
220    }
221}
222