Class: Voice::Actions::Record
- Inherits:
-
Object
- Object
- Voice::Actions::Record
- Defined in:
- lib/vonage/voice/actions/record.rb
Instance Attribute Summary collapse
-
#beepStart ⇒ Object
Returns the value of attribute beepStart.
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#endOnKey ⇒ Object
Returns the value of attribute endOnKey.
-
#endOnSilence ⇒ Object
Returns the value of attribute endOnSilence.
-
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
-
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
-
#format ⇒ Object
Returns the value of attribute format.
-
#split ⇒ Object
Returns the value of attribute split.
-
#timeOut ⇒ Object
Returns the value of attribute timeOut.
Instance Method Summary collapse
- #action ⇒ Object
- #after_initialize! ⇒ Object
- #create_record!(builder) ⇒ Object
-
#initialize(attributes = {}) ⇒ Record
constructor
A new instance of Record.
- #validate_beep_start ⇒ Object
- #validate_channels ⇒ Object
- #validate_end_on_key ⇒ Object
- #validate_end_on_silence ⇒ Object
- #validate_event_method ⇒ Object
- #validate_event_url ⇒ Object
- #validate_format ⇒ Object
- #validate_split ⇒ Object
- #validate_time_out ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Record
Returns a new instance of Record.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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) after_initialize! end |
Instance Attribute Details
#beepStart ⇒ Object
Returns the value of attribute beepStart.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def beepStart @beepStart end |
#channels ⇒ Object
Returns the value of attribute channels.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def channels @channels end |
#endOnKey ⇒ Object
Returns the value of attribute endOnKey.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def endOnKey @endOnKey end |
#endOnSilence ⇒ Object
Returns the value of attribute endOnSilence.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def endOnSilence @endOnSilence end |
#eventMethod ⇒ Object
Returns the value of attribute eventMethod.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def eventMethod @eventMethod end |
#eventUrl ⇒ Object
Returns the value of attribute eventUrl.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def eventUrl @eventUrl end |
#format ⇒ Object
Returns the value of attribute format.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def format @format end |
#split ⇒ Object
Returns the value of attribute split.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def split @split end |
#timeOut ⇒ Object
Returns the value of attribute timeOut.
6 7 8 |
# File 'lib/vonage/voice/actions/record.rb', line 6 def timeOut @timeOut end |
Instance Method Details
#action ⇒ Object
106 107 108 |
# File 'lib/vonage/voice/actions/record.rb', line 106 def action create_record!(self) end |
#after_initialize! ⇒ Object
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 |
# File 'lib/vonage/voice/actions/record.rb', line 22 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 end |
#create_record!(builder) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vonage/voice/actions/record.rb', line 110 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 end |
#validate_beep_start ⇒ Object
88 89 90 |
# File 'lib/vonage/voice/actions/record.rb', line 88 def validate_beep_start raise ClientError.new("Expected 'beepStart' value to be a Boolean") unless self.beepStart == true || self.beepStart == false end |
#validate_channels ⇒ Object
70 71 72 73 74 |
# File 'lib/vonage/voice/actions/record.rb', line 70 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_key ⇒ Object
80 81 82 |
# File 'lib/vonage/voice/actions/record.rb', line 80 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_silence ⇒ Object
76 77 78 |
# File 'lib/vonage/voice/actions/record.rb', line 76 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_method ⇒ Object
100 101 102 103 104 |
# File 'lib/vonage/voice/actions/record.rb', line 100 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
92 93 94 95 96 97 98 |
# File 'lib/vonage/voice/actions/record.rb', line 92 def validate_event_url uri = URI.parse(self.eventUrl) raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS) self.eventUrl end |
#validate_format ⇒ Object
60 61 62 63 64 |
# File 'lib/vonage/voice/actions/record.rb', line 60 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_split ⇒ Object
66 67 68 |
# File 'lib/vonage/voice/actions/record.rb', line 66 def validate_split raise ClientError.new("Expected 'split' value to be 'conversation' if defined") unless self.split == 'conversation' end |
#validate_time_out ⇒ Object
84 85 86 |
# File 'lib/vonage/voice/actions/record.rb', line 84 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 |