vonage 7.31.0 → 8.0.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +92 -604
  3. data/lib/vonage/applications.rb +4 -12
  4. data/lib/vonage/basic.rb +1 -1
  5. data/lib/vonage/bearer_token.rb +1 -1
  6. data/lib/vonage/client.rb +0 -65
  7. data/lib/vonage/client_error.rb +1 -1
  8. data/lib/vonage/config.rb +1 -4
  9. data/lib/vonage/conversations/events.rb +0 -12
  10. data/lib/vonage/conversations/legs.rb +0 -6
  11. data/lib/vonage/conversations/members.rb +0 -15
  12. data/lib/vonage/conversations/users.rb +0 -15
  13. data/lib/vonage/conversations.rb +0 -30
  14. data/lib/vonage/errors.rb +20 -37
  15. data/lib/vonage/gsm7.rb +1 -1
  16. data/lib/vonage/http.rb +3 -3
  17. data/lib/vonage/jwt.rb +0 -17
  18. data/lib/vonage/key_secret_params.rb +2 -3
  19. data/lib/vonage/keys.rb +1 -15
  20. data/lib/vonage/logger.rb +3 -0
  21. data/lib/vonage/messaging/channels/messenger.rb +0 -2
  22. data/lib/vonage/messaging/channels/mms.rb +3 -13
  23. data/lib/vonage/messaging/channels/sms.rb +0 -2
  24. data/lib/vonage/messaging/channels/viber.rb +2 -11
  25. data/lib/vonage/messaging/channels/whats_app.rb +1 -5
  26. data/lib/vonage/messaging/message.rb +1 -4
  27. data/lib/vonage/messaging.rb +3 -42
  28. data/lib/vonage/namespace.rb +68 -137
  29. data/lib/vonage/number_insight.rb +0 -1
  30. data/lib/vonage/numbers.rb +17 -40
  31. data/lib/vonage/server_error.rb +1 -1
  32. data/lib/vonage/signature.rb +5 -5
  33. data/lib/vonage/sms.rb +20 -23
  34. data/lib/vonage/version.rb +1 -1
  35. data/lib/vonage/video/archives.rb +58 -27
  36. data/lib/vonage/video/list_response.rb +11 -0
  37. data/lib/vonage/video/moderation.rb +22 -7
  38. data/lib/vonage/video/signals.rb +9 -4
  39. data/lib/vonage/video/streams.rb +12 -6
  40. data/lib/vonage/video.rb +13 -50
  41. data/lib/vonage/voice/actions/connect.rb +8 -41
  42. data/lib/vonage/voice/actions/conversation.rb +4 -10
  43. data/lib/vonage/voice/actions/input.rb +3 -19
  44. data/lib/vonage/voice/actions/notify.rb +3 -8
  45. data/lib/vonage/voice/actions/pay.rb +107 -0
  46. data/lib/vonage/voice/actions/record.rb +4 -52
  47. data/lib/vonage/voice/actions/stream.rb +3 -7
  48. data/lib/vonage/voice/actions/talk.rb +4 -14
  49. data/lib/vonage/voice/talk.rb +1 -11
  50. data/lib/vonage/voice.rb +0 -24
  51. data/lib/vonage.rb +0 -4
  52. data/vonage.gemspec +1 -3
  53. metadata +12 -108
  54. data/lib/vonage/api_error.rb +0 -33
  55. data/lib/vonage/conversation/event/list_response.rb +0 -11
  56. data/lib/vonage/conversation/event.rb +0 -108
  57. data/lib/vonage/conversation/list_response.rb +0 -11
  58. data/lib/vonage/conversation/member/list_response.rb +0 -11
  59. data/lib/vonage/conversation/member.rb +0 -134
  60. data/lib/vonage/conversation/user/conversations_list_response.rb +0 -11
  61. data/lib/vonage/conversation/user/sessions_list_response.rb +0 -11
  62. data/lib/vonage/conversation/user.rb +0 -67
  63. data/lib/vonage/conversation.rb +0 -164
  64. data/lib/vonage/meetings/applications.rb +0 -28
  65. data/lib/vonage/meetings/dial_in_numbers/list_response.rb +0 -11
  66. data/lib/vonage/meetings/dial_in_numbers.rb +0 -26
  67. data/lib/vonage/meetings/recordings.rb +0 -42
  68. data/lib/vonage/meetings/rooms/list_response.rb +0 -11
  69. data/lib/vonage/meetings/rooms.rb +0 -167
  70. data/lib/vonage/meetings/sessions/list_response.rb +0 -11
  71. data/lib/vonage/meetings/sessions.rb +0 -31
  72. data/lib/vonage/meetings/themes/list_response.rb +0 -11
  73. data/lib/vonage/meetings/themes.rb +0 -239
  74. data/lib/vonage/meetings.rb +0 -50
  75. data/lib/vonage/messaging/channels/rcs.rb +0 -44
  76. data/lib/vonage/network_authentication/client_authentication.rb +0 -39
  77. data/lib/vonage/network_authentication/server_authentication.rb +0 -47
  78. data/lib/vonage/network_authentication.rb +0 -22
  79. data/lib/vonage/network_number_verification.rb +0 -92
  80. data/lib/vonage/network_sim_swap.rb +0 -84
  81. data/lib/vonage/number_insight_2.rb +0 -21
  82. data/lib/vonage/proactive_connect/events/list_response.rb +0 -11
  83. data/lib/vonage/proactive_connect/events.rb +0 -71
  84. data/lib/vonage/proactive_connect/item.rb +0 -116
  85. data/lib/vonage/proactive_connect/items/file_response.rb +0 -32
  86. data/lib/vonage/proactive_connect/items/list_response.rb +0 -11
  87. data/lib/vonage/proactive_connect/items.rb +0 -116
  88. data/lib/vonage/proactive_connect/list.rb +0 -186
  89. data/lib/vonage/proactive_connect/lists/list_response.rb +0 -11
  90. data/lib/vonage/proactive_connect/lists.rb +0 -38
  91. data/lib/vonage/proactive_connect.rb +0 -43
  92. data/lib/vonage/subaccounts/balance_transfers/list_response.rb +0 -11
  93. data/lib/vonage/subaccounts/credit_transfers/list_response.rb +0 -11
  94. data/lib/vonage/subaccounts/list_response.rb +0 -15
  95. data/lib/vonage/subaccounts.rb +0 -203
  96. data/lib/vonage/users/list_response.rb +0 -11
  97. data/lib/vonage/users.rb +0 -156
  98. data/lib/vonage/verify2/channels/email.rb +0 -36
  99. data/lib/vonage/verify2/channels/silent_auth.rb +0 -45
  100. data/lib/vonage/verify2/channels/sms.rb +0 -63
  101. data/lib/vonage/verify2/channels/voice.rb +0 -32
  102. data/lib/vonage/verify2/channels/whats_app.rb +0 -39
  103. data/lib/vonage/verify2/channels/whats_app_interactive.rb +0 -32
  104. data/lib/vonage/verify2/start_verification_options.rb +0 -63
  105. data/lib/vonage/verify2/template_fragments/list_response.rb +0 -11
  106. data/lib/vonage/verify2/template_fragments.rb +0 -125
  107. data/lib/vonage/verify2/templates/list_response.rb +0 -11
  108. data/lib/vonage/verify2/templates.rb +0 -86
  109. data/lib/vonage/verify2/workflow.rb +0 -39
  110. data/lib/vonage/verify2/workflow_builder.rb +0 -25
  111. data/lib/vonage/verify2.rb +0 -112
  112. data/lib/vonage/video/archives/list_response.rb +0 -11
  113. data/lib/vonage/video/broadcasts/list_response.rb +0 -11
  114. data/lib/vonage/video/broadcasts.rb +0 -75
  115. data/lib/vonage/video/captions.rb +0 -67
  116. data/lib/vonage/video/renders/list_response.rb +0 -11
  117. data/lib/vonage/video/renders.rb +0 -107
  118. data/lib/vonage/video/sip.rb +0 -48
  119. data/lib/vonage/video/streams/list_response.rb +0 -11
  120. data/lib/vonage/video/web_socket.rb +0 -62
