plivo 4.16.0 → 4.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 432a8633325d5e44eee995dc40993c24b25251ae
4
- data.tar.gz: f1c57049cd472b7f27912e15c34949e560994132
3
+ metadata.gz: d0e41ca933ee8b7b7e1d43b5f894acd712e0f4db
4
+ data.tar.gz: 87f28295afadfa54936053e9972fe25781bd89ae
5
5
  SHA512:
6
- metadata.gz: eef8a0013b8f4eb0356c98bf70c6390b0be26b23bfc6236b78751df0d8c3496a29d0f556361a5068225beda650b6d8385cd95927c05bac3cc37fb761e635ed11
7
- data.tar.gz: f2a93d08156446bfe73769f162c8bd8ade2d20314cadf636b8831ea91b02de673965638b3e0aea385d2c9a7dd5527b91432295c379ad88bfc16365a2d49a029a
6
+ metadata.gz: '08ea6b08cadfa871edcb5ccdeaa41eda8af3cb8e74c4e1afc8a0031c9d10a79aff48591d3aaac59651d3874bb8d0226f2c47227277847fabf2dcc9ccf2c4496f'
7
+ data.tar.gz: 731d629d2fe5b97d5b7b513f0a2dd8aade4a648d7fd403799bff496883a8850208db06c2f49ec321551ccd43c59d9dec17d1b42d363d9e0a1593792cdc228e6c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.19.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.19.0) (2021-07-19)
4
+ - Add support for Voice MultiPartyCall APIs (includes retry) and XML, validate voice UTs
5
+
6
+ ## [4.18.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.18.0) (2021-07-13)
7
+ - Power pack ID has been included to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message).
8
+ - Support for filtering messages by Power pack ID has been added to the [list all messages API](https://www.plivo.com/docs/sms/api/message#list-all-messages).
9
+
10
+ ## [4.17.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.17.1) (2021-06-18)
11
+ - **WARNING**: Remove total_count field from meta data for list MDR response
12
+
13
+ ## [4.17.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.17.0) (2021-06-15)
14
+ - Added stir verification param as part of Get CDR and live call APIs response.
15
+
3
16
  ## [4.16.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.16.0) (2021-02-08)
4
17
  - Add support for Regulatory Compliance APIs.
5
18
 
data/README.md CHANGED
@@ -8,7 +8,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'plivo', '>= 4.16.0'
11
+ gem 'plivo', '>= 4.19.0'
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -114,5 +114,35 @@ module Plivo
114
114
  Response.new(response_json, @_identifier_string)
115
115
  end
116
116
  end
117
+
118
+ class SecondaryResource < Resource
119
+ attr_reader :secondary_id
120
+ def initialize(client, options = nil)
121
+ super
122
+ configure_secondary_options(options) if options
123
+ configure_secondary_resource_uri
124
+ end
125
+
126
+ def configure_secondary_options(options)
127
+ valid_param?(:options, options, Hash, false)
128
+ @secondary_id = options[:member_id] if options.key?(:member_id)
129
+ secondary_parse_and_set(options[:resource_json]) if options.key?(:resource_json)
130
+ end
131
+
132
+ def secondary_parse_and_set(resource_json)
133
+ return unless resource_json
134
+
135
+ valid_param?(:resource_json, resource_json, Hash, true)
136
+ return unless @_secondary_identifier_string && (resource_json.key? @_secondary_identifier_string)
137
+ @secondary_id = resource_json[@_secondary_identifier_string]
138
+ end
139
+
140
+ def configure_secondary_resource_uri
141
+ to_join = @secondary_id ? [@_client.auth_id, @_name, @id, @_secondary_name, @secondary_id] : [@_client.auth_id, @_name, @id]
142
+ to_join = ['', 'v1', 'Account'] << to_join
143
+ to_join << ''
144
+ @_resource_uri = to_join.join('/')
145
+ end
146
+ end
117
147
  end
118
148
  end
@@ -33,7 +33,7 @@ module Plivo
33
33
  raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\
34
34
  'couldn\'t be deleted'
35
35
  end
36
- elsif !([200, 201, 202, 207].include? response[:status])
36
+ elsif !([200, 201, 202, 204, 207].include? response[:status])
37
37
  raise Exceptions::PlivoRESTError, "Received #{response[:status]} for #{method}"
38
38
  end
39
39
  @@voice_retry_count = 0
@@ -266,6 +266,7 @@ module Plivo
266
266
  req.url resource_path
267
267
  req.options.timeout = timeout if timeout
268
268
  req.body = data
269
+ puts req
269
270
  end
270
271
  else
271
272
  if !data.nil? && (data.has_key? 'is_callinsights_request')
@@ -17,6 +17,7 @@ require_relative 'resources/call_feedback'
17
17
  require_relative 'resources/media'
18
18
  require_relative 'resources/lookup'
19
19
  require_relative 'resources/regulatory_compliance'
20
+ require_relative 'resources/multipartycalls'
20
21
 
21
22
  module Plivo
22
23
  module Resources
@@ -230,7 +230,8 @@ module Plivo
230
230
  from: @from,
231
231
  request_uuid: @request_uuid,
232
232
  direction: @direction,
233
- caller_name: @caller_name
233
+ caller_name: @caller_name,
234
+ stir_verification: @stir_verification
234
235
  }
235
236
  call_details = call_details.select {|k, v| !v.nil? }
236
237
  call_details.to_s
@@ -29,6 +29,7 @@ module Plivo
29
29
  to_number: @to_number,
30
30
  total_amount: @total_amount,
31
31
  total_rate: @total_rate,
32
+ powerpack_id: @powerpack_id,
32
33
  units: @units
33
34
  }.to_s
34
35
  end
@@ -152,8 +153,7 @@ module Plivo
152
153
  # @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
153
154
  # @option options [Int] :offset Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results.
154
155
  # @option options [String] :error_code Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
155
- #@option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
156
- #@option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
156
+ # @option options [String] :powerpack_id Filter the results by powerpack id.
157
157
  def list(options = nil)
158
158
  return perform_list if options.nil?
159
159
  valid_param?(:options, options, Hash, true)
@@ -161,7 +161,7 @@ module Plivo
161
161
  params = {}
162
162
  params_expected = %i[
163
163
  subaccount message_time message_time__gt message_time__gte
164
- message_time__lt message_time__lte error_code
164
+ message_time__lt message_time__lte error_code powerpack_id
165
165
  ]
166
166
  params_expected.each do |param|
167
167
  if options.key?(param) &&
