messagebird_async/sms/
recipients.rs1use super::*;
2
3#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
9pub struct Recipients {
10 #[serde(rename = "totalCount")]
11 total_count: u32,
12 #[serde(rename = "totalSentCount")]
13 total_sent: u32,
14 #[serde(rename = "totalDeliveredCount")]
15 total_delivered: u32,
16 #[serde(rename = "totalDeliveryFailedCount")]
17 total_delivery_failed: u32,
18 #[serde(rename = "items")]
19 items: Vec<Recipient>,
20}
21
22impl Default for Recipients {
23 fn default() -> Self {
24 Self {
25 total_count: 0,
26 total_sent: 0,
27 total_delivered: 0,
28 total_delivery_failed: 0,
29 items: Vec::new(),
30 }
31 }
32}
33
34impl Recipients {
35 pub fn count(&self) -> (u32, u32, u32) {
36 (
37 self.total_sent,
38 self.total_delivered,
39 self.total_delivery_failed,
40 )
41 }
42 pub fn iter(&mut self) -> Iter<Recipient> {
43 self.items.iter()
44 }
45 pub fn add(&mut self, recipient: Recipient) {
46 self.items.push(recipient)
47 }
48}
49
50#[cfg(test)]
51mod test {
52 use super::*;
53 static RAW: &str = r#"{
54 "totalCount":1,
55 "totalSentCount":1,
56 "totalDeliveredCount":0,
57 "totalDeliveryFailedCount":0,
58 "items":[
59 {
60 "recipient": 31612345678,
61 "status":"sent",
62 "statusDatetime":"2016-05-03T14:26:57+00:00"
63 }
64 ]
65}"#;
66
67 deser_roundtrip!(recipients_deser, Recipients, RAW);
68 serde_roundtrip!(recipients_serde, Recipients, Recipients::default());
69}