1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use super::{Execute, Twilio, TwilioErr, TwilioJson, TwilioRequest, TwilioResp};
use async_trait::async_trait;
use hyper::{self, Method};
use serde::Deserialize;

#[derive(Debug, Default)]
pub struct Recording<'a> {
    sid: &'a str,
}

impl<'a> Recording<'a> {
    pub fn new(sid: &'a str) -> Recording<'a> {
        Recording { sid }
    }
}

// GET ONE Recording
#[derive(Debug)]
pub struct GetRecording<'a> {
    pub recording: Recording<'a>,
    pub client: &'a Twilio,
}

execute!(GetRecording);

#[async_trait]
impl<'a> TwilioRequest for GetRecording<'a> {
    type Resp = RecordingResp;

    async fn run(&self) -> TwilioResp<TwilioJson<Self::Resp>> {
        let url = format!("Recordings/{}.json", self.recording.sid);
        self.execute(Method::GET, url, None).await
    }
}

impl<'a> GetRecording<'a> {
    pub async fn delete(&self) -> TwilioResp<TwilioJson<Option<bool>>> {
        let url = format!("Recordings/{}.json", self.recording.sid);
        self.execute(Method::DELETE, url, None).await
    }
}

// GET ALL RECORDINGS
#[derive(Debug)]
pub struct Recordings<'a> {
    pub client: &'a Twilio,
}

execute!(Recordings);

#[async_trait]
impl<'a> TwilioRequest for Recordings<'a> {
    type Resp = ListRecordingResp;

    async fn run(&self) -> TwilioResp<TwilioJson<Self::Resp>> {
        self.execute(Method::GET, "Recordings.json", None).await
    }
}

impl<'a> Recordings<'a> {
    pub async fn for_call(&self, call_sid: &'a str) -> TwilioResp<TwilioJson<ListRecordingResp>> {
        let url = format!("Recordings.json?CallSid={}", call_sid);
        self.execute(Method::GET, url, None).await
    }

    pub async fn created(
        &self,
        date_created: &'a str,
    ) -> TwilioResp<TwilioJson<ListRecordingResp>> {
        let url = format!("Recordings.json?DateCreated={}", date_created);
        self.execute(Method::GET, url, None).await
    }

    pub async fn range(
        &self,
        before: &'a str,
        after: &'a str,
    ) -> TwilioResp<TwilioJson<ListRecordingResp>> {
        let url = format!(
            "Recordings.json?DateCreatedBefore={}&DateCreatedAfter={}",
            before, after
        );
        self.execute(Method::GET, url, None).await
    }
}

#[derive(Deserialize, Debug)]
pub struct ListRecordingResp {
    pub recordings: Vec<RecordingResp>,
    pub end: usize,
    pub account_sid: String,
    pub start: usize,
    pub page: usize,
    pub page_size: usize,
}

#[derive(Deserialize, Debug)]
pub struct RecordingResp {
    pub account_sid: String,
    pub call_sid: String,
    pub channels: String,
    pub conference_sid: String,
    pub date_created: String,
    pub date_updated: String,
    pub end_time: String,
    pub start_time: String,
    pub price: String,
    pub price_unit: String,
    pub duration: String,
    pub encryption_details: EncryptionDetails,
    pub error_code: String,
    pub uri: String,
    pub status: RecordingStatus,
}

#[derive(Deserialize, Debug)]
pub struct EncryptionDetails {
    pub encryption_public_key_sid: String,
    pub encryption_cek: String,
    pub encryption_iv: String,
}

#[derive(Deserialize, Debug)]
#[allow(non_camel_case_types)]
pub enum RecordingStatus {
    #[serde(rename = "in-progress")]
    inprogress,
    paused,
    stopped,
    processing,
    completed,
    failed,
}