@@ -0,0 +1,554 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class MultiPartyCall < Base::Resource
5
+ def initialize(client, options = nil)
6
+ @_name = 'MultiPartyCall'
7
+ @_identifier_string = 'mpc_uuid'
8
+ super
9
+ @_is_voice_request = true
10
+ if options.key? :multi_party_prefix
11
+ @id = options[:multi_party_prefix] + '_' + @id
12
+ else
13
+ @id = 'uuid_' + @id
14
+ end
15
+ configure_resource_uri
16
+ end
17
+
18
+ def get
19
+ perform_action(nil,'GET',nil,true)
20
+ end
21
+
22
+ def add_participant(role,
23
+ from=nil,
24
+ to=nil,
25
+ call_uuid=nil,
26
+ caller_name=nil,
27
+ call_status_callback_url=nil,
28
+ call_status_callback_method='POST',
29
+ sip_headers=nil,
30
+ confirm_key=nil,
31
+ confirm_key_sound_url=nil,
32
+ confirm_key_sound_method='GET',
33
+ dial_music='Real',
34
+ ring_timeout=45,
35
+ delay_dial=0,
36
+ max_duration=14400,
37
+ max_participants=10,
38
+ wait_music_url=nil,
39
+ wait_music_method='GET',
40
+ agent_hold_music_url=nil,
41
+ agent_hold_music_method='GET',
42
+ customer_hold_music_url=nil,
43
+ customer_hold_music_method='GET',
44
+ recording_callback_url=nil,
45
+ recording_callback_method='GET',
46
+ status_callback_url=nil,
47
+ status_callback_method='GET',
48
+ on_exit_action_url=nil,
49
+ on_exit_action_method='POST',
50
+ record=false,
51
+ record_file_format='mp3',
52
+ status_callback_events='mpc-state-changes,participant-state-changes',
53
+ stay_alone=false,
54
+ coach_mode=true,
55
+ mute=false,
56
+ hold=false,
57
+ start_mpc_on_enter=false,
58
+ end_mpc_on_exit=false,
59
+ relay_dtmf_inputs=false,
60
+ enter_sound='beep:1',
61
+ enter_sound_method='GET',
62
+ exit_sound='beep:2',
63
+ exit_sound_method='GET')
64
+ if (from and to) and call_uuid
65
+ raise_invalid_request('cannot specify call_uuid when (from, to) is provided')
66
+ end
67
+ if not from and not to and not call_uuid
68
+ raise_invalid_request('specify either call_uuid or (from, to)')
69
+ end
70
+ if call_uuid.nil? and (not from or not to)
71
+ raise_invalid_request('specify (from, to) when not adding an existing call_uuid to multi party participant')
72
+ end
73
+
74
+ valid_param?(:role, role.downcase, String, true, %w[agent supervisor customer])
75
+ valid_param?(:from, from, String, false ) unless from.nil?
76
+ valid_param?(:to, to, String, false ) unless to.nil?
77
+ valid_multiple_destination_nos?(:to, to, role: role, delimiter: '<', agent_limit: 20) unless to.nil?
78
+ valid_param?(:call_uuid, call_uuid, String, false ) unless call_uuid.nil?
79
+ valid_param?(:caller_name, caller_name, String, false) unless caller_name.nil?
80
+ valid_range?(:caller_name, caller_name.length, false, 0, 50) unless caller_name.nil?
81
+ valid_url?(:call_status_callback_url, call_status_callback_url, false) unless call_status_callback_url.nil?
82
+ valid_param?(:call_status_callback_method, call_status_callback_method.upcase, String, false, %w[GET POST])
83
+ valid_param?(:sip_headers, sip_headers, String, false) unless sip_headers.nil?
84
+ valid_param?(:confirm_key, confirm_key, String, false , %w[0 1 2 3 4 5 6 7 8 9 # *]) unless confirm_key.nil?
85
+ valid_url?(:confirm_key_sound_url, confirm_key_sound_url, false) unless confirm_key_sound_url.nil?
86
+ valid_param?(:confirm_key_sound_method, confirm_key_sound_method.upcase, String, false, %w[GET POST])
87
+ is_one_among_string_url?(:dial_music, dial_music, false, %w[real none])
88
+ valid_param?(:ring_timeout, ring_timeout, [String,Integer], false)
89
+ valid_multiple_destination_integers?(:ring_timeout, ring_timeout)
90
+ valid_param?(:delay_dial, delay_dial, [String,Integer], false)
91
+ valid_multiple_destination_integers?(:delay_dial, delay_dial)
92
+ valid_range?(:max_duration, max_duration, false, 300, 28800)
93
+ valid_range?(:max_participants, max_participants, false, 2, 10)
94
+ valid_url?(:wait_music_url, wait_music_url, false ) unless wait_music_url.nil?
95
+ valid_param?(:wait_music_method, wait_music_method.upcase, String, false , %w[GET POST])
96
+ valid_url?(:agent_hold_music_url, agent_hold_music_url, false) unless agent_hold_music_url.nil?
97
+ valid_param?(:agent_hold_music_method, agent_hold_music_method.upcase, String, false , %w[GET POST])
98
+ valid_url?(:customer_hold_music_url, customer_hold_music_url, false) unless customer_hold_music_url.nil?
99
+ valid_param?(:customer_hold_music_method, customer_hold_music_method.upcase, String, false, %w[GET POST])
100
+ valid_url?(:recording_callback_url, recording_callback_url, false) unless recording_callback_url.nil?
101
+ valid_param?(:recording_callback_method, recording_callback_method.upcase, String, false, %w[GET POST])
102
+ valid_url?(:status_callback_url, status_callback_url, false) unless status_callback_url.nil?
103
+ valid_param?(:status_callback_method, status_callback_method.upcase, String, false, %w[GET POST])
104
+ valid_url?(:on_exit_action_url, on_exit_action_url, false ) unless on_exit_action_url.nil?
105
+ valid_param?(:on_exit_action_method, on_exit_action_method.upcase, String, false, %w[GET POST])
106
+ valid_param?(:record, record, [TrueClass, FalseClass], false )
107
+ valid_param?(:record_file_format, record_file_format.downcase, String, false, %w[mp3 wav])
108
+ multi_valid_param?(:status_callback_events, status_callback_events.downcase, String, false, %w[mpc-state-changes participant-state-changes participant-speak-events participant-digit-input-events add-participant-api-events], true, ',')
109
+ valid_param?(:stay_alone, stay_alone, [TrueClass, FalseClass], false)
110
+ valid_param?(:coach_mode, coach_mode, [TrueClass, FalseClass], false)
111
+ valid_param?(:mute, mute, [TrueClass, FalseClass],false)
112
+ valid_param?(:hold, hold, [TrueClass, FalseClass], false)
113
+ valid_param?(:start_mpc_on_enter, start_mpc_on_enter, [TrueClass, FalseClass], false)
114
+ valid_param?(:end_mpc_on_exit, end_mpc_on_exit, [TrueClass, FalseClass], false)
115
+ valid_param?(:relay_dtmf_inputs, relay_dtmf_inputs, [TrueClass, FalseClass], false)
116
+ is_one_among_string_url?(:enter_sound, enter_sound, false, %w[beep:1 beep:2 none])
117
+ valid_param?(:enter_sound_method, enter_sound_method.upcase, String, false, %w[GET POST])
118
+ is_one_among_string_url?(:exit_sound, exit_sound, false , %w[beep:1 beep:2 none])
119
+ valid_param?(:exit_sound_method, exit_sound_method.upcase, String, false, %w[GET POST])
120
+ if (to!=nil) && (ring_timeout.is_a?(String)) && (to.split('<').size < ring_timeout.split('<').size)
121
+ raise_invalid_request("RingTimeout:number of ring_timout(s) should be same as number of destination(s)")
122
+ end
123
+
124
+ if (to!=nil) && (delay_dial.is_a?(String)) && (to.split('<').size < delay_dial.split('<').size)
125
+ raise_invalid_request("Delaydial : number of delay_dial(s) should be same as number of destination(s)")
126
+ end
127
+
128
+ params = {}
129
+ params[:role] = role unless role.nil?
130
+ params[:from] = from unless from.nil?
131
+ params[:to] = to unless to.nil?
132
+ params[:call_uuid] = call_uuid unless call_uuid.nil?
133
+ params[:caller_name] = caller_name || from
134
+ params[:call_status_callback_url] = call_status_callback_url unless call_status_callback_url.nil?
135
+ params[:call_status_callback_method] = call_status_callback_method.upcase unless call_status_callback_method.nil?
136
+ params[:sip_headers] = sip_headers unless sip_headers.nil?
137
+ params[:confirm_key] = confirm_key unless confirm_key.nil?
138
+ params[:confirm_key_sound_url] = confirm_key_sound_url unless confirm_key_sound_url.nil?
139
+ params[:confirm_key_sound_method] = confirm_key_sound_method.upcase unless confirm_key_sound_method.nil?
140
+ params[:dial_music] = dial_music unless dial_music.nil?
141
+ params[:ring_timeout] = ring_timeout unless ring_timeout.nil?
142
+ params[:delay_dial] = delay_dial unless delay_dial.nil?
143
+ params[:max_duration] = max_duration unless max_duration.nil?
144
+ params[:max_participants] = max_participants unless max_participants.nil?
145
+ params[:wait_music_url] = wait_music_url unless wait_music_url.nil?
146
+ params[:wait_music_method] = wait_music_method.upcase unless wait_music_method.nil?
147
+ params[:agent_hold_music_url] = agent_hold_music_url unless agent_hold_music_url.nil?
148
+ params[:agent_hold_music_method] = agent_hold_music_method.upcase unless agent_hold_music_method.nil?
149
+ params[:customer_hold_music_url] = customer_hold_music_url unless customer_hold_music_url.nil?
150
+ params[:customer_hold_music_method] = customer_hold_music_method.upcase unless customer_hold_music_method.nil?
151
+ params[:recording_callback_url] = recording_callback_url unless recording_callback_url.nil?
152
+ params[:recording_callback_method] = recording_callback_method.upcase unless recording_callback_method.nil?
153
+ params[:status_callback_url] = status_callback_url unless status_callback_url.nil?
154
+ params[:status_callback_method] = status_callback_method.upcase unless status_callback_method.nil?
155
+ params[:on_exit_action_url] = on_exit_action_url unless on_exit_action_url.nil?
156
+ params[:on_exit_action_method] = on_exit_action_method.upcase unless on_exit_action_method.nil?
157
+ params[:record] = record unless record.nil?
158
+ params[:record_file_format] = record_file_format.downcase unless record_file_format.nil?
159
+ params[:status_callback_events] = status_callback_events.downcase unless status_callback_events.nil?
160
+ params[:stay_alone] = stay_alone unless stay_alone.nil?
161
+ params[:coach_mode] = coach_mode unless coach_mode.nil?
162
+ params[:mute] = mute unless mute.nil?
163
+ params[:hold] = hold unless hold.nil?
164
+ params[:start_mpc_on_enter] = start_mpc_on_enter unless start_mpc_on_enter.nil?
165
+ params[:end_mpc_on_exit] = end_mpc_on_exit unless end_mpc_on_exit.nil?
166
+ params[:relay_dtmf_inputs] = relay_dtmf_inputs unless relay_dtmf_inputs.nil?
167
+ params[:enter_sound] = enter_sound unless enter_sound.nil?
168
+ params[:enter_sound_method] = enter_sound_method.upcase unless exit_sound_method.nil?
169
+ params[:exit_sound] = exit_sound unless exit_sound.nil?
170
+ params[:exit_sound_method] = exit_sound_method.upcase unless exit_sound_method.nil?
171
+ perform_action_apiresponse('Participant', 'POST', params, true )
172
+ end
173
+
174
+ def start
175
+ perform_action_apiresponse(nil, 'POST', Hash['status' => 'active'], true)
176
+ end
177
+
178
+ def stop
179
+ perform_action_apiresponse(nil, 'DELETE', nil, true)
180
+ end
181
+
182
+ def start_recording(file_format = 'mp3', status_callback_url = nil, status_callback_method='POST')
183
+ valid_param?(:file_format, file_format, String, false , %w[mp3 wav])
184
+ valid_url?(:status_callback_url, status_callback_url, false) unless status_callback_url.nil?
185
+ valid_param?(:status_callback_method, status_callback_method.upcase,String, false, %w[GET POST])
186
+
187
+ params = {}
188
+ params[:file_format] = file_format.downcase unless file_format.nil?
189
+ params[:status_callback_url] = status_callback_url unless status_callback_url.nil?
190
+ params[:status_callback_method] = status_callback_method.upcase unless status_callback_method.nil?
191
+
192
+ perform_action_apiresponse('Record', 'POST', params, true)
193
+ end
194
+
195
+ def stop_recording
196
+ perform_action_apiresponse('Record', 'DELETE')
197
+ end
198
+
199
+ def pause_recording
200
+ perform_action_apiresponse('Record/Pause', 'POST')
201
+ end
202
+
203
+ def resume_recording
204
+ perform_action_apiresponse('Record/Resume', 'POST')
205
+ end
206
+
207
+
208
+ def start_participant_recording(member_id, file_format='mp3', status_callback_url=nil, status_callback_method='POST')
209
+ valid_param?(:member_id, member_id, [String, Integer], true)
210
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], member_id: member_id).start_participant_recording(file_format, status_callback_url, status_callback_method)
211
+ end
212
+
213
+ def stop_participant_recording(member_id)
214
+ valid_param?(:member_id, member_id, [String, Integer], true)
215
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], member_id: member_id).stop_participant_recording
216
+ end
217
+
218
+ def pause_participant_recording(member_id)
219
+ valid_param?(:member_id, member_id, [String, Integer], true)
220
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], member_id: member_id).pause_participant_recording
221
+ end
222
+
223
+ def resume_participant_recording(member_id)
224
+ valid_param?(:member_id, member_id, [String, Integer], true)
225
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], member_id: member_id).resume_participant_recording
226
+ end
227
+
228
+ def list_participants(call_uuid = nil )
229
+ valid_param?(:call_uuid, call_uuid, String, false) unless call_uuid.nil?
230
+ params = {}
231
+ params[:call_uuid] = call_uuid unless call_uuid.nil?
232
+ perform_action('Participant', 'GET', params, true)
233
+ end
234
+
235
+ def update_participant(member_id, coach_mode = nil, mute = nil , hold = nil)
236
+ valid_param?(:member_id, member_id, [String, Integer], true)
237
+ MultiPartyCallParticipant.new(@_client, resource_id: @id, member_id: member_id).update_participant(coach_mode, mute, hold)
238
+ end
239
+
240
+ def kick_participant(member_id)
241
+ valid_param?(:member_id, member_id, [String, Integer], true)
242
+ MultiPartyCallParticipant.new(@_client, resource_id: @id, member_id: member_id).kick_participant
243
+ end
244
+
245
+ def get_participant(member_id)
246
+ valid_param?(:member_id, member_id, [String, Integer], true)
247
+ MultiPartyCallParticipant.new(@_client,resource_id: @id, member_id: member_id).get_participant
248
+ end
249
+ end
250
+
251
+ class MultiPartyCallParticipant < Base::SecondaryResource
252
+ def initialize(client, options = nil)
253
+ @_name = 'MultiPartyCall'
254
+ @_identifier_string = 'mpc_uuid'
255
+ @_secondary_name = 'Participant'
256
+ @_secondary_identifier_string = 'member_id'
257
+ super
258
+ @_is_voice_request = true
259
+ if options.key? :multi_party_prefix
260
+ @id = options[:multi_party_prefix] + '_' + @id
261
+ elsif @id.split('_').size > 1
262
+ nil
263
+ else
264
+ @id = 'uuid_' + @id
265
+ end
266
+ configure_secondary_resource_uri
267
+ end
268
+
269
+ def start_participant_recording(file_format = 'mp3', status_callback_url = nil, status_callback_method='POST')
270
+ valid_param?(:file_format, file_format, String, false , %w[mp3 wav])
271
+ valid_url?(:status_callback_url, status_callback_url, false) unless status_callback_url.nil?
272
+ valid_param?(:status_callback_method, status_callback_method.upcase,String, false, %w[GET POST])
273
+
274
+ params = {}
275
+ params[:file_format] = file_format.downcase unless file_format.nil?
276
+ params[:status_callback_url] = status_callback_url unless status_callback_url.nil?
277
+ params[:status_callback_method] = status_callback_method.upcase unless status_callback_method.nil?
278
+
279
+ perform_action_apiresponse('Record', 'POST', params, true)
280
+ end
281
+
282
+ def stop_participant_recording
283
+ perform_action_apiresponse('Record', 'DELETE')
284
+ end
285
+
286
+ def pause_participant_recording
287
+ perform_action_apiresponse('Record/Pause', 'POST')
288
+ end
289
+
290
+ def resume_participant_recording
291
+ perform_action_apiresponse('Record/Resume', 'POST')
292
+ end
293
+
294
+ def update_participant(coach_mode = nil, mute= nil, hold = nil)
295
+ valid_param?(:coach_mode, coach_mode, [TrueClass, FalseClass], false) unless coach_mode.nil?
296
+ valid_param?(:mute, mute, [TrueClass, FalseClass], false) unless mute.nil?
297
+ valid_param?(:hold, hold, [TrueClass, FalseClass], false) unless hold.nil?
298
+ params = {}
299
+ params[:coach_mode] = coach_mode unless coach_mode.nil?
300
+ params[:mute] = mute unless mute.nil?
301
+ params[:hold] = hold unless hold.nil?
302
+ perform_action_apiresponse(nil, 'POST', params, true )
303
+ end
304
+
305
+ def kick_participant
306
+ perform_action_apiresponse(nil, 'DELETE', nil, true)
307
+ end
308
+
309
+ def get_participant
310
+ perform_action_apiresponse(nil,'GET',nil,false)
311
+ end
312
+ end
313
+
314
+ class MultiPartyCallInterface < Base::ResourceInterface
315
+ def initialize(client, resource_list_json = nil)
316
+ @_name = 'MultiPartyCall'
317
+ @_resource_type = MultiPartyCall
318
+ @_identifier_string = 'mpc_uuid'
319
+ super
320
+ @_is_voice_request = true
321
+ end
322
+
323
+ def make_mpc_id(uuid=nil, friendly_name=nil)
324
+ if not uuid and not friendly_name
325
+ raise_invalid_request('specify either multi party call friendly name or uuid')
326
+ end
327
+ if uuid and friendly_name
328
+ raise_invalid_request('cannot specify both multi party call friendly name or uuid')
329
+ end
330
+ if uuid
331
+ identifier = ['uuid', uuid]
332
+ else
333
+ identifier = ['name', friendly_name]
334
+ end
335
+ return identifier
336
+ end
337
+
338
+ def list(options={})
339
+ valid_param?(:options, options, Hash, false)
340
+ valid_subaccount?(options[:sub_account], true) unless options[:sub_account].nil?
341
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
342
+ valid_param?(:status, options[:status].downcase, String, false, %w[initialized active ended]) unless options[:status].nil?
343
+ valid_param?(:termination_cause_code, options[:termination_cause_code], Integer, false) unless options[:termination_cause_code].nil?
344
+ valid_date_format?(:end_time__gt, options[:end_time__gt], false ) unless options[:end_time__gt].nil?
345
+ valid_date_format?(:end_time__gte, options[:end_time__gte], false ) unless options[:end_time__gte].nil?
346
+ valid_date_format?(:end_time__lt, options[:end_time__lt], String) unless options[:end_time__lt].nil?
347
+ valid_date_format?(:end_time__lte, options[:end_time__lte], false) unless options[:end_time__lte].nil?
348
+ valid_date_format?(:creation_time__gt, options[:creation_time__gt], false) unless options[:creation_time__gt].nil?
349
+ valid_date_format?(:creation_time__gte, options[:creation_time__gte], false) unless options[:creation_time__gte].nil?
350
+ valid_date_format?(:creation_time__lt, options[:creation_time__lt], false) unless options[:creation_time__lt].nil?
351
+ valid_date_format?(:creation_time__lte, options[:creation_time__lte], false) unless options[:creation_time__lte].nil?
352
+ valid_range?(:limit, options[:limit], false, 1, 20)
353
+ valid_range?(:offset, options[:offset], false, 0)
354
+ perform_action(nil ,'GET', options ,true )
355
+ end
356
+
357
+ def get(options = {})
358
+ valid_param?(:options, options, Hash, false)
359
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
360
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
361
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
362
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).get
363
+ end
364
+
365
+ def add_participant(options = {})
366
+ valid_param?(:options, options, Hash, false)
367
+ if not options[:role ]
368
+ raise_invalid_request("Role is mandatory")
369
+ end
370
+ options[:call_status_callback_method] = 'POST' unless options.key?(:call_status_callback_method)
371
+ options[:confirm_key_sound_method] = 'GET' unless options.key?(:confirm_key_sound_method)
372
+ options[:dial_music] = 'Real' unless options.key?(:dial_music)
373
+ options[:ring_timeout] = 45 unless options.key?(:ring_timeout)
374
+ options[:delay_dial] = 0 unless options.key?(:delay_dial)
375
+ options[:max_duration] = 14400 unless options.key?(:max_duration)
376
+ options[:max_participants] = 10 unless options.key?(:max_participants)
377
+ options[:wait_music_method] = 'GET' unless options.key?(:wait_music_method)
378
+ options[:agent_hold_music_method] = 'GET' unless options.key?(:agent_hold_music_method)
379
+ options[:customer_hold_music_method] = 'GET' unless options.key?(:customer_hold_music_method)
380
+ options[:recording_callback_method] ='GET' unless options.key?(:recording_callback_method)
381
+ options[:status_callback_method] = 'GET' unless options.key?(:status_callback_method)
382
+ options[:on_exit_action_method] = 'POST' unless options.key?(:on_exit_action_method)
383
+ options[:record] = false unless options.key?(:record)
384
+ options[:record_file_format] = 'mp3' unless options.key?(:record_file_format)
385
+ options[:status_callback_events] = 'mpc-state-changes,participant-state-changes' unless options.key?(:status_callback_events)
386
+ options[:stay_alone] = false unless options.key?(:stay_alone)
387
+ options[:coach_mode] = true unless options.key?(:coach_mode)
388
+ options[:mute] = false unless options.key?(:mute)
389
+ options[:hold] = false unless options.key?(:hold)
390
+ options[:start_mpc_on_enter] = true unless options.key?(:start_mpc_on_enter)
391
+ options[:end_mpc_on_exit] = false unless options.key?(:end_mpc_on_exit)
392
+ options[:relay_dtmf_inputs] = false unless options.key?(:relay_dtmf_inputs)
393
+ options[:enter_sound] = 'beep:1' unless options.key?(:enter_sound)
394
+ options[:enter_sound_method] = 'GET' unless options.key?(:enter_sound_method)
395
+ options[:exit_sound] = 'beep:2' unless options.key?(:exit_sound)
396
+ options[:exit_sound_method] = 'GET' unless options.key?(:exit_sound_method)
397
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
398
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
399
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
400
+
401
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).add_participant(options[:role],options[:from],options[:to],options[:call_uuid],options[:caller_name],options[:call_status_callback_url],options[:call_status_callback_method],options[:sip_headers],options[:confirm_key],
402
+ options[:confirm_key_sound_url],options[:confirm_key_sound_method],options[:dial_music],options[:ring_timeout],options[:delay_dial],options[:max_duration], options[:max_participants],options[:wait_music_url],
403
+ options[:wait_music_method],options[:agent_hold_music_url],options[:agent_hold_music_method],options[:customer_hold_music_url],options[:customer_hold_music_method],
404
+ options[:recording_callback_url],options[:recording_callback_method],options[:status_callback_url],options[:status_callback_method],options[:on_exit_action_url], options[:on_exit_action_method],
405
+ options[:record],options[:record_file_format],options[:status_callback_events],options[:stay_alone], options[:coach_mode],options[:mute],options[:hold],options[:start_mpc_on_enter],options[:end_mpc_on_exit],
406
+ options[:relay_dtmf_inputs],options[:enter_sound],options[:enter_sound_method],options[:exit_sound],options[:exit_sound_method])
407
+ end
408
+
409
+ def start(options = {})
410
+ valid_param?(:options, options, Hash, false)
411
+ valid_param?(:uuid, options[:uuid], String, false)
412
+ valid_param?(:friendly_name, options[:friendly_name], String, false)
413
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
414
+ MultiPartyCall.new(@_client,resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).start
415
+ end
416
+
417
+ def stop(options = {})
418
+ valid_param?(:options, options, Hash, false)
419
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
420
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
421
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
422
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).stop
423
+ end
424
+
425
+ def start_recording(options = {})
426
+ valid_param?(:options, options, Hash, false)
427
+ options[:file_format] = 'mp3' unless options.key?(:file_format)
428
+ options[:status_callback_method] = 'POST' unless options.key?(:status_callback_method)
429
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
430
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
431
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
432
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).start_recording(options[:file_format], options[:status_callback_url], options[:status_callback_method])
433
+ end
434
+
435
+ def stop_recording(options = {})
436
+ valid_param?(:options, options, Hash, false)
437
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
438
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
439
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
440
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).stop_recording
441
+ end
442
+
443
+ def pause_recording(options = {})
444
+ valid_param?(:options, options, Hash, false)
445
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
446
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
447
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
448
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).pause_recording
449
+ end
450
+
451
+ def resume_recording(options = {})
452
+ valid_param?(:options, options, Hash, false)
453
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
454
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
455
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
456
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).resume_recording
457
+ end
458
+
459
+ def start_participant_recording(options = {})
460
+ valid_param?(:options, options, Hash, false)
461
+ if not options[:member_id]
462
+ raise_invalid_request("Member Id is mandatory")
463
+ end
464
+ options[:file_format] = 'mp3' unless options.key?(:file_format)
465
+ options[:status_callback_method] = 'POST' unless options.key?(:status_callback_method)
466
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
467
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
468
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
469
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
470
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).start_participant_recording(options[:file_format], options[:status_callback_url], options[:status_callback_method])
471
+ end
472
+
473
+ def stop_participant_recording(options = {})
474
+ valid_param?(:options, options, Hash, false)
475
+ if not options[:member_id]
476
+ raise_invalid_request("Member Id is mandatory")
477
+ end
478
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
479
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
480
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
481
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
482
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).stop_participant_recording
483
+ end
484
+
485
+ def pause_participant_recording(options = {})
486
+ valid_param?(:options, options, Hash, false)
487
+ if not options[:member_id]
488
+ raise_invalid_request("Member Id is mandatory")
489
+ end
490
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
491
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
492
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
493
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
494
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).pause_participant_recording
495
+ end
496
+
497
+ def resume_participant_recording(options = {})
498
+ valid_param?(:options, options, Hash, false)
499
+ if not options[:member_id]
500
+ raise_invalid_request("Member Id is mandatory")
501
+ end
502
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
503
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
504
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
505
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
506
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).resume_participant_recording
507
+ end
508
+
509
+ def list_participants(options = {})
510
+ valid_param?(:options, options, Hash, false)
511
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
512
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
513
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
514
+ MultiPartyCall.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0]).list_participants(options[:call_uuid])
515
+ end
516
+
517
+ def update_participant(options = {})
518
+ valid_param?(:options, options, Hash, false)
519
+ if not options[:member_id]
520
+ raise_invalid_request("Member Id is mandatory")
521
+ end
522
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
523
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
524
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
525
+ mpc_id = self.make_mpc_id(options[:uuid], options[:friendly_name])
526
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).update_participant(options[:coach_mode], options[:mute], options[:hold])
527
+ end
528
+
529
+ def kick_participant(options = {})
530
+ valid_param?(:options, options, Hash, false)
531
+ if not options[:member_id]
532
+ raise_invalid_request("Member Id is mandatory")
533
+ end
534
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
535
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
536
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
537
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
538
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).kick_participant
539
+ end
540
+
541
+ def get_participant(options = {})
542
+ valid_param?(:options, options, Hash, false)
543
+ if not options[:member_id]
544
+ raise_invalid_request("Member Id is mandatory")
545
+ end
546
+ valid_param?(:member_id, options[:member_id], [String, Integer], true)
547
+ valid_param?(:uuid, options[:uuid], String, false) unless options[:uuid].nil?
548
+ valid_param?(:friendly_name, options[:friendly_name], String, false) unless options[:friendly_name].nil?
549
+ mpc_id = make_mpc_id(options[:uuid], options[:friendly_name])
550
+ MultiPartyCallParticipant.new(@_client, resource_id: mpc_id[1], multi_party_prefix: mpc_id[0], member_id: options[:member_id]).get_participant
551
+ end
552
+ end
553
+ end
554
+ end
@@ -8,7 +8,7 @@ module Plivo
8
8
  # Resources
