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



90
91
92
# File 'lib/vonage/voice/actions/conversation.rb', line 90

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vonage/voice/actions/conversation.rb', line 94

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:



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

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:



77
78
79
# File 'lib/vonage/voice/actions/conversation.rb', line 77

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:



69
70
71
# File 'lib/vonage/voice/actions/conversation.rb', line 69

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

def verify_music_on_hold_url
  music_on_hold_url = self.musicOnHoldUrl

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

  uri = URI.parse(music_on_hold_url[0])

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

  self.musicOnHoldUrl
end

#verify_muteObject

Raises:



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

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:



73
74
75
# File 'lib/vonage/voice/actions/conversation.rb', line 73

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:



65
66
67
# File 'lib/vonage/voice/actions/conversation.rb', line 65

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