33
44module Vonage
55 class Voice ::Actions ::Record
6- attr_accessor :format , :split , :channels , :endOnSilence , :endOnKey , :timeOut , :beepStart , :eventUrl , :eventMethod
6+ attr_accessor :format , :split , :channels , :endOnSilence , :endOnKey , :timeOut , :beepStart , :eventUrl , :eventMethod , :transcription
77
88 def initialize ( attributes = { } )
99 @format = attributes . fetch ( :format , nil )
@@ -15,6 +15,7 @@ def initialize(attributes = {})
1515 @beepStart = attributes . fetch ( :beepStart , nil )
1616 @eventUrl = attributes . fetch ( :eventUrl , nil )
1717 @eventMethod = attributes . fetch ( :eventMethod , nil )
18+ @transcription = attributes . fetch ( :transcription , nil )
1819
1920 after_initialize!
2021 end
@@ -55,6 +56,10 @@ def after_initialize!
5556 if self . eventMethod
5657 validate_event_method
5758 end
59+
60+ if self . transcription
61+ validate_transcription
62+ end
5863 end
5964
6065 def validate_format
@@ -90,17 +95,59 @@ def validate_beep_start
9095 end
9196
9297 def validate_event_url
93- uri = URI . parse ( self . eventUrl )
98+ unless self . eventUrl . is_a? ( Array ) && self . eventUrl . length == 1 && self . eventUrl [ 0 ] . is_a? ( String )
99+ raise ClientError . new ( "Expected 'eventUrl' parameter to be an Array containing a single string item" )
100+ end
94101
95- raise ClientError . new ( "Invalid 'eventUrl' value, must be a valid URL" ) unless uri . kind_of? ( URI ::HTTP ) || uri . kind_of? ( URI ::HTTPS )
102+ uri = URI . parse ( self . eventUrl [ 0 ] )
103+
104+ raise ClientError . new ( "Invalid 'eventUrl' value, array must contain a valid URL" ) unless uri . kind_of? ( URI ::HTTP ) || uri . kind_of? ( URI ::HTTPS )
96105
97106 self . eventUrl
98107 end
99108
100109 def validate_event_method
101110 valid_methods = [ 'GET' , 'POST' ]
102111
103- raise ClientError . new ( "Invalid 'eventMethod' value. must be either: 'GET' or 'POST'" ) unless valid_methods . include? ( self . eventMethod . upcase )
112+ raise ClientError . new ( "Invalid 'eventMethod' value. Must be either: 'GET' or 'POST'" ) unless valid_methods . include? ( self . eventMethod . upcase )
113+ end
114+
115+ def validate_transcription
116+ raise ClientError . new ( "Expected 'transcription' parameter to be a Hash" ) unless self . transcription . is_a? ( Hash )
117+
118+ if self . transcription [ :language ]
119+ raise ClientError . new ( "Invalid 'language' value, must be a String" ) unless self . transcription [ :language ] . is_a? ( String )
120+ end
121+
122+ if self . transcription [ :eventUrl ]
123+ event_url = self . transcription [ :eventUrl ]
124+
125+ unless event_url . is_a? ( Array ) && event_url . length == 1 && event_url [ 0 ] . is_a? ( String )
126+ raise ClientError . new ( "Expected 'eventUrl' parameter to be an Array containing a single string item" )
127+ end
128+
129+ uri = URI . parse ( event_url [ 0 ] )
130+
131+ raise ClientError . new ( "Invalid 'eventUrl' value, array must contain a valid URL" ) unless uri . kind_of? ( URI ::HTTP ) || uri . kind_of? ( URI ::HTTPS )
132+ end
133+
134+ if self . transcription [ :eventMethod ]
135+ event_method = self . transcription [ :eventMethod ]
136+ raise ClientError . new ( "Invalid 'eventMethod' value, must be either: 'GET' or 'POST'" ) unless [ 'GET' , 'POST' ] . include? ( event_method . upcase )
137+ end
138+
139+ if self . transcription [ :sentimentAnalysis ]
140+ sentiment_analysis = self . transcription [ :sentimentAnalysis ]
141+ raise ClientError . new ( "Invalid 'sentimentAnalysis' value, must be a Boolean" ) unless sentiment_analysis == true || sentiment_analysis == false
142+ end
143+
144+ # if self.dtmf[:maxDigits]
145+ # raise ClientError.new("Expected 'maxDigits' to not be more than 22") if self.dtmf[:maxDigits] > 22
146+ # end
147+
148+ # if self.dtmf[:submitOnHash]
149+ # raise ClientError.new("Invalid 'submitOnHash' value, must be a Boolean") unless self.dtmf[:submitOnHash] == true || self.dtmf[:submitOnHash] == false
150+ # end
104151 end
105152
106153 def action
@@ -123,6 +170,7 @@ def create_record!(builder)
123170 ncco [ 0 ] . merge! ( beepStart : builder . beepStart ) if builder . beepStart
124171 ncco [ 0 ] . merge! ( eventUrl : builder . eventUrl ) if builder . eventUrl
125172 ncco [ 0 ] . merge! ( eventMethod : builder . eventMethod ) if builder . eventMethod
173+ ncco [ 0 ] . merge! ( transcription : builder . transcription ) if builder . transcription
126174
127175 ncco
128176 end
0 commit comments