Class: Voice::Actions::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/vonage/voice/actions/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Record

Returns a new instance of Record.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vonage/voice/actions/record.rb', line 8

def initialize(attributes = {})
  @format = attributes.fetch(:format, nil)
  @split = attributes.fetch(:split, nil)
  @channels = attributes.fetch(:channels, nil)
  @endOnSilence = attributes.fetch(:endOnSilence, nil)
  @endOnKey = attributes.fetch(:endOnKey, nil)
  @timeOut = attributes.fetch(:timeOut, nil)
  @beepStart = attributes.fetch(:beepStart, nil)
  @eventUrl = attributes.fetch(:eventUrl, nil)
  @eventMethod = attributes.fetch(:eventMethod, nil)
  @transcription = attributes.fetch(:transcription, nil)

  after_initialize!
end

Instance Attribute Details

#beepStartObject

Returns the value of attribute beepStart.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def beepStart
  @beepStart
end

#channelsObject

Returns the value of attribute channels.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def channels
  @channels
end

#endOnKeyObject

Returns the value of attribute endOnKey.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def endOnKey
  @endOnKey
end

#endOnSilenceObject

Returns the value of attribute endOnSilence.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def endOnSilence
  @endOnSilence
end

#eventMethodObject

Returns the value of attribute eventMethod.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def eventMethod
  @eventMethod
end

#eventUrlObject

Returns the value of attribute eventUrl.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def eventUrl
  @eventUrl
end

#formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def format
  @format
end

#splitObject

Returns the value of attribute split.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def split
  @split
end

#timeOutObject

Returns the value of attribute timeOut.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def timeOut
  @timeOut
end

#transcriptionObject

Returns the value of attribute transcription.



6
7
8
# File 'lib/vonage/voice/actions/record.rb', line 6

def transcription
  @transcription
end

Instance Method Details

#actionObject



153
154
155
# File 'lib/vonage/voice/actions/record.rb', line 153

def action
  create_record!(self)
end

#after_initialize!Object



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
59
60
61
62
63
# File 'lib/vonage/voice/actions/record.rb', line 23

def after_initialize!
  if self.format
    validate_format
  end

  if self.split
    validate_split
  end

  if self.channels
    validate_channels
  end

  if self.endOnSilence
    validate_end_on_silence
  end

  if self.endOnKey
    validate_end_on_key
  end

  if self.timeOut
    validate_time_out
  end

  if self.beepStart
    validate_beep_start
  end

  if self.eventUrl
    validate_event_url
  end

  if self.eventMethod
    validate_event_method
  end

  if self.transcription
    validate_transcription
  end
end

#create_record!(builder) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vonage/voice/actions/record.rb', line 157

def create_record!(builder)
  ncco = [
    {
      action: 'record'
    }
  ]

  ncco[0].merge!(format: builder.format) if builder.format
  ncco[0].merge!(split: builder.split) if builder.split
  ncco[0].merge!(channels: builder.channels) if builder.channels
  ncco[0].merge!(endOnSilence: builder.endOnSilence) if builder.endOnSilence
  ncco[0].merge!(endOnKey: builder.endOnKey) if builder.endOnKey
  ncco[0].merge!(timeOut: builder.timeOut) if builder.timeOut
  ncco[0].merge!(beepStart: builder.beepStart) if builder.beepStart
  ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl
  ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod
  ncco[0].merge!(transcription: builder.transcription) if builder.transcription

  ncco
end

#validate_beep_startObject

Raises:



93
94
95
# File 'lib/vonage/voice/actions/record.rb', line 93

def validate_beep_start
  raise ClientError.new("Expected 'beepStart' value to be a Boolean") unless self.beepStart == true || self.beepStart == false
end

#validate_channelsObject

Raises:



75
76
77
78
79
# File 'lib/vonage/voice/actions/record.rb', line 75

def validate_channels
  raise ClientError.new("The 'split' parameter must be defined to 'conversation' to also define 'channels'") unless self.split

  raise ClientError.new("Expected 'split' parameter to be equal to or less than 32") unless self.channels <= 32
end

#validate_end_on_keyObject

Raises:



85
86
87
# File 'lib/vonage/voice/actions/record.rb', line 85

def validate_end_on_key
  raise ClientError.new("Expected 'endOnKey' value to be a one of the following: a single digit between 1-9, '*' or '#'") unless self.endOnKey.match(/^(\*|[1-9]|\#)$/)
end

#validate_end_on_silenceObject

Raises:



81
82
83
# File 'lib/vonage/voice/actions/record.rb', line 81

def validate_end_on_silence
  raise ClientError.new("Expected 'endOnSilence' value to be between 3 and 10") unless self.endOnSilence <= 10 && self.endOnSilence >= 3
end

#validate_event_methodObject

Raises:



109
110
111
112
113
# File 'lib/vonage/voice/actions/record.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_urlObject

Raises:



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/vonage/voice/actions/record.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_formatObject

Raises:



65
66
67
68
69
# File 'lib/vonage/voice/actions/record.rb', line 65

def validate_format
  valid_formats = ['mp3', 'wav', 'ogg']

  raise ClientError.new("Invalid format, must be one of: 'mp3', 'wav', 'ogg'") unless valid_formats.include?(self.format)
end

#validate_splitObject

Raises:



71
72
73
# File 'lib/vonage/voice/actions/record.rb', line 71

def validate_split
  raise ClientError.new("Expected 'split' value to be 'conversation' if defined") unless self.split == 'conversation'
end

#validate_time_outObject

Raises:



89
90
91
# File 'lib/vonage/voice/actions/record.rb', line 89

def validate_time_out
  raise ClientError.new("Expected 'timeOut' value to be between 3 and 7200 seconds") unless self.timeOut <= 7200 && self.timeOut >= 3
end

#validate_transcriptionObject

Raises:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/vonage/voice/actions/record.rb', line 115

def validate_transcription
  raise ClientError.new("Expected 'transcription' parameter to be a Hash") unless self.transcription.is_a?(Hash)

  if self.transcription[:language]
    raise ClientError.new("Invalid 'language' value, must be a String") unless self.transcription[:language].is_a?(String)
  end

  if self.transcription[:eventUrl]
    event_url = self.transcription[:eventUrl]

    unless event_url.is_a?(Array) && event_url.length == 1 && event_url[0].is_a?(String)
      raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item")
    end

    uri = URI.parse(event_url[0])

    raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
  end

  if self.transcription[:eventMethod]
    event_method = self.transcription[:eventMethod]
    raise ClientError.new("Invalid 'eventMethod' value, must be either: 'GET' or 'POST'") unless ['GET', 'POST'].include?(event_method.upcase)
  end

  if self.transcription[:sentimentAnalysis]
    sentiment_analysis = self.transcription[:sentimentAnalysis]
    raise ClientError.new("Invalid 'sentimentAnalysis' value, must be a Boolean") unless sentiment_analysis == true || sentiment_analysis == false
  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