twilio_openapi/models/
twiml.rs1pub struct Twiml {
2 body: String,
3}
4
5impl Twiml {
6 pub fn new() -> Twiml {
7 Twiml {
8 body: "".to_string(),
9 }
10 }
11 pub fn add(&mut self, a: &Message) -> &mut Twiml {
12 let twiml = a.as_twiml();
13 self.body.push_str((&twiml as &dyn AsRef<str>).as_ref());
14 self
15 }
16 pub fn as_twiml(&self) -> String {
17 let b: &str = self.body.as_ref();
18 format!(
19 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Response>{}</Response>",
20 b
21 )
22 }
23}
24
25fn format_xml_string(tag: &str, attributes: &[(&str, &str)], inner: &str) -> String {
26 let attribute_string = match attributes.len() {
27 0 => "".to_string(),
28 _ => attributes
29 .iter()
30 .map(|t| format!("{}=\"{}\"", t.0, t.1))
31 .fold("".to_string(), |mut acc, v| {
32 acc.push_str(" ");
33 acc.push_str(&v);
34 acc
35 }),
36 };
37 let attribute_str: &str = attribute_string.as_ref();
38 format!("<{}{}>{}</{}>", tag, attribute_str, inner, tag)
39}
40
41pub enum Method {
42 Get,
43 Post,
44}
45
46pub struct Message {
47 pub txt: String,
48}
49
50impl Message {
51 fn as_twiml(&self) -> String {
52 format_xml_string("Message", &vec![], &self.txt)
53 }
54}