9
9
  attr_reader :messages, :account, :subaccounts, :recordings
10
10
  attr_reader :pricings, :numbers, :calls, :conferences
11
- attr_reader :phone_numbers, :applications, :endpoints
11
+ attr_reader :phone_numbers, :applications, :endpoints, :multipartycalls
12
12
  attr_reader :addresses, :identities
13
13
  attr_reader :call_feedback
14
14
  attr_reader :powerpacks
@@ -51,6 +51,7 @@ module Plivo
51
51
  @addresses = Resources::AddressInterface.new(self)
52
52
  @identities = Resources::IdentityInterface.new(self)
53
53
  @call_feedback = Resources::CallFeedbackInterface.new(self)
54
+ @multipartycalls = Resources::MultiPartyCallInterface.new( self)
54
55
  @lookup = Resources::LookupInterface.new(self)
55
56
  @end_users = Resources::EndUsersInterface.new(self)
56
57
  @compliance_document_types = Resources::ComplianceDocumentTypesInterface.new(self)
data/lib/plivo/utils.rb CHANGED
@@ -67,6 +67,117 @@ module Plivo
67
67
  expected_value?(param_name, expected_values, param_value)
68
68
  end
69
69
 
70
+ def valid_multiple_destination_nos?(param_name, param_value, options = nil)
71
+ if param_value.split(options[:delimiter]).size > 1 && options[:role].downcase != 'agent'
72
+ raise_invalid_request("Multiple #{param_name} values given for role #{options[:role]}")
73
+ elsif param_value.split(options[:delimiter]).size >= options[:agent_limit]
74
+ raise_invalid_request("No of #{param_name} values provided should be lesser than #{options[:agent_limit]}")
75
+ else
76
+ return true
77
+ end
78
+ end
79
+
80
+ def valid_multiple_destination_integers?(param_name, param_value)
81
+ if (param_value.is_a? String)
82
+ values = param_value.split("<")
83
+ for i in values
84
+ unless (Integer(i) rescue false)
85
+ raise_invalid_request("#{param_name} Destination Value must be integer")
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def valid_url?(param_name, param_value, mandatory = false)
92
+ if mandatory && param_value.nil?
93
+ raise_invalid_request("#{param_name} is a required parameter")
94
+ end
95
+
96
+ return true if param_value.nil?
97
+ return raise_invalid_request("#{param_name}: Expected a String but received #{param_value.class} instead") unless expected_type?(param_name, String, param_value)
98
+
99
+ if param_value =~ /^(http[s]?:\/\/([a-zA-Z]|[0-9]|[\$\-\_\@\.\&\+\/\#]|[\!\*\(\)\,]|(%[0-9a-fA-F][0-9a-fA-F]))+|nil)$/ix
100
+ return true
101
+ else
102
+ return raise_invalid_request("Invalid URL : Doesn't satisfy the URL format")
103
+ end
104
+ end
105
+
106
+ def valid_range?(param_name, param_value, mandatory = false, lower_bound = nil, upper_bound = nil)
107
+ if mandatory && param_value.nil?
108
+ raise_invalid_request("#{param_name} is a required parameter")
109
+ end
110
+
111
+ return true if param_value.nil?
112
+
113
+ return raise_invalid_request("#{param_name}: Expected an Integer but received #{param_value.class} instead") unless expected_type?(param_name, Integer, param_value)
114
+ if lower_bound && upper_bound
115
+ return raise_invalid_request("#{param_name} ranges between #{lower_bound} and #{upper_bound}") if param_value < lower_bound or param_value > upper_bound
116
+
117
+ return true if param_value >= lower_bound and param_value <= upper_bound
118
+ elsif lower_bound
119
+ return raise_invalid_request("#{param_name} should be greater than #{lower_bound}") if param_value < lower_bound
120
+
121
+ return true if param_value >= lower_bound
122
+ elsif upper_bound
123
+ return raise_invalid_request("#{param_name} should be lesser than #{upper_bound}") if param_value > upper_bound
124
+
125
+ return true if param_value <= upper_bound
126
+ else
127
+ return raise_invalid_request("Any one or both of lower and upper bound should be provided")
128
+ end
129
+ end
130
+
131
+ def multi_valid_param?(param_name, param_value, expected_types = nil, mandatory = false, expected_values = nil, make_down_case = false, seperator = ',')
132
+ if mandatory && param_value.nil?
133
+ raise_invalid_request("#{param_name} is a required parameter")
134
+ end
135
+
136
+ return true if param_value.nil?
137
+
138
+ if make_down_case
139
+ param_value = param_value.downcase
140
+ else
141
+ param_value = param_value.uppercase
142
+ end
143
+
144
+ for val in param_value.split(seperator)
145
+ return expected_type?(param_name, expected_types, val.strip) unless expected_values
146
+ expected_value?(param_name, expected_values, val.strip)
147
+ end
148
+ end
149
+
150
+ def valid_date_format?(param_name, param_value, mandatory = false)
151
+ if mandatory && param_value.nil?
152
+ raise_invalid_request("#{param_name} is a required parameter")
153
+ end
154
+
155
+ return true if param_value.nil?
156
+
157
+ if param_value =~ /^(\d{4}\-\d{2}\-\d{2}\ \d{2}\:\d{2}(\:\d{2}(\.\d{1,6})?)?)$/ix
158
+ return true
159
+ else
160
+ return raise_invalid_request("Invalid Date Format")
161
+ end
162
+ end
163
+
164
+ def is_one_among_string_url?(param_name, param_value, mandatory = false, expected_values= nil)
165
+ if mandatory && param_value.nil?
166
+ raise_invalid_request("#{param_name} is a required parameter")
167
+ end
168
+
169
+ return true if param_value.nil?
170
+ return raise_invalid_request("#{param_name}: Expected a String but received #{param_value.class} instead") unless expected_type?(param_name, String, param_value)
171
+
172
+ if expected_values.include? param_value.downcase or expected_values.include? param_value.upcase
173
+ return true
174
+ elsif valid_url?(param_name, param_value)
175
+ return true
176
+ else
177
+ raise_invalid_request("#{param_name} neither a valid URL nor in the expected values")
178
+ end
179
+ end
180
+
70
181
  def expected_type?(param_name, expected_types, param_value)
71
182
  return true if expected_types.nil?
72
183
  param_value_class = param_value.class
data/lib/plivo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = "4.16.0".freeze
2
+ VERSION = "4.19.0".freeze
3
3
  end
data/lib/plivo/xml.rb CHANGED
@@ -29,7 +29,7 @@ require_relative 'xml/say_as'
29
29
  require_relative 'xml/sub'
30
30
  require_relative 'xml/w'
31
31
  require_relative 'xml/plivo_xml'
32
-
32
+ require_relative 'xml/multipartycall'
33
33
  include Plivo::Exceptions
34
34
 
35
35
  module Plivo
@@ -0,0 +1,188 @@
1
+ module Plivo
2
+ module XML
3
+ class MultiPartyCall < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[role maxDuration maxParticipants waitMusicUrl
6
+ waitMusicMethod agentHoldMusicUrl agentHoldMusicMethod
7
+ customerHoldMusicUrl customerHoldMusicMethod record
8
+ recordFileFormat recordingCallbackUrl recordingCallbackMethod
9
+ statusCallbackEvents statusCallbackUrl statusCallbackMethod
10
+ stayAlone coachMode mute hold startMpcOnEnter endMpcOnExit
11
+ enterSound enterSoundMethod exitSound exitSoundMethod
12
+ onExitActionUrl onExitActionMethod relayDTMFInputs]
13
+
14
+ VALID_ROLE_VALUES = %w[agent supervisor customer]
15
+ VALID_METHOD_VALUES = %w[GET POST]
16
+ VALID_BOOL_VALUES = [true, false]
17
+ VALID_RECORD_FILE_FORMAT_VALUES = %w[mp3 wav]
18
+
19
+ def initialize(body, attributes = {})
20
+ if attributes[:role] && !VALID_ROLE_VALUES.include?(attributes[:role].downcase)
21
+ raise PlivoXMLError, "invalid attribute value #{attributes[:role]} for role"
22
+ elsif !attributes[:role]
23
+ raise PlivoXMLError, "role not mentioned : possible values - Agent / Supervisor / Customer"
24
+ end
25
+
26
+ if attributes[:maxDuration] && (attributes[:maxDuration]<300 || attributes[:maxDuration]>28800)
27
+ raise PlivoXMLError, "invalid attribute value #{attributes[:maxDuration]} for maxDuration"
28
+ elsif !attributes[:maxDuration]
29
+ attributes[:maxDuration] = 14400
30
+ end
31
+
32
+ if attributes[:maxParticipants] && (attributes[:maxParticipants]<2 || attributes[:maxParticipants]>10)
33
+ raise PlivoXMLError, "invalid attribute value #{attributes[:maxParticipants]} for maxParticipants"
34
+ elsif !attributes[:maxParticipants]
35
+ attributes[:maxParticipants] = 10
36
+ end
37
+
38
+ if attributes[:waitMusicMethod] && !VALID_METHOD_VALUES.include?(attributes[:waitMusicMethod].upcase)
39
+ raise PlivoXMLError, "invalid attribute value #{attributes[:waitMusicMethod]} for waitMusicMethod"
40
+ elsif !attributes[:waitMusicMethod]
41
+ attributes[:waitMusicMethod] = 'GET'
42
+ end
43
+
44
+ if attributes[:agentHoldMusicMethod] && !VALID_METHOD_VALUES.include?(attributes[:agentHoldMusicMethod].upcase)
45
+ raise PlivoXMLError, "invalid attribute value #{attributes[:agentHoldMusicMethod]} for agentHoldMusicMethod"
46
+ elsif !attributes[:agentHoldMusicMethod]
47
+ attributes[:agentHoldMusicMethod] = 'GET'
48
+ end
49
+
50
+ if attributes[:customerHoldMusicMethod] && !VALID_METHOD_VALUES.include?(attributes[:customerHoldMusicMethod].upcase)
51
+ raise PlivoXMLError, "invalid attribute value #{attributes[:customerHoldMusicMethod]} for customerHoldMusicMethod"
52
+ elsif !attributes[:customerHoldMusicMethod]
53
+ attributes[:customerHoldMusicMethod] = 'GET'
54
+ end
55
+
56
+ if attributes[:record] && !VALID_BOOL_VALUES.include?(attributes[:record])
57
+ raise PlivoXMLError, "invalid attribute value #{attributes[:record]} for record"
58
+ elsif !attributes[:record]
59
+ attributes[:record] = false
60
+ end
61
+
62
+ if attributes[:recordFileFormat] && !VALID_RECORD_FILE_FORMAT_VALUES.include?(attributes[:recordFileFormat])
63
+ raise PlivoXMLError, "invalid attribute value #{attributes[:recordFileFormat]} for recordFileFormat"
64
+ elsif !attributes[:recordFileFormat]
65
+ attributes[:recordFileFormat] = 'mp3'
66
+ end
67
+
68
+ if attributes[:recordingCallbackMethod] && !VALID_METHOD_VALUES.include?(attributes[:recordingCallbackMethod].upcase)
69
+ raise PlivoXMLError, "invalid attribute value #{attributes[:recordingCallbackMethod]} for recordingCallbackMethod"
70
+ elsif !attributes[:recordingCallbackMethod]
71
+ attributes[:recordingCallbackMethod] = 'GET'
72
+ end
73
+
74
+ if attributes[:statusCallbackEvents] && !multi_valid_param?(:statusCallbackEvents, attributes[:statusCallbackEvents], String, false, %w[mpc-state-changes participant-state-changes participant-speak-events participant-digit-input-events add-participant-api-events], true, ',') == true
75
+ raise PlivoXMLError, "invalid attribute value #{attributes[:statusCallbackEvents]} for statusCallbackEvents"
76
+ elsif !attributes[:statusCallbackEvents]
77
+ attributes[:statusCallbackEvents] = 'mpc-state-changes,participant-state-changes'
78
+ end
79
+
80
+ if attributes[:statusCallbackMethod] && !VALID_METHOD_VALUES.include?(attributes[:statusCallbackMethod].upcase)
81
+ raise PlivoXMLError, "invalid attribute value #{attributes[:statusCallbackMethod]} for statusCallbackMethod"
82
+ elsif !attributes[:statusCallbackMethod]
83
+ attributes[:statusCallbackMethod] = 'POST'
84
+ end
85
+
86
+ if attributes[:stayAlone] && !VALID_BOOL_VALUES.include?(attributes[:stayAlone])
87
+ raise PlivoXMLError, "invalid attribute value #{attributes[:stayAlone]} for stayAlone"
88
+ elsif !attributes[:stayAlone]
89
+ attributes[:stayAlone] = false
90
+ end
91
+
92
+ if attributes[:coachMode] && !VALID_BOOL_VALUES.include?(attributes[:coachMode])
93
+ raise PlivoXMLError, "invalid attribute value #{attributes[:coachMode]} for coachMode"
94
+ elsif !attributes[:coachMode]
95
+ attributes[:coachMode] = true
96
+ end
97
+
98
+ if attributes[:mute] && !VALID_BOOL_VALUES.include?(attributes[:mute])
99
+ raise PlivoXMLError, "invalid attribute value #{attributes[:mute]} for mute"
100
+ elsif !attributes[:mute]
101
+ attributes[:mute] = false
102
+ end
103
+
104
+ if attributes[:hold] && !VALID_BOOL_VALUES.include?(attributes[:hold])
105
+ raise PlivoXMLError, "invalid attribute value #{attributes[:hold]} for hold"
106
+ elsif !attributes[:hold]
107
+ attributes[:hold] = false
108
+ end
109
+
110
+ if attributes[:startMpcOnEnter] && !VALID_BOOL_VALUES.include?(attributes[:startMpcOnEnter])
111
+ raise PlivoXMLError, "invalid attribute value #{attributes[:startMpcOnEnter]} for startMpcOnEnter"
112
+ elsif !attributes[:startMpcOnEnter]
113
+ attributes[:startMpcOnEnter] = true
114
+ end
115
+
116
+ if attributes[:endMpcOnExit] && !VALID_BOOL_VALUES.include?(attributes[:endMpcOnExit])
117
+ raise PlivoXMLError, "invalid attribute value #{attributes[:endMpcOnExit]} for endMpcOnExit"
118
+ elsif !attributes[:endMpcOnExit]
119
+ attributes[:endMpcOnExit] = false
120
+ end
121
+
122
+ if attributes[:enterSound] && !is_one_among_string_url?(:enterSound, attributes[:enterSound], false, %w[beep:1 beep:2 none])
123
+ raise PlivoXMLError, "invalid attribute value #{attributes[:enterSound]} for enterSound"
124
+ elsif !attributes[:enterSound]
125
+ attributes[:enterSound] = 'beep:1'
126
+ end
127
+
128
+ if attributes[:enterSoundMethod] && !VALID_METHOD_VALUES.include?(attributes[:enterSoundMethod].upcase)
129
+ raise PlivoXMLError, "invalid attribute value #{attributes[:enterSoundMethod]} for enterSoundMethod"
130
+ elsif !attributes[:enterSoundMethod]
131
+ attributes[:enterSoundMethod] = 'GET'
132
+ end
133
+
134
+ if attributes[:exitSound] && !is_one_among_string_url?(:exitSound, attributes[:exitSound], false, %w[beep:1 beep:2 none])
135
+ raise PlivoXMLError, "invalid attribute value #{attributes[:exitSound]} for exitSound"
136
+ elsif !attributes[:exitSound]
137
+ attributes[:exitSound] = 'beep:2'
138
+ end
139
+
140
+ if attributes[:exitSoundMethod] && !VALID_METHOD_VALUES.include?(attributes[:exitSoundMethod].upcase)
141
+ raise PlivoXMLError, "invalid attribute value #{attributes[:exitSoundMethod]} for exitSoundMethod"
142
+ elsif !attributes[:exitSoundMethod]
143
+ attributes[:exitSoundMethod] = 'GET'
144
+ end
145
+
146
+ if attributes[:onExitActionMethod] && !VALID_METHOD_VALUES.include?(attributes[:onExitActionMethod].upcase)
147
+ raise PlivoXMLError, "invalid attribute value #{attributes[:onExitActionMethod]} for onExitActionMethod"
148
+ elsif !attributes[:onExitActionMethod]
149
+ attributes[:onExitActionMethod] = 'POST'
150
+ end
151
+
152
+ if attributes[:relayDTMFInputs] && !VALID_BOOL_VALUES.include?(attributes[:relayDTMFInputs])
153
+ raise PlivoXMLError, "invalid attribute value #{attributes[:relayDTMFInputs]} for relayDTMFInputs"
154
+ elsif !attributes[:relayDTMFInputs]
155
+ attributes[:relayDTMFInputs] = false
156
+ end
157
+
158
+ if attributes[:waitMusicUrl] && !valid_url?(:waitMusicUrl, attributes[:waitMusicUrl], false)
159
+ raise PlivoXMLError, "invalid attribute value #{attributes[:waitMusicUrl]} for waitMusicUrl"
160
+ end
161
+
162
+ if attributes[:agentHoldMusicUrl] && !valid_url?(:agentHoldMusicUrl, attributes[:agentHoldMusicUrl], false)
163
+ raise PlivoXMLError, "invalid attribute value #{attributes[:agentHoldMusicUrl]} for agentHoldMusicUrl"
164
+ end
165
+
166
+ if attributes[:customerHoldMusicUrl] && !valid_url?(:customerHoldMusicUrl, attributes[:customerHoldMusicUrl], false)
167
+ raise PlivoXMLError, "invalid attribute value #{attributes[:customerHoldMusicUrl]} for customerHoldMusicUrl"
168
+ end
169
+
170
+ if attributes[:recordingCallbackUrl] && !valid_url?(:recordingCallbackUrl, attributes[:recordingCallbackUrl], false)
171
+ raise PlivoXMLError, "invalid attribute value #{attributes[:recordingCallbackUrl]} for recordingCallbackUrl"
172
+ end
173
+
174
+ if attributes[:statusCallbackUrl] && !valid_url?(:statusCallbackUrl, attributes[:statusCallbackUrl], false)
175
+ raise PlivoXMLError, "invalid attribute value #{attributes[:statusCallbackUrl]} for statusCallbackUrl"
176
+ end
177
+
178
+ if attributes[:customerHoldMusicUrl] && !valid_url?(:customerHoldMusicUrl, attributes[:customerHoldMusicUrl], false)
179
+ raise PlivoXMLError, "invalid attribute value #{attributes[:customerHoldMusicUrl]} for customerHoldMusicUrl"
180
+ end
181
+
182
+ raise PlivoXMLError, 'No MPC name set for the MPC' unless body
183
+ super(body, attributes)
184
+ end
185
+
186
+ end
187
+ end
188
+ end
@@ -2,7 +2,7 @@ module Plivo
2
2
  module XML
3
3
  class Response < Element
4
4
  @nestables = %w[Speak Play GetDigits GetInput Record Dial Message
5
- Redirect Wait Hangup PreAnswer Conference DTMF]
5
+ Redirect Wait Hangup PreAnswer Conference DTMF MultiPartyCall]
6
6
  @valid_attributes = []
7
7
 
8
8
  def initialize
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plivo
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.16.0
4
+ version: 4.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Plivo SDKs Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -190,6 +190,7 @@ files:
190
190
  - lib/plivo/resources/lookup.rb
191
191
  - lib/plivo/resources/media.rb
192
192
  - lib/plivo/resources/messages.rb
193
+ - lib/plivo/resources/multipartycalls.rb
193
194
  - lib/plivo/resources/nodes.rb
194
195
  - lib/plivo/resources/numbers.rb
195
196
  - lib/plivo/resources/phlo_member.rb
@@ -213,6 +214,7 @@ files:
213
214
  - lib/plivo/xml/hangup.rb
214
215
  - lib/plivo/xml/lang.rb
215
216
  - lib/plivo/xml/message.rb
217
+ - lib/plivo/xml/multipartycall.rb
216
218
  - lib/plivo/xml/number.rb
217
219
  - lib/plivo/xml/p.rb
218
220
  - lib/plivo/xml/phoneme.rb