twilio_async/
recording.rs

1use super::{Execute, Twilio, TwilioErr, TwilioJson, TwilioRequest, TwilioResp};
2use async_trait::async_trait;
3use hyper::{self, Method};
4use serde::Deserialize;
5
6#[derive(Debug, Default)]
7pub struct Recording<'a> {
8    sid: &'a str,
9}
10
11impl<'a> Recording<'a> {
12    pub fn new(sid: &'a str) -> Recording<'a> {
13        Recording { sid }
14    }
15}
16
17// GET ONE Recording
18#[derive(Debug)]
19pub struct GetRecording<'a> {
20    pub recording: Recording<'a>,
21    pub client: &'a Twilio,
22}
23
24execute!(GetRecording);
25
26#[async_trait]
27impl<'a> TwilioRequest for GetRecording<'a> {
28    type Resp = RecordingResp;
29
30    async fn run(&self) -> TwilioResp<TwilioJson<Self::Resp>> {
31        let url = format!("Recordings/{}.json", self.recording.sid);
32        self.execute(Method::GET, url, None).await
33    }
34}
35
36impl<'a> GetRecording<'a> {
37    pub async fn delete(&self) -> TwilioResp<TwilioJson<Option<bool>>> {
38        let url = format!("Recordings/{}.json", self.recording.sid);
39        self.execute(Method::DELETE, url, None).await
40    }
41}
42
43// GET ALL RECORDINGS
44#[derive(Debug)]
45pub struct Recordings<'a> {
46    pub client: &'a Twilio,
47}
48
49execute!(Recordings);
50
51#[async_trait]
52impl<'a> TwilioRequest for Recordings<'a> {
53    type Resp = ListRecordingResp;
54
55    async fn run(&self) -> TwilioResp<TwilioJson<Self::Resp>> {
56        self.execute(Method::GET, "Recordings.json", None).await
57    }
58}
59
60impl<'a> Recordings<'a> {
61    pub async fn for_call(&self, call_sid: &'a str) -> TwilioResp<TwilioJson<ListRecordingResp>> {
62        let url = format!("Recordings.json?CallSid={}", call_sid);
63        self.execute(Method::GET, url, None).await
64    }
65
66    pub async fn created(
67        &self,
68        date_created: &'a str,
69    ) -> TwilioResp<TwilioJson<ListRecordingResp>> {
70        let url = format!("Recordings.json?DateCreated={}", date_created);
71        self.execute(Method::GET, url, None).await
72    }
73
74    pub async fn range(
75        &self,
76        before: &'a str,
77        after: &'a str,
78    ) -> TwilioResp<TwilioJson<ListRecordingResp>> {
79        let url = format!(
80            "Recordings.json?DateCreatedBefore={}&DateCreatedAfter={}",
81            before, after
82        );
83        self.execute(Method::GET, url, None).await
84    }
85}
86
87#[derive(Deserialize, Debug)]
88pub struct ListRecordingResp {
89    pub recordings: Vec<RecordingResp>,
90    pub end: usize,
91    pub account_sid: String,
92    pub start: usize,
93    pub page: usize,
94    pub page_size: usize,
95}
96
97#[derive(Deserialize, Debug)]
98pub struct RecordingResp {
99    pub account_sid: String,
100    pub call_sid: String,
101    pub channels: String,
102    pub conference_sid: String,
103    pub date_created: String,
104    pub date_updated: String,
105    pub end_time: String,
106    pub start_time: String,
107    pub price: String,
108    pub price_unit: String,
109    pub duration: String,
110    pub encryption_details: EncryptionDetails,
111    pub error_code: String,
112    pub uri: String,
113    pub status: RecordingStatus,
114}
115
116#[derive(Deserialize, Debug)]
117pub struct EncryptionDetails {
118    pub encryption_public_key_sid: String,
119    pub encryption_cek: String,
120    pub encryption_iv: String,
121}
122
123#[derive(Deserialize, Debug)]
124#[allow(non_camel_case_types)]
125pub enum RecordingStatus {
126    #[serde(rename = "in-progress")]
127    inprogress,
128    paused,
129    stopped,
130    processing,
131    completed,
132    failed,
133}