Class: Voice::Actions::Input
- Inherits:
-
Object
- Object
- Voice::Actions::Input
- Defined in:
- lib/vonage/voice/actions/input.rb
Instance Attribute Summary collapse
-
#dtmf ⇒ Object
Returns the value of attribute dtmf.
-
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
-
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#speech ⇒ Object
Returns the value of attribute speech.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #action ⇒ Object
- #after_initialize! ⇒ Object
- #create_input!(builder) ⇒ Object
-
#initialize(attributes = {}) ⇒ Input
constructor
A new instance of Input.
- #validate_dtmf ⇒ Object
- #validate_event_method ⇒ Object
- #validate_event_url ⇒ Object
- #validate_mode ⇒ Object
- #validate_speech ⇒ Object
- #validate_type ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Input
Returns a new instance of Input.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vonage/voice/actions/input.rb', line 8 def initialize(attributes = {}) @type = attributes.fetch(:type) @dtmf = attributes.fetch(:dtmf, nil) @speech = attributes.fetch(:speech, nil) @eventUrl = attributes.fetch(:eventUrl, nil) @eventMethod = attributes.fetch(:eventMethod, nil) @mode = attributes.fetch(:mode, nil) after_initialize! end |
Instance Attribute Details
#dtmf ⇒ Object
Returns the value of attribute dtmf.
6 7 8 |
# File 'lib/vonage/voice/actions/input.rb', line 6 def dtmf @dtmf end |
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
6 7 8 |
# File 'lib/vonage/voice/actions/input.rb', line 6 def eventMethod @eventMethod end |
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
6 7 8 |
# File 'lib/vonage/voice/actions/input.rb', line 6 def eventUrl @eventUrl end |
#mode ⇒ Object
Returns the value of attribute mode.
6 7 8 |
# File 'lib/vonage/voice/actions/input.rb', line 6 def mode @mode end |
#speech ⇒ Object
Returns the value of attribute speech.
6 7 8 |
# File 'lib/vonage/voice/actions/input.rb', line 6 def speech @speech end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/vonage/voice/actions/input.rb', line 6 def type @type end |
Instance Method Details
#action ⇒ Object
121 122 123 |
# File 'lib/vonage/voice/actions/input.rb', line 121 def action create_input!(self) end |
#after_initialize! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vonage/voice/actions/input.rb', line 19 def after_initialize! validate_type if self.dtmf validate_dtmf end if self.speech validate_speech end if self.eventUrl validate_event_url end if self.eventMethod validate_event_method end if self.mode validate_mode end end |
#create_input!(builder) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vonage/voice/actions/input.rb', line 125 def create_input!(builder) ncco = [ { action: 'input', type: builder.type } ] ncco[0].merge!(dtmf: builder.dtmf) if builder.dtmf ncco[0].merge!(speech: builder.speech) if builder.speech ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod ncco[0].merge!(mode: builder.mode) if builder.mode ncco end |
#validate_dtmf ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vonage/voice/actions/input.rb', line 50 def validate_dtmf raise ClientError.new("Expected 'dtmf' to be included in 'type' parameter if 'dtmf' options specified") unless self.type.include?('dtmf') if self.dtmf[:timeOut] raise ClientError.new("Expected 'timeOut' to not be more than 10 seconds") if self.dtmf[:timeOut] > 10 end if self.dtmf[:maxDigits] raise ClientError.new("Expected 'maxDigits' to not be more than 22") if self.dtmf[:maxDigits] > 22 end if self.dtmf[:submitOnHash] raise ClientError.new("Invalid 'submitOnHash' value, must be a Boolean") unless self.dtmf[:submitOnHash] == true || self.dtmf[:submitOnHash] == false end end |
#validate_event_method ⇒ Object
109 110 111 112 113 |
# File 'lib/vonage/voice/actions/input.rb', line 109 def validate_event_method valid_methods = ['GET', 'POST'] raise ClientError.new("Invalid 'eventMethod' value. must be either: 'GET' or 'POST'") unless valid_methods.include?(self.eventMethod.upcase) end |
#validate_event_url ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/vonage/voice/actions/input.rb', line 97 def validate_event_url unless self.eventUrl.is_a?(Array) && self.eventUrl.length == 1 && self.eventUrl[0].is_a?(String) raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item") end uri = URI.parse(self.eventUrl[0]) raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS) self.eventUrl end |
#validate_mode ⇒ Object
115 116 117 118 119 |
# File 'lib/vonage/voice/actions/input.rb', line 115 def validate_mode valid_modes = ['asyncronous'] raise ClientError.new("Invalid 'mode' value, must be asyncronous'") unless valid_modes.include?(self.mode) end |
#validate_speech ⇒ Object
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 |
# File 'lib/vonage/voice/actions/input.rb', line 66 def validate_speech raise ClientError.new("Expected 'speech' to be included in 'type' parameter if 'speech' options specified") unless self.type.include?('speech') if self.speech[:uuid] raise ClientError.new("Invalid 'uuid' value, must be an Array containing a single call leg ID element") unless self.speech[:uuid].is_a?(Array) end if self.speech[:endOnSilence] raise ClientError.new("Expected 'endOnSilence' to not be more than 10 seconds") unless self.speech[:endOnSilence] <= 10 && self.speech[:endOnSilence] >= 0 end if self.speech[:context] raise ClientError.new("Expected 'context' to be an Array of strings") unless self.speech[:context].is_a?(Array) end if self.speech[:startTimeout] raise ClientError.new("Expected 'startTimeout' to not be more than 10 seconds") unless self.speech[:startTimeout] <= 10 && self.speech[:startTimeout] >= 0 end if self.speech[:maxDuration] raise ClientError.new("Expected 'maxDuration' to not be more than 60 seconds") unless self.speech[:maxDuration] <= 60 && self.speech[:maxDuration] >= 0 end if self.speech[:provider] valid_providers = ['google'] raise ClientError.new("Invalid 'provider' value, must be one of: #{valid_providers.join(', ')}") unless valid_providers.include?(self.speech[:provider]) raise ClientError.new("The `providerOptions` parameter is required when specifying a `provider`") unless self.speech[:providerOptions] end end |
#validate_type ⇒ Object
43 44 45 46 47 48 |
# File 'lib/vonage/voice/actions/input.rb', line 43 def validate_type valid_types = ['dtmf', 'speech'] raise ClientError.new("Invalid 'type', must be an Array of at least one String") unless self.type.is_a?(Array) raise ClientError.new("Invalid 'type' value, must be 'dtmf', 'speech' or both 'dtmf' and 'speech'") if (valid_types & self.type).empty? end |