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
use super::{format_xml_string, Action, Method, Play, Say}; use std::default::Default; pub enum Prompt { Nothing, Play(Play), Say(Say), } pub struct Gather { pub action: Option<String>, pub method: Method, pub timeout_seconds: u32, pub finish_on_key: char, pub num_digits: Option<u32>, pub prompt: Prompt, } impl Action for Gather { fn as_twiml(&self) -> String { let timeout_string = format!("{}", self.timeout_seconds); let finish_string = self.finish_on_key.to_string(); let digits_string = self.num_digits.map(|d| format!("{}", d)); let mut attrs = Vec::new(); let method_str = match self.method { Method::Get => "GET", Method::Post => "POST", }; attrs.push(("method", method_str)); if let Some(ref a) = self.action { attrs.push(("action", a)); } attrs.push(("timeout", timeout_string.as_ref())); attrs.push(("finishOnKey", finish_string.as_ref())); if let Some(ref d) = digits_string { attrs.push(("numDigits", d.as_ref())); } let inner = match self.prompt { Prompt::Nothing => "".to_string(), Prompt::Play(ref p) => p.as_twiml(), Prompt::Say(ref s) => s.as_twiml(), }; format_xml_string("Gather", &attrs, inner.as_ref()) } } impl Default for Gather { fn default() -> Gather { Gather { action: None, method: Method::Post, timeout_seconds: 5, finish_on_key: '*', num_digits: None, prompt: Prompt::Nothing, } } }