twilio_rust_openapi/apis/
api20100401_user_defined_message_subscription_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 [`create_user_defined_message_subscription`]
18#[derive(Clone, Debug)]
19pub struct CreateUserDefinedMessageSubscriptionParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that subscribed to the User Defined Messages.
21    pub account_sid: String,
22    /// The SID of the [Call](https://www.twilio.com/docs/voice/api/call-resource) the User Defined Messages subscription is associated with. This refers to the Call SID that is producing the user defined messages.
23    pub call_sid: String,
24    /// The URL we should call using the `method` to send user defined events to your application. URLs must contain a valid hostname (underscores are not permitted).
25    pub callback: String,
26    /// A unique string value to identify API call. This should be a unique string value per API call and can be a randomly generated.
27    pub idempotency_key: Option<String>,
28    /// The HTTP method Twilio will use when requesting the above `Url`. Either `GET` or `POST`. Default is `POST`.
29    pub method: Option<String>
30}
31
32/// struct for passing parameters to the method [`delete_user_defined_message_subscription`]
33#[derive(Clone, Debug)]
34pub struct DeleteUserDefinedMessageSubscriptionParams {
35    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that subscribed to the User Defined Messages.
36    pub account_sid: String,
37    /// The SID of the [Call](https://www.twilio.com/docs/voice/api/call-resource) the User Defined Message Subscription is associated with. This refers to the Call SID that is producing the User Defined Messages.
38    pub call_sid: String,
39    /// The SID that uniquely identifies this User Defined Message Subscription.
40    pub sid: String
41}
42
43
44/// struct for typed errors of method [`create_user_defined_message_subscription`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum CreateUserDefinedMessageSubscriptionError {
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`delete_user_defined_message_subscription`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum DeleteUserDefinedMessageSubscriptionError {
55    UnknownValue(serde_json::Value),
56}
57
58
59/// Subscribe to User Defined Messages for a given Call SID.
60pub async fn create_user_defined_message_subscription(configuration: &configuration::Configuration, params: CreateUserDefinedMessageSubscriptionParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCallPeriodUserDefinedMessageSubscription, Error<CreateUserDefinedMessageSubscriptionError>> {
61    let local_var_configuration = configuration;
62
63    // unbox the parameters
64    let account_sid = params.account_sid;
65    let call_sid = params.call_sid;
66    let callback = params.callback;
67    let idempotency_key = params.idempotency_key;
68    let method = params.method;
69
70
71    let local_var_client = &local_var_configuration.client;
72
73    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CallSid=crate::apis::urlencode(call_sid));
74    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
75
76    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
77        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
78    }
79    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
80        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
81    };
82    let mut local_var_form_params = std::collections::HashMap::new();
83    local_var_form_params.insert("Callback", callback.to_string());
84    if let Some(local_var_param_value) = idempotency_key {
85        local_var_form_params.insert("IdempotencyKey", local_var_param_value.to_string());
86    }
87    if let Some(local_var_param_value) = method {
88        local_var_form_params.insert("Method", local_var_param_value.to_string());
89    }
90    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
91
92    let local_var_req = local_var_req_builder.build()?;
93    let local_var_resp = local_var_client.execute(local_var_req).await?;
94
95    let local_var_status = local_var_resp.status();
96    let local_var_content = local_var_resp.text().await?;
97
98    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
99        serde_json::from_str(&local_var_content).map_err(Error::from)
100    } else {
101        let local_var_entity: Option<CreateUserDefinedMessageSubscriptionError> = serde_json::from_str(&local_var_content).ok();
102        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
103        Err(Error::ResponseError(local_var_error))
104    }
105}
106
107/// Delete a specific User Defined Message Subscription.
108pub async fn delete_user_defined_message_subscription(configuration: &configuration::Configuration, params: DeleteUserDefinedMessageSubscriptionParams) -> Result<(), Error<DeleteUserDefinedMessageSubscriptionError>> {
109    let local_var_configuration = configuration;
110
111    // unbox the parameters
112    let account_sid = params.account_sid;
113    let call_sid = params.call_sid;
114    let sid = params.sid;
115
116
117    let local_var_client = &local_var_configuration.client;
118
119    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), CallSid=crate::apis::urlencode(call_sid), Sid=crate::apis::urlencode(sid));
120    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
121
122    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
123        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
124    }
125    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
126        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
127    };
128
129    let local_var_req = local_var_req_builder.build()?;
130    let local_var_resp = local_var_client.execute(local_var_req).await?;
131
132    let local_var_status = local_var_resp.status();
133    let local_var_content = local_var_resp.text().await?;
134
135    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
136        Ok(())
137    } else {
138        let local_var_entity: Option<DeleteUserDefinedMessageSubscriptionError> = serde_json::from_str(&local_var_content).ok();
139        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
140        Err(Error::ResponseError(local_var_error))
141    }
142}
143