twilio_rust_openapi/apis/
api20100401_notification_api.rs

1/*
2 * Twilio - Api
3 *
4 * This is the public Twilio REST API.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: support@twilio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`fetch_call_notification`]
18#[derive(Clone, Debug)]
19pub struct FetchCallNotificationParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call Notification resource to fetch.
21    pub account_sid: String,
22    /// The [Call](https://www.twilio.com/docs/voice/api/call-resource) SID of the Call Notification resource to fetch.
23    pub call_sid: String,
24    /// The Twilio-provided string that uniquely identifies the Call Notification resource to fetch.
25    pub sid: String
26}
27
28/// struct for passing parameters to the method [`fetch_notification`]
29#[derive(Clone, Debug)]
30pub struct FetchNotificationParams {
31    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Notification resource to fetch.
32    pub account_sid: String,
33    /// The Twilio-provided string that uniquely identifies the Notification resource to fetch.
34    pub sid: String
35}
36
37/// struct for passing parameters to the method [`list_call_notification`]
38#[derive(Clone, Debug)]
39pub struct ListCallNotificationParams {
40    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call Notification resources to read.
41    pub account_sid: String,
42    /// The [Call](https://www.twilio.com/docs/voice/api/call-resource) SID of the Call Notification resources to read.
43    pub call_sid: String,
44    /// Only read notifications of the specified log level. Can be:  `0` to read only ERROR notifications or `1` to read only WARNING notifications. By default, all notifications are read.
45    pub log: Option<i32>,
46    /// Only show notifications for the specified date, formatted as `YYYY-MM-DD`. You can also specify an inequality, such as `<=YYYY-MM-DD` for messages logged at or before midnight on a date, or `>=YYYY-MM-DD` for messages logged at or after midnight on a date.
47    pub message_date: Option<String>,
48    /// Only show notifications for the specified date, formatted as `YYYY-MM-DD`. You can also specify an inequality, such as `<=YYYY-MM-DD` for messages logged at or before midnight on a date, or `>=YYYY-MM-DD` for messages logged at or after midnight on a date.
49    pub message_date_less_than: Option<String>,
50    /// Only show notifications for the specified date, formatted as `YYYY-MM-DD`. You can also specify an inequality, such as `<=YYYY-MM-DD` for messages logged at or before midnight on a date, or `>=YYYY-MM-DD` for messages logged at or after midnight on a date.
51    pub message_date_greater_than: Option<String>,
52    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
53    pub page_size: Option<i32>,
54    /// The page index. This value is simply for client state.
55    pub page: Option<i32>,
56    /// The page token. This is provided by the API.
57    pub page_token: Option<String>
58}
59
60/// struct for passing parameters to the method [`list_notification`]
61#[derive(Clone, Debug)]
62pub struct ListNotificationParams {
63    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Notification resources to read.
64    pub account_sid: String,
65    /// Only read notifications of the specified log level. Can be:  `0` to read only ERROR notifications or `1` to read only WARNING notifications. By default, all notifications are read.
66    pub log: Option<i32>,
67    /// Only show notifications for the specified date, formatted as `YYYY-MM-DD`. You can also specify an inequality, such as `<=YYYY-MM-DD` for messages logged at or before midnight on a date, or `>=YYYY-MM-DD` for messages logged at or after midnight on a date.
68    pub message_date: Option<String>,
69    /// Only show notifications for the specified date, formatted as `YYYY-MM-DD`. You can also specify an inequality, such as `<=YYYY-MM-DD` for messages logged at or before midnight on a date, or `>=YYYY-MM-DD` for messages logged at or after midnight on a date.
70    pub message_date_less_than: Option<String>,
71    /// Only show notifications for the specified date, formatted as `YYYY-MM-DD`. You can also specify an inequality, such as `<=YYYY-MM-DD` for messages logged at or before midnight on a date, or `>=YYYY-MM-DD` for messages logged at or after midnight on a date.
72    pub message_date_greater_than: Option<String>,
73    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
74    pub page_size: Option<i32>,
75    /// The page index. This value is simply for client state.
76    pub page: Option<i32>,
77    /// The page token. This is provided by the API.
78    pub page_token: Option<String>
79}
80
81
82/// struct for typed errors of method [`fetch_call_notification`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum FetchCallNotificationError {
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`fetch_notification`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum FetchNotificationError {
93    UnknownValue(serde_json::Value),
94}
95
96/// struct for typed errors of method [`list_call_notification`]
97#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum ListCallNotificationError {
100    UnknownValue(serde_json::Value),
101}
102
103/// struct for typed errors of method [`list_notification`]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum ListNotificationError {
107    UnknownValue(serde_json::Value),
108}
109
110
111/// 
112pub async fn fetch_call_notification(configuration: &configuration::Configuration, params: FetchCallNotificationParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCallPeriodCallNotificationInstance, Error<FetchCallNotificationError>> {
113    let local_var_configuration = configuration;
114
115    // unbox the parameters
116    let account_sid = params.account_sid;
117    let call_sid = params.call_sid;
118    let sid = params.sid;
119
120
121    let local_var_client = &local_var_configuration.client;
122
123    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CallSid=crate::apis::urlencode(call_sid), Sid=crate::apis::urlencode(sid));
124    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
125
126    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
127        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
128    }
129    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
130        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
131    };
132
133    let local_var_req = local_var_req_builder.build()?;
134    let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136    let local_var_status = local_var_resp.status();
137    let local_var_content = local_var_resp.text().await?;
138
139    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140        serde_json::from_str(&local_var_content).map_err(Error::from)
141    } else {
142        let local_var_entity: Option<FetchCallNotificationError> = serde_json::from_str(&local_var_content).ok();
143        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
144        Err(Error::ResponseError(local_var_error))
145    }
146}
147
148/// Fetch a notification belonging to the account used to make the request
149pub async fn fetch_notification(configuration: &configuration::Configuration, params: FetchNotificationParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodNotificationInstance, Error<FetchNotificationError>> {
150    let local_var_configuration = configuration;
151
152    // unbox the parameters
153    let account_sid = params.account_sid;
154    let sid = params.sid;
155
156
157    let local_var_client = &local_var_configuration.client;
158
159    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
160    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
161
162    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164    }
165    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
166        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
167    };
168
169    let local_var_req = local_var_req_builder.build()?;
170    let local_var_resp = local_var_client.execute(local_var_req).await?;
171
172    let local_var_status = local_var_resp.status();
173    let local_var_content = local_var_resp.text().await?;
174
175    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176        serde_json::from_str(&local_var_content).map_err(Error::from)
177    } else {
178        let local_var_entity: Option<FetchNotificationError> = serde_json::from_str(&local_var_content).ok();
179        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
180        Err(Error::ResponseError(local_var_error))
181    }
182}
183
184/// 
185pub async fn list_call_notification(configuration: &configuration::Configuration, params: ListCallNotificationParams) -> Result<models::ListCallNotificationResponse, Error<ListCallNotificationError>> {
186    let local_var_configuration = configuration;
187
188    // unbox the parameters
189    let account_sid = params.account_sid;
190    let call_sid = params.call_sid;
191    let log = params.log;
192    let message_date = params.message_date;
193    let message_date_less_than = params.message_date_less_than;
194    let message_date_greater_than = params.message_date_greater_than;
195    let page_size = params.page_size;
196    let page = params.page;
197    let page_token = params.page_token;
198
199
200    let local_var_client = &local_var_configuration.client;
201
202    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CallSid=crate::apis::urlencode(call_sid));
203    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
204
205    if let Some(ref local_var_str) = log {
206        local_var_req_builder = local_var_req_builder.query(&[("Log", &local_var_str.to_string())]);
207    }
208    if let Some(ref local_var_str) = message_date {
209        local_var_req_builder = local_var_req_builder.query(&[("MessageDate", &local_var_str.to_string())]);
210    }
211    if let Some(ref local_var_str) = message_date_less_than {
212        local_var_req_builder = local_var_req_builder.query(&[("MessageDate<", &local_var_str.to_string())]);
213    }
214    if let Some(ref local_var_str) = message_date_greater_than {
215        local_var_req_builder = local_var_req_builder.query(&[("MessageDate>", &local_var_str.to_string())]);
216    }
217    if let Some(ref local_var_str) = page_size {
218        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
219    }
220    if let Some(ref local_var_str) = page {
221        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
222    }
223    if let Some(ref local_var_str) = page_token {
224        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
225    }
226    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
228    }
229    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
230        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
231    };
232
233    let local_var_req = local_var_req_builder.build()?;
234    let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236    let local_var_status = local_var_resp.status();
237    let local_var_content = local_var_resp.text().await?;
238
239    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
240        serde_json::from_str(&local_var_content).map_err(Error::from)
241    } else {
242        let local_var_entity: Option<ListCallNotificationError> = serde_json::from_str(&local_var_content).ok();
243        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
244        Err(Error::ResponseError(local_var_error))
245    }
246}
247
248/// Retrieve a list of notifications belonging to the account used to make the request
249pub async fn list_notification(configuration: &configuration::Configuration, params: ListNotificationParams) -> Result<models::ListNotificationResponse, Error<ListNotificationError>> {
250    let local_var_configuration = configuration;
251
252    // unbox the parameters
253    let account_sid = params.account_sid;
254    let log = params.log;
255    let message_date = params.message_date;
256    let message_date_less_than = params.message_date_less_than;
257    let message_date_greater_than = params.message_date_greater_than;
258    let page_size = params.page_size;
259    let page = params.page;
260    let page_token = params.page_token;
261
262
263    let local_var_client = &local_var_configuration.client;
264
265    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Notifications.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
266    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
267
268    if let Some(ref local_var_str) = log {
269        local_var_req_builder = local_var_req_builder.query(&[("Log", &local_var_str.to_string())]);
270    }
271    if let Some(ref local_var_str) = message_date {
272        local_var_req_builder = local_var_req_builder.query(&[("MessageDate", &local_var_str.to_string())]);
273    }
274    if let Some(ref local_var_str) = message_date_less_than {
275        local_var_req_builder = local_var_req_builder.query(&[("MessageDate<", &local_var_str.to_string())]);
276    }
277    if let Some(ref local_var_str) = message_date_greater_than {
278        local_var_req_builder = local_var_req_builder.query(&[("MessageDate>", &local_var_str.to_string())]);
279    }
280    if let Some(ref local_var_str) = page_size {
281        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
282    }
283    if let Some(ref local_var_str) = page {
284        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
285    }
286    if let Some(ref local_var_str) = page_token {
287        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
288    }
289    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
291    }
292    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
293        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
294    };
295
296    let local_var_req = local_var_req_builder.build()?;
297    let local_var_resp = local_var_client.execute(local_var_req).await?;
298
299    let local_var_status = local_var_resp.status();
300    let local_var_content = local_var_resp.text().await?;
301
302    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
303        serde_json::from_str(&local_var_content).map_err(Error::from)
304    } else {
305        let local_var_entity: Option<ListNotificationError> = serde_json::from_str(&local_var_content).ok();
306        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
307        Err(Error::ResponseError(local_var_error))
308    }
309}
310