Class: Voice::Actions::Talk

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Talk

Returns a new instance of Talk.



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

def initialize(attributes= {})
  @text = attributes.fetch(:text)
  @bargeIn = attributes.fetch(:bargeIn, nil)
  @loop = attributes.fetch(:loop, nil)
  @level = attributes.fetch(:level, nil)
  @language = attributes.fetch(:language, nil)
  @style = attributes.fetch(:style, nil)
  @premium = attributes.fetch(:premium, nil)
  @provider = attributes.fetch(:provider, nil)
  @providerOptions = attributes.fetch(:providerOptions, nil)

  after_initialize!
end

Instance Attribute Details

#bargeInObject

Returns the value of attribute bargeIn.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def bargeIn
  @bargeIn
end

#languageObject

Returns the value of attribute language.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def language
  @language
end

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def level
  @level
end

#loopObject

Returns the value of attribute loop.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def loop
  @loop
end

#premiumObject

Returns the value of attribute premium.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def premium
  @premium
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def provider
  @provider
end

#providerOptionsObject

Returns the value of attribute providerOptions.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def providerOptions
  @providerOptions
end

#styleObject

Returns the value of attribute style.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def style
  @style
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/vonage/voice/actions/talk.rb', line 5

def text
  @text
end

Instance Method Details

#actionObject



74
75
76
# File 'lib/vonage/voice/actions/talk.rb', line 74

def action
  create_talk!(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
# File 'lib/vonage/voice/actions/talk.rb', line 21

def after_initialize!
  if self.bargeIn || self.bargeIn == false
    verify_barge_in
  end

  if self.loop
    verify_loop
  end

  if self.level
    verify_level
  end

  if self.style
    verify_style
  end

  if self.premium || self.premium == false
    verify_premium
  end

  if self.provider
    verify_provider
  end
end

#create_talk!(builder) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/vonage/voice/actions/talk.rb', line 78

def create_talk!(builder)
  ncco = [
    {
      action: 'talk',
      text: builder.text
    }
  ]

  ncco[0].merge!(bargeIn: builder.bargeIn) if (builder.bargeIn || builder.bargeIn == false)
  ncco[0].merge!(loop: builder.loop) if builder.loop
  ncco[0].merge!(level: builder.level) if builder.level
  ncco[0].merge!(language: builder.language) if builder.language
  ncco[0].merge!(style: builder.style) if builder.style
  ncco[0].merge!(premium: builder.premium) if (builder.premium || builder.premium == false)
  ncco[0].merge!(provider: builder.provider) if builder.provider
  ncco[0].merge!(providerOptions: builder.providerOptions) if builder.providerOptions

  ncco
end

#verify_barge_inObject

Raises:



47
48
49
# File 'lib/vonage/voice/actions/talk.rb', line 47

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

#verify_levelObject

Raises:



55
56
57
# File 'lib/vonage/voice/actions/talk.rb', line 55

def verify_level
  raise ClientError.new("Expected 'level' value to be a number between -1 and 1") unless self.level.between?(-1, 1)
end

#verify_loopObject

Raises:



51
52
53
# File 'lib/vonage/voice/actions/talk.rb', line 51

def verify_loop
  raise ClientError.new("Expected 'loop' value to be either 0 or a positive integer") unless self.loop >= 0
end

#verify_premiumObject

Raises:



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

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

#verify_providerObject

Raises:



67
68
69
70
71
72
# File 'lib/vonage/voice/actions/talk.rb', line 67

def verify_provider
  valid_providers = ['google']

  raise ClientError.new("Invalid 'provider' value, must be one of: #{valid_providers.join(', ')}") unless valid_providers.include?(self.provider)
  raise ClientError.new("The `providerOptions` parameter is required when specifying a `provider`") unless self.providerOptions
end

#verify_styleObject

Raises:



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

def verify_style
  raise ClientError.new("Expected 'style' value to be an Integer") unless self.style.is_a?(Integer)
end