data/lib/vonage/video.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  module Vonage
5
5
  class Video < Namespace
6
6
  include Keys
7
-
7
+
8
8
  self.authentication = BearerToken
9
9
 
10
10
  self.host = :video_host
@@ -30,7 +30,7 @@ module Vonage
30
30
  #
31
31
  def create_session(**params)
32
32
  request_params = params.clone
33
- request_params[:archive_mode] ||= 'manual'
33
+ request_params[:archive_mode] ||= 'manual'
34
34
  media_mode = request_params.delete(:media_mode) || 'routed'
35
35
 
36
36
  if media_mode == 'relayed' && request_params[:archive_mode] == 'manual'
@@ -42,7 +42,7 @@ module Vonage
42
42
  response = request('/session/create', params: camelcase(request_params), type: Post)
43
43
 
44
44
  public_response_data = {
45
- session_id: response.entity.first.session_id,
45
+ session_id: response.entity[:session_id],
46
46
  archive_mode: request_params[:archive_mode],
47
47
  media_mode: media_mode,
48
48
  location: request_params[:location]
@@ -54,22 +54,7 @@ module Vonage
54
54
  end
55
55
 
56
56
  def generate_client_token(session_id:, scope: 'session.connect', role: 'publisher', **params)
57
- valid_roles = %w[publisher subscriber moderator publisheronly]
58
- raise ArgumentError, "Invalid role: #{role}" unless valid_roles.include?(role)
59
-
60
- claims = {
61
- application_id: @config.application_id,
62
- scope: scope,
63
- session_id: session_id,
64
- role: role,
65
- initial_layout_class_list: '',
66
- sub: 'video',
67
- acl: {
68
- paths: {'/session/**' => {}}
69
- }
70
- }
71
-
72
-
57
+ claims = {session_id: session_id, application_id: @config.application_id, scope: scope, role: role}
73
58
  claims[:data] = params[:data] if params[:data]
74
59
  claims[:initial_layout_class_list] = params[:initial_layout_class_list].join(' ') if params[:initial_layout_class_list]
75
60
  claims[:exp] = params[:expire_time].to_i if params[:expire_time]
@@ -77,52 +62,30 @@ module Vonage
77
62
  JWT.generate(claims, @config.private_key)
78
63
  end
79
64
 
80
- # @return [Archives]
65
+ # @return [Streams]
81
66
  #
82
- def archives
83
- @archives ||= Archives.new(@config)
67
+ def streams
68
+ @streams ||= Streams.new(@config)
84
69
  end
85
70
 
86
- # @return [Broadcasts]
71
+ # @return [Archives]
87
72
  #
88
- def broadcasts
89
- @broadcasts ||= Broadcasts.new(@config)
73
+ def archives
74
+ @archives ||= Archives.new(@config)
90
75
  end
91
76
 
92
- # @return [Moderation]
77
+ # @return [Archives]
93
78
  #
94
79
  def moderation
95
80
  @moderation ||= Moderation.new(@config)
96
81
  end
97
82
 
98
- # @return [Signals]
83
+ # @return [Archives]
99
84
  #
100
85
  def signals
101
86
  @signals ||= Signals.new(@config)
102
87
  end
103
88
 
104
- # @return [Streams]
105
- #
106
- def streams
107
- @streams ||= Streams.new(@config)
108
- end
109
-
110
- # @return [Captions]
111
- #
112
- def captions
113
- @captions ||= Captions.new(@config)
114
- end
115
-
116
- # @return [Renders]
117
- #
118
- def renders
119
- @renders ||= Renders.new(@config)
120
- end
121
-
122
- # @return [WebSocket]
123
- #
124
- def web_socket
125
- @web_socket ||= WebSocket.new(@config)
126
- end
89
+ # TODO: add token generator
127
90
  end
128
91
  end
@@ -2,9 +2,9 @@
2
2
  # frozen_string_literal: true
3
3
  require 'phonelib'
4
4
 
5
- module Vonage
5
+ module Vonage
6
6
  class Voice::Actions::Connect
7
- attr_accessor :endpoint, :from, :eventType, :timeout, :limit, :machineDetection, :advanced_machine_detection, :eventUrl, :eventMethod, :ringbackTone
7
+ attr_accessor :endpoint, :from, :eventType, :timeout, :limit, :machineDetection, :eventUrl, :eventMethod, :ringbackTone
8
8
 
9
9
  def initialize(attributes = {})
10
10
  @endpoint = attributes.fetch(:endpoint)
@@ -13,7 +13,6 @@ module Vonage
13
13
  @timeout = attributes.fetch(:timeout, nil)
14
14
  @limit = attributes.fetch(:limit, nil)
15
15
  @machineDetection = attributes.fetch(:machineDetection, nil)
16
- @advanced_machine_detection = attributes.fetch(:advanced_machine_detection, nil)
17
16
  @eventUrl = attributes.fetch(:eventUrl, nil)
18
17
  @eventMethod = attributes.fetch(:eventMethod, nil)
19
18
  @ringbackTone = attributes.fetch(:ringbackTone, nil)
@@ -40,10 +39,6 @@ module Vonage
40
39
  verify_machine_detection
41
40
  end
42
41
 
43
- if self.advanced_machine_detection
44
- verify_advanced_machine_detection
45
- end
46
-
47
42
  if self.eventUrl
48
43
  verify_event_url
49
44
  end
@@ -67,9 +62,7 @@ module Vonage
67
62
  raise ClientError.new("Expected 'uri' value to be a valid URI") unless URI.parse(endpoint[:uri]).kind_of?(URI::Generic)
68
63
  raise ClientError.new("Expected 'content-type' parameter to be either 'audio/116;rate=16000' or 'audio/116;rate=8000") unless endpoint[:'content-type'] == 'audio/116;rate=16000' || endpoint[:'content-type'] == 'audio/116;rate=8000'
69
64
  when 'sip'
70
- raise ClientError.new("Expected 'uri' value to be a valid URI") unless URI.parse(endpoint[:uri]).kind_of?(URI::Generic) if endpoint[:uri]
71
- raise ClientError.new("`uri` must not be combined with `user` and `domain`") if endpoint[:uri] && (endpoint[:user] || endpoint[:domain])
72
- raise ClientError.new("You must provide both `user` and `domain`") if (endpoint[:user] && !endpoint[:domain]) || (endpoint[:domain] && !endpoint[:user])
65
+ raise ClientError.new("Expected 'uri' value to be a valid URI") unless URI.parse(endpoint[:uri]).kind_of?(URI::Generic)
73
66
  end
74
67
  end
75
68
 
@@ -89,33 +82,10 @@ module Vonage
89
82
  raise ClientError.new("Invalid 'machineDetection' value, must be either: 'continue' or 'hangup' if defined") unless self.machineDetection == 'continue' || self.machineDetection == 'hangup'
90
83
  end
91
84
 
92
- def verify_advanced_machine_detection
93
- raise ClientError.new("Invalid 'advanced_machine_detection' value, must be a Hash") unless self.advanced_machine_detection.is_a?(Hash)
94
- verify_advanced_machine_detection_behavior if self.advanced_machine_detection[:behavior]
95
- verify_advanced_machine_detection_mode if self.advanced_machine_detection[:mode]
96
- verify_advanced_machine_detection_beep_timeout if self.advanced_machine_detection[:beep_timeout]
97
- end
98
-
99
- def verify_advanced_machine_detection_behavior
100
- raise ClientError.new("Invalid 'advanced_machine_detection[:behavior]' value, must be a `continue` or `hangup`") unless ['continue', 'hangup'].include?(self.advanced_machine_detection[:behavior])
101
- end
102
-
103
- def verify_advanced_machine_detection_mode
104
- raise ClientError.new("Invalid 'advanced_machine_detection[:mode]' value, must be a `detect` or `detect_beep`") unless ['detect', 'detect_beep'].include?(self.advanced_machine_detection[:mode])
105
- end
106
-
107
- def verify_advanced_machine_detection_beep_timeout
108
- raise ClientError.new("Invalid 'advanced_machine_detection[:beep_timeout]' value, must be between 45 and 120") unless self.advanced_machine_detection[:beep_timeout].between?(45, 120)
109
- end
110
-
111
85
  def verify_event_url
112
- unless self.eventUrl.is_a?(Array) && self.eventUrl.length == 1 && self.eventUrl[0].is_a?(String)
113
- raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item")
114
- end
115
-
116
- uri = URI.parse(self.eventUrl[0])
86
+ uri = URI.parse(self.eventUrl)
117
87
 
118
- raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
88
+ raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
119
89
 
120
90
  self.eventUrl
121
91
  end
@@ -210,14 +180,11 @@ module Vonage
210
180
 
211
181
  def sip_endpoint(endpoint_attrs)
212
182
  hash = {
213
- type: 'sip'
183
+ type: 'sip',
184
+ uri: endpoint_attrs[:uri]
214
185
  }
215
186
 
216
- hash.merge!(uri: endpoint_attrs[:uri]) if endpoint_attrs[:uri]
217
- hash.merge!(user: endpoint_attrs[:user]) if endpoint_attrs[:user]
218
- hash.merge!(domain: endpoint_attrs[:domain]) if endpoint_attrs[:domain]
219
187
  hash.merge!(headers: endpoint_attrs[:headers]) if endpoint_attrs[:headers]
220
- hash.merge!(standardHeaders: endpoint_attrs[:standardHeaders]) if endpoint_attrs[:standardHeaders]
221
188
 
222
189
  hash
223
190
  end
@@ -229,4 +196,4 @@ module Vonage
229
196
  }
