twilio_rust_openapi/apis/
api20100401_media_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 [`delete_media`]
18#[derive(Clone, Debug)]
19pub struct DeleteMediaParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that is associated with the Media resource.
21    pub account_sid: String,
22    /// The SID of the Message resource that is associated with the Media resource.
23    pub message_sid: String,
24    /// The unique identifier of the to-be-deleted Media resource.
25    pub sid: String
26}
27
28/// struct for passing parameters to the method [`fetch_media`]
29#[derive(Clone, Debug)]
30pub struct FetchMediaParams {
31    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) associated with the Media resource.
32    pub account_sid: String,
33    /// The SID of the Message resource that is associated with the Media resource.
34    pub message_sid: String,
35    /// The Twilio-provided string that uniquely identifies the Media resource to fetch.
36    pub sid: String
37}
38
39/// struct for passing parameters to the method [`list_media`]
40#[derive(Clone, Debug)]
41pub struct ListMediaParams {
42    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that is associated with the Media resources.
43    pub account_sid: String,
44    /// The SID of the Message resource that is associated with the Media resources.
45    pub message_sid: String,
46    /// Only include Media resources that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read Media that were created on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read Media that were created on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read Media that were created on or after midnight of this date.
47    pub date_created: Option<String>,
48    /// Only include Media resources that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read Media that were created on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read Media that were created on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read Media that were created on or after midnight of this date.
49    pub date_created_less_than: Option<String>,
50    /// Only include Media resources that were created on this date. Specify a date as `YYYY-MM-DD` in GMT, for example: `2009-07-06`, to read Media that were created on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read Media that were created on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read Media that were created on or after midnight of this date.
51    pub date_created_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
61/// struct for typed errors of method [`delete_media`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum DeleteMediaError {
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`fetch_media`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum FetchMediaError {
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`list_media`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum ListMediaError {
79    UnknownValue(serde_json::Value),
80}
81
82
83/// Delete the Media resource.
84pub async fn delete_media(configuration: &configuration::Configuration, params: DeleteMediaParams) -> Result<(), Error<DeleteMediaError>> {
85    let local_var_configuration = configuration;
86
87    // unbox the parameters
88    let account_sid = params.account_sid;
89    let message_sid = params.message_sid;
90    let sid = params.sid;
91
92
93    let local_var_client = &local_var_configuration.client;
94
95    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), MessageSid=crate::apis::urlencode(message_sid), Sid=crate::apis::urlencode(sid));
96    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
97
98    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100    }
101    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
102        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
103    };
104
105    let local_var_req = local_var_req_builder.build()?;
106    let local_var_resp = local_var_client.execute(local_var_req).await?;
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        Ok(())
113    } else {
114        let local_var_entity: Option<DeleteMediaError> = 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/// Fetch a single Media resource associated with a specific Message resource
121pub async fn fetch_media(configuration: &configuration::Configuration, params: FetchMediaParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodMessagePeriodMedia, Error<FetchMediaError>> {
122    let local_var_configuration = configuration;
123
124    // unbox the parameters
125    let account_sid = params.account_sid;
126    let message_sid = params.message_sid;
127    let sid = params.sid;
128
129
130    let local_var_client = &local_var_configuration.client;
131
132    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), MessageSid=crate::apis::urlencode(message_sid), Sid=crate::apis::urlencode(sid));
133    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
134
135    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
139        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
140    };
141
142    let local_var_req = local_var_req_builder.build()?;
143    let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145    let local_var_status = local_var_resp.status();
146    let local_var_content = local_var_resp.text().await?;
147
148    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
149        serde_json::from_str(&local_var_content).map_err(Error::from)
150    } else {
151        let local_var_entity: Option<FetchMediaError> = serde_json::from_str(&local_var_content).ok();
152        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
153        Err(Error::ResponseError(local_var_error))
154    }
155}
156
157/// Read a list of Media resources associated with a specific Message resource
158pub async fn list_media(configuration: &configuration::Configuration, params: ListMediaParams) -> Result<models::ListMediaResponse, Error<ListMediaError>> {
159    let local_var_configuration = configuration;
160
161    // unbox the parameters
162    let account_sid = params.account_sid;
163    let message_sid = params.message_sid;
164    let date_created = params.date_created;
165    let date_created_less_than = params.date_created_less_than;
166    let date_created_greater_than = params.date_created_greater_than;
167    let page_size = params.page_size;
168    let page = params.page;
169    let page_token = params.page_token;
170
171
172    let local_var_client = &local_var_configuration.client;
173
174    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), MessageSid=crate::apis::urlencode(message_sid));
175    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
176
177    if let Some(ref local_var_str) = date_created {
178        local_var_req_builder = local_var_req_builder.query(&[("DateCreated", &local_var_str.to_string())]);
179    }
180    if let Some(ref local_var_str) = date_created_less_than {
181        local_var_req_builder = local_var_req_builder.query(&[("DateCreated<", &local_var_str.to_string())]);
182    }
183    if let Some(ref local_var_str) = date_created_greater_than {
184        local_var_req_builder = local_var_req_builder.query(&[("DateCreated>", &local_var_str.to_string())]);
185    }
186    if let Some(ref local_var_str) = page_size {
187        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
188    }
189    if let Some(ref local_var_str) = page {
190        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
191    }
192    if let Some(ref local_var_str) = page_token {
193        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
194    }
195    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
196        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
197    }
198    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
199        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
200    };
201
202    let local_var_req = local_var_req_builder.build()?;
203    let local_var_resp = local_var_client.execute(local_var_req).await?;
204
205    let local_var_status = local_var_resp.status();
206    let local_var_content = local_var_resp.text().await?;
207
208    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
209        serde_json::from_str(&local_var_content).map_err(Error::from)
210    } else {
211        let local_var_entity: Option<ListMediaError> = serde_json::from_str(&local_var_content).ok();
212        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
213        Err(Error::ResponseError(local_var_error))
214    }
215}
216