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
# 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

#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

Instance Method Details

#actionObject



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_startObject

Raises:



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_channelsObject

Raises:



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_keyObject

Raises:



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_silenceObject

Raises:



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_methodObject

Raises:



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_urlObject

Raises:



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_formatObject

Raises:



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_splitObject

Raises:



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_outObject

Raises:



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