230
197
  end
231
198
  end
232
- end
199
+ end
@@ -1,7 +1,7 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
-
4
- module Vonage
3
+
4
+ module Vonage
5
5
  class Voice::Actions::Conversation
6
6
  attr_accessor :name, :musicOnHoldUrl, :startOnEnter, :endOnExit, :record, :canSpeak, :canHear, :mute
7
7
 
@@ -49,15 +49,9 @@ module Vonage
49
49
  end
50
50
 
51
51
  def verify_music_on_hold_url
52
- music_on_hold_url = self.musicOnHoldUrl
53
-
54
- unless music_on_hold_url.is_a?(Array) && music_on_hold_url.length == 1 && music_on_hold_url[0].is_a?(String)
55
- raise ClientError.new("Expected 'musicOnHoldUrl' parameter to be an Array containing a single string item")
56
- end
57
-
58
- uri = URI.parse(music_on_hold_url[0])
52
+ uri = URI.parse(self.musicOnHoldUrl)
59
53
 
60
- raise ClientError.new("Invalid 'musicOnHoldUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
54
+ raise ClientError.new("Invalid 'musicOnHoldUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
61
55
 
62
56
  self.musicOnHoldUrl
63
57
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Vonage
5
5
  class Voice::Actions::Input
6
- attr_accessor :type, :dtmf, :speech, :eventUrl, :eventMethod, :mode
6
+ attr_accessor :type, :dtmf, :speech, :eventUrl, :eventMethod
7
7
 
8
8
  def initialize(attributes = {})
9
9
  @type = attributes.fetch(:type)
@@ -11,7 +11,6 @@ module Vonage
11
11
  @speech = attributes.fetch(:speech, nil)
12
12
  @eventUrl = attributes.fetch(:eventUrl, nil)
13
13
  @eventMethod = attributes.fetch(:eventMethod, nil)
14
- @mode = attributes.fetch(:mode, nil)
15
14
 
16
15
  after_initialize!
17
16
  end
@@ -34,10 +33,6 @@ module Vonage
34
33
  if self.eventMethod
35
34
  validate_event_method
36
35
  end
37
-
38
- if self.mode
39
- validate_mode
40
- end
41
36
  end
42
37
 
43
38
  def validate_type
@@ -88,13 +83,9 @@ module Vonage
88
83
  end
89
84
 
90
85
  def validate_event_url
91
- unless self.eventUrl.is_a?(Array) && self.eventUrl.length == 1 && self.eventUrl[0].is_a?(String)
92
- raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item")
93
- end
94
-
95
- uri = URI.parse(self.eventUrl[0])
86
+ uri = URI.parse(self.eventUrl)
96
87
 
97
- raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
88
+ raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
98
89
 
99
90
  self.eventUrl
100
91
  end
@@ -105,12 +96,6 @@ module Vonage
105
96
  raise ClientError.new("Invalid 'eventMethod' value. must be either: 'GET' or 'POST'") unless valid_methods.include?(self.eventMethod.upcase)
106
97
  end
107
98
 
108
- def validate_mode
109
- valid_modes = ['asyncronous']
110
-
111
- raise ClientError.new("Invalid 'mode' value, must be asyncronous'") unless valid_modes.include?(self.mode)
112
- end
113
-
114
99
  def action
115
100
  create_input!(self)
116
101
  end
@@ -127,7 +112,6 @@ module Vonage
127
112
  ncco[0].merge!(speech: builder.speech) if builder.speech
128
113
  ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl
129
114
  ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod
130
- ncco[0].merge!(mode: builder.mode) if builder.mode
131
115
 
132
116
  ncco
133
117
  end
@@ -22,15 +22,10 @@ module Vonage
22
22
  end
23
23
 
24
24
  def validate_event_url
25
- event_url = self.eventUrl
25
+ uri = URI.parse(self.eventUrl[0])
26
26
 
27
- unless event_url.is_a?(Array) && event_url.length == 1 && event_url[0].is_a?(String)
28
- raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item")
29
- end
30
-
31
- uri = URI.parse(event_url[0])
32
-
33
- raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
27
+ raise ClientError.new("Expected 'eventUrl' value to be an Array with a single string") unless self.eventUrl.is_a?(Array)
28
+ raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
34
29
 
35
30
  self.eventUrl
36
31
  end
@@ -0,0 +1,107 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+ module Vonage
4
+ class Voice::Actions::Pay
5
+ attr_accessor :amount, :currency, :eventUrl, :prompts, :voice
6
+
7
+ def initialize(attributes= {})
8
+ @amount = attributes.fetch(:amount)
9
+ @currency = attributes.fetch(:currency, nil)
10
+ @eventUrl = attributes.fetch(:eventUrl, nil)
11
+ @prompts = attributes.fetch(:prompts, nil)
12
+ @voice = attributes.fetch(:voice, nil)
13
+
14
+ after_initialize!
15
+ end
16
+
17
+ def action
18
+ create_pay!(self)
19
+ end
20
+
21
+ def create_pay!(builder)
22
+ ncco = [
23
+ {
24
+ action: 'pay',
25
+ amount: builder.amount
26
+ }
27
+ ]
28
+
29
+ ncco[0].merge!(currency: builder.currency) if builder.currency
30
+ ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl
31
+ ncco[0].merge!(prompts: builder.prompts) if builder.prompts
32
+ ncco[0].merge!(voice: builder.voice) if builder.voice
33
+
34
+ ncco
35
+ end
36
+
37
+ private
38
+
39
+ def after_initialize!
40
+ verify_amount
41
+
42
+ if self.eventUrl
43
+ verify_event_url
44
+ end
45
+
46
+ if self.prompts
47
+ verify_prompts
48
+ end
49
+
50
+ if self.voice
51
+ verify_voice
52
+ end
53
+ end
54
+
55
+ def verify_amount
56
+ verify_amount_class
57
+ verify_amount_value
58
+ end
59
+
60
+ def verify_event_url
61
+ raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item") unless self.eventUrl.is_a?(Array)
62
+
63
+ uri = URI.parse(self.eventUrl[0])
64
+
65
+ raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
66
+ end
67
+
68
+ def verify_prompts
69
+ verify_prompts_structure
70
+ verify_prompts_values
71
+ end
72
+
73
+ def verify_voice
74
+ verify_voice_structure
75
+ verify_voice_style if self.voice[:style]
76
+ end
77
+
78
+ def verify_amount_class
79
+ raise ClientError.new("Invalid 'amount' value, must be a float") unless self.amount.is_a?(Float)
80
+ end
81
+
82
+ def verify_amount_value
83
+ raise ClientError.new("Invalid 'amount' value, must be greater than 0") unless self.amount > 0
84
+ end
85
+
86
+ def verify_prompts_structure
87
+ raise ClientError.new("Invalid 'prompt', must be an array of at least one hash") unless self.prompts.is_a?(Array) && !self.prompts.empty? && self.prompts.all?(Hash)
88
+ end
89
+
90
+ def verify_prompts_values
91
+ self.prompts.each do |prompt|
92
+ prompt_keys = prompt.keys
93
+ [:type, :text, :errors].each do |key|
94
+ raise ClientError.new("Invalid 'prompt', '#{key}' is required") unless prompt_keys.include?(key)
95
+ end
96
+ end
97
+ end
98
+
99
+ def verify_voice_structure
100
+ raise ClientError.new("Expected 'voice' value to be a Hash") unless self.voice.is_a?(Hash)
101
+ end
102
+
103
+ def verify_voice_style
104
+ raise ClientError.new("Expected 'style' value to be an Integer") unless self.voice[:style].is_a?(Integer)
105
+ end
106
+ end
107
+ end
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Vonage
5
5
  class Voice::Actions::Record
6
- attr_accessor :format, :split, :channels, :endOnSilence, :endOnKey, :timeOut, :beepStart, :eventUrl, :eventMethod, :transcription
6
+ attr_accessor :format, :split, :channels, :endOnSilence, :endOnKey, :timeOut, :beepStart, :eventUrl, :eventMethod
7
7
 
8
8
  def initialize(attributes = {})
9
9
  @format = attributes.fetch(:format, nil)
@@ -15,7 +15,6 @@ module Vonage
15
15
  @beepStart = attributes.fetch(:beepStart, nil)
16
16
  @eventUrl = attributes.fetch(:eventUrl, nil)
17
17
  @eventMethod = attributes.fetch(:eventMethod, nil)
18
- @transcription = attributes.fetch(:transcription, nil)
19
18
 
20
19
  after_initialize!
21
20
  end
@@ -56,10 +55,6 @@ module Vonage
56
55
  if self.eventMethod
57
56
  validate_event_method
58
57
  end
59
-
60
- if self.transcription
61
- validate_transcription
62
- end
63
58
  end
64
59
 
65
60
  def validate_format
@@ -95,13 +90,9 @@ module Vonage
95
90
  end
96
91
 
97
92
  def validate_event_url
98
- unless self.eventUrl.is_a?(Array) && self.eventUrl.length == 1 && self.eventUrl[0].is_a?(String)
99
- raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item")
100
- end
93
+ uri = URI.parse(self.eventUrl)
101
94
 
102
- uri = URI.parse(self.eventUrl[0])
103
-
104
- raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
95
+ raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
105
96
 
106
97
  self.eventUrl
107
98
  end
@@ -109,45 +100,7 @@ module Vonage
109
100
  def validate_event_method
110
101
  valid_methods = ['GET', 'POST']
111
102
 
112
- raise ClientError.new("Invalid 'eventMethod' value. Must be either: 'GET' or 'POST'") unless valid_methods.include?(self.eventMethod.upcase)
113
- end
114
-
115
- def validate_transcription
116
- raise ClientError.new("Expected 'transcription' parameter to be a Hash") unless self.transcription.is_a?(Hash)
117
-
118
- if self.transcription[:language]
119
- raise ClientError.new("Invalid 'language' value, must be a String") unless self.transcription[:language].is_a?(String)
120
- end
121
-
122
- if self.transcription[:eventUrl]
123
- event_url = self.transcription[:eventUrl]
124
-
125
- unless event_url.is_a?(Array) && event_url.length == 1 && event_url[0].is_a?(String)
126
- raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item")
127
- end
128
-
129
- uri = URI.parse(event_url[0])
130
-
131
- raise ClientError.new("Invalid 'eventUrl' value, array must contain a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
132
- end
133
-
134
- if self.transcription[:eventMethod]
135
- event_method = self.transcription[:eventMethod]
136
- raise ClientError.new("Invalid 'eventMethod' value, must be either: 'GET' or 'POST'") unless ['GET', 'POST'].include?(event_method.upcase)
137
- end
138
-
139
- if self.transcription[:sentimentAnalysis]
140
- sentiment_analysis = self.transcription[:sentimentAnalysis]
141
- raise ClientError.new("Invalid 'sentimentAnalysis' value, must be a Boolean") unless sentiment_analysis == true || sentiment_analysis == false
142
- end
143
-
144
- # if self.dtmf[:maxDigits]
145
- # raise ClientError.new("Expected 'maxDigits' to not be more than 22") if self.dtmf[:maxDigits] > 22
146
- # end
147
-
148
- # if self.dtmf[:submitOnHash]
149
- # raise ClientError.new("Invalid 'submitOnHash' value, must be a Boolean") unless self.dtmf[:submitOnHash] == true || self.dtmf[:submitOnHash] == false
150
- # end
103
+ raise ClientError.new("Invalid 'eventMethod' value. must be either: 'GET' or 'POST'") unless valid_methods.include?(self.eventMethod.upcase)
151
104
  end
152
105
 
153
106
  def action
@@ -170,7 +123,6 @@ module Vonage
170
123
  ncco[0].merge!(beepStart: builder.beepStart) if builder.beepStart
171
124
  ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl
172
125
  ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod
173
- ncco[0].merge!(transcription: builder.transcription) if builder.transcription
174
126
 
175
127
  ncco
176
128
  end
@@ -31,13 +31,9 @@ module Vonage
31
31
  end
32
32
 
33
33
  def verify_stream_url
34
- stream_url = self.streamUrl
34
+ raise ClientError.new("Expected 'streamUrl' parameter to be an Array containing a single string item") unless self.streamUrl.is_a?(Array)
35
35
 
36
- unless stream_url.is_a?(Array) && stream_url.length == 1 && stream_url[0].is_a?(String)
37
- raise ClientError.new("Expected 'streamUrl' parameter to be an Array containing a single string item")
38
- end
39
-
40
- uri = URI.parse(stream_url[0])
36
+ uri = URI.parse(self.streamUrl[0])
41
37
 
42
38
  raise ClientError.new("Invalid 'streamUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
43
39
  end
@@ -51,7 +47,7 @@ module Vonage
51
47
  end
52
48
 
53
49
  def verify_loop
54
- raise ClientError.new("Expected 'loop' value to be either 0 or a positive integer") unless self.loop >= 0
50
+ raise ClientError.new("Expected 'loop' value to be either 1 or 0") unless self.loop == 1 || self.loop == 0
55
51
  end
56
52
 
57
53
  def action
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
  module Vonage
4
4
  class Voice::Actions::Talk
5
- attr_accessor :text, :bargeIn, :loop, :level, :language, :style, :premium
5
+ attr_accessor :text, :bargeIn, :loop, :level, :language, :style
6
6
 
7
7
  def initialize(attributes= {})
8
8
  @text = attributes.fetch(:text)
@@ -11,13 +11,12 @@ module Vonage
11
11
  @level = attributes.fetch(:level, nil)
12
12
  @language = attributes.fetch(:language, nil)
13
13
  @style = attributes.fetch(:style, nil)
14
- @premium = attributes.fetch(:premium, nil)
15
14
 
16
15
  after_initialize!
17
16
  end
18
17
 
19
18
  def after_initialize!
20
- if self.bargeIn || self.bargeIn == false
19
+ if self.bargeIn
21
20
  verify_barge_in
22
21
  end
23
22
 
@@ -32,10 +31,6 @@ module Vonage
32
31
  if self.style
33
32
  verify_style
34
33
  end
35
-
36
- if self.premium || self.premium == false
37
- verify_premium
38
- end
39
34
  end
40
35
 
41
36
  def verify_barge_in
@@ -43,7 +38,7 @@ module Vonage
43
38
  end
44
39
 
45
40
  def verify_loop
46
- raise ClientError.new("Expected 'loop' value to be either 0 or a positive integer") unless self.loop >= 0
41
+ raise ClientError.new("Expected 'loop' value to be either 1 or 0") unless self.loop == 1 || self.loop == 0
47
42
  end
48
43
 
49
44
  def verify_level
@@ -54,10 +49,6 @@ module Vonage
54
49
  raise ClientError.new("Expected 'style' value to be an Integer") unless self.style.is_a?(Integer)
55
50
  end
56
51
 
57
- def verify_premium
58
- raise ClientError.new("Expected 'premium' value to be a Boolean") unless self.premium == true || self.premium == false
59
- end
60
-
61
52
  def action
62
53
  create_talk!(self)
63
54
  end
@@ -75,9 +66,8 @@ module Vonage
75
66
  ncco[0].merge!(level: builder.level) if builder.level
76
67
  ncco[0].merge!(language: builder.language) if builder.language
77
68
  ncco[0].merge!(style: builder.style) if builder.style
78
- ncco[0].merge!(premium: builder.premium) if (builder.bargeIn || builder.bargeIn == false)
79
69
 
80
70
  ncco
81
71
  end
82
72
  end
83
- end
73
+ end
@@ -12,18 +12,8 @@ module Vonage
12
12
  # @option params [required, String] :text
13
13
  # The text to read.
14
14
  #
15
- # @option params [String] :language
16
- # The language to use. See {https://developer.vonage.com/en/api/voice#startTalk-req-body} for a list of valid language codes.
17
- #
18
- # @option params [Integer] :style
19
- # The vocal style, as identified by an assigned integer.
20
- # See {https://developer.vonage.com/en/voice/voice-api/concepts/text-to-speech#supported-languages} for a list of available styles.
21
- #
22
- # @option params [Boolean] :premium
23
- # Set to `true` to use the premium version of the specified style if available, otherwise the standard version will be used.
24
- #
25
15
  # @option params [String] :voice_name
26
- # The voice & language to use. [DEPRECATED: use `language` and `style` instead].
16
+ # The voice & language to use.
27
17
  #
28
18
  # @option params [Integer] :loop
29
19
  # The number of times to repeat the text the file, 0 for infinite.
data/lib/vonage/voice.rb CHANGED
@@ -18,8 +18,6 @@ module Vonage
18
18
  #
19
19
  # @option params [required, Array<Hash>] :to
20
20
  # Connect to a Phone (PSTN) number, SIP Endpoint, Websocket, or VBC extension.
21
- # The `to` Hash can contain a number of different properties depending on the `type`.
22
- # See the API reference for specific details.
23
21
  #
24
22
  # @option params [Hash] :from
25
23
  # Connect to a Phone (PSTN) number. Should not be set if **:random_from_number** is **true**
@@ -50,17 +48,6 @@ module Vonage
50
48
  # @option params [String] :machine_detection
51
49
  # Configure the behavior when Vonage detects that the call is answered by voicemail.
52
50
  #
53
- # @option params [Hash] :advanced_machine_detection
54
- # Configure the behavior of Vonage's advanced machine detection. Overrides machine_detection if both are set.
55
- # Hash with three possible properties:
56
- # - :behavior [String]: Must be one of `continue` or `hangup`. When hangup is used, the call will be terminated if a
57
- # machine is detected. When continue is used, the call will continue even if a machine is detected.
58
- # - :mode [String]: Must be one of `detect` or `detect_beep`. Detect if machine answered and sends a human or
59
- # machine status in the webhook payload. When set to `detect_beep`, the system also attempts to detect
60
- # voice mail beep and sends an additional parameter `sub_state` in the webhook with the value `beep_start`.
61
- # - :beep_timeout [Integer]: Min: 45, Max: 120. Maximum time in seconds Vonage should wait for a machine beep
62
- # to be detected. A machine event with `sub_state` set to `beep_timeout` will be sent if the timeout is exceeded.
63
- #
64
51
  # @option params [Integer] :length_timer
65
52
  # Set the number of seconds that elapse before Vonage hangs up after the call state changes to in_progress.
66
53
  #
@@ -281,16 +268,5 @@ module Vonage
281
268
  def dtmf
282
269
  @dtmf ||= DTMF.new(@config)
283
270
  end
284
-
285
- # Validate a JSON Web Token from a Voice API Webhook.
286
- #
287
- # @param [String, required] :token The JWT from the Webhook's Authorization header
288
- # @param [String, optional] :signature_secret The account signature secret. Required, unless `signature_secret`
289
- # is set in `Config`
290
- #
291
- # @return [Boolean] true, if the JWT is verified, false otherwise
292
- def verify_webhook_token(token:, signature_secret: @config.signature_secret)
293
- JWT.verify_hs256_signature(token: token, signature_secret: signature_secret)
294
- end
295
271
  end
296
272
  end