Class: Voice::Actions::Conversation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Conversation

Returns a new instance of Conversation.



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

def initialize(attributes = {})
  @name = attributes.fetch(:name)
  @musicOnHoldUrl = attributes.fetch(:musicOnHoldUrl, nil)
  @startOnEnter = attributes.fetch(:startOnEnter, nil)
  @endOnExit = attributes.fetch(:endOnExit, nil)
  @record = attributes.fetch(:record, nil)
  @canSpeak = attributes.fetch(:canSpeak, nil)
  @canHear = attributes.fetch(:canHear, nil)
  @mute = attributes.fetch(:mute, nil)

  after_initialize!
end

Instance Attribute Details

#canHearObject

Returns the value of attribute canHear.



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

def canHear
  @canHear
end

#canSpeakObject

Returns the value of attribute canSpeak.



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

def canSpeak
  @canSpeak
end

#endOnExitObject

Returns the value of attribute endOnExit.



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

def endOnExit
  @endOnExit
end

#musicOnHoldUrlObject

Returns the value of attribute musicOnHoldUrl.



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

def musicOnHoldUrl
  @musicOnHoldUrl
end

#muteObject

Returns the value of attribute mute.



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

def mute
  @mute
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#recordObject

Returns the value of attribute record.



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

def record
  @record
end

#startOnEnterObject

Returns the value of attribute startOnEnter.



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

def startOnEnter
  @startOnEnter
end

Instance Method Details

#actionObject



84
85
86
# File 'lib/vonage/voice/actions/conversation.rb', line 84

def action
  create_conversation!(self)
end

#after_initialize!Object



21
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
# File 'lib/vonage/voice/actions/conversation.rb', line 21

def after_initialize!
  if self.musicOnHoldUrl
    verify_music_on_hold_url
  end

  if self.startOnEnter
    verify_start_on_enter
  end

  if self.endOnExit
    verify_end_on_exit
  end

  if self.record
    verify_record
  end

  if self.canSpeak
    verify_can_speak
  end

  if self.canHear
    verify_can_hear
  end

  if self.mute
    verify_mute
  end
end

#create_conversation!(builder) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vonage/voice/actions/conversation.rb', line 88

def create_conversation!(builder)
  ncco = [
    {
      action: 'conversation',
      name: builder.name
    }
  ]

  ncco[0].merge!(musicOnHoldUrl: builder.musicOnHoldUrl) if (builder.musicOnHoldUrl || builder.musicOnHoldUrl == false)
  ncco[0].merge!(startOnEnter: builder.startOnEnter) if (builder.startOnEnter || builder.startOnEnter == false)
  ncco[0].merge!(endOnExit: builder.endOnExit) if (builder.endOnExit || builder.endOnExit == false)
  ncco[0].merge!(record: builder.record) if builder.record
  ncco[0].merge!(canSpeak: builder.canSpeak) if builder.canSpeak
  ncco[0].merge!(canHear: builder.canHear) if builder.canHear
  ncco[0].merge!(mute: builder.mute) if builder.mute

  ncco
end

#verify_can_hearObject

Raises:



75
76
77
# File 'lib/vonage/voice/actions/conversation.rb', line 75

def verify_can_hear
  raise ClientError.new("Expected 'canHear' value to be an Array of leg UUIDs") unless self.canHear.is_a?(Array)
end

#verify_can_speakObject

Raises:



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

def verify_can_speak
  raise ClientError.new("Expected 'canSpeak' value to be an Array of leg UUIDs") unless self.canSpeak.is_a?(Array)
end

#verify_end_on_exitObject

Raises:



63
64
65
# File 'lib/vonage/voice/actions/conversation.rb', line 63

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

#verify_music_on_hold_urlObject

Raises:



51
52
53
54
55
56
57
# File 'lib/vonage/voice/actions/conversation.rb', line 51

def verify_music_on_hold_url
  uri = URI.parse(self.musicOnHoldUrl)

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

  self.musicOnHoldUrl
end

#verify_muteObject

Raises:



79
80
81
82
# File 'lib/vonage/voice/actions/conversation.rb', line 79

def verify_mute
  raise ClientError.new("Expected 'mute' value to be a Boolean") unless self.mute == true || self.mute == false
  raise ClientError.new("The 'mute' value is not supported if the 'canSpeak' option is defined") if self.canSpeak
end

#verify_recordObject

Raises:



67
68
69
# File 'lib/vonage/voice/actions/conversation.rb', line 67

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

#verify_start_on_enterObject

Raises:



59
60
61
# File 'lib/vonage/voice/actions/conversation.rb', line 59

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