plivo 0.3.19 → 4.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/AUTHORS.md +4 -0
  6. data/CHANGELOG.md +158 -0
  7. data/Gemfile +10 -0
  8. data/Jenkinsfile +7 -0
  9. data/LICENSE.txt +19 -0
  10. data/README.md +155 -24
  11. data/Rakefile +9 -0
  12. data/ci/config.yml +7 -0
  13. data/examples/conference_bridge.rb +108 -0
  14. data/examples/jwt.rb +32 -0
  15. data/examples/lookup.rb +24 -0
  16. data/examples/multi_party_call.rb +295 -0
  17. data/examples/phlos.rb +55 -0
  18. data/examples/regulatory_compliance.rb +167 -0
  19. data/lib/plivo/base/resource.rb +148 -0
  20. data/lib/plivo/base/resource_interface.rb +108 -0
  21. data/lib/plivo/base/response.rb +38 -0
  22. data/lib/plivo/base.rb +17 -0
  23. data/lib/plivo/base_client.rb +393 -0
  24. data/lib/plivo/exceptions.rb +50 -0
  25. data/lib/plivo/jwt.rb +120 -0
  26. data/lib/plivo/phlo_client.rb +29 -0
  27. data/lib/plivo/resources/accounts.rb +181 -0
  28. data/lib/plivo/resources/addresses.rb +302 -0
  29. data/lib/plivo/resources/applications.rb +258 -0
  30. data/lib/plivo/resources/call_feedback.rb +55 -0
  31. data/lib/plivo/resources/calls.rb +559 -0
  32. data/lib/plivo/resources/conferences.rb +367 -0
  33. data/lib/plivo/resources/endpoints.rb +132 -0
  34. data/lib/plivo/resources/identities.rb +319 -0
  35. data/lib/plivo/resources/lookup.rb +88 -0
  36. data/lib/plivo/resources/media.rb +97 -0
  37. data/lib/plivo/resources/messages.rb +215 -0
  38. data/lib/plivo/resources/multipartycalls.rb +554 -0
  39. data/lib/plivo/resources/nodes.rb +83 -0
  40. data/lib/plivo/resources/numbers.rb +319 -0
  41. data/lib/plivo/resources/phlo_member.rb +64 -0
  42. data/lib/plivo/resources/phlos.rb +55 -0
  43. data/lib/plivo/resources/powerpacks.rb +717 -0
  44. data/lib/plivo/resources/pricings.rb +43 -0
  45. data/lib/plivo/resources/recordings.rb +116 -0
  46. data/lib/plivo/resources/regulatory_compliance.rb +610 -0
  47. data/lib/plivo/resources.rb +25 -0
  48. data/lib/plivo/rest_client.rb +63 -0
  49. data/lib/plivo/utils.rb +294 -0
  50. data/lib/plivo/version.rb +3 -0
  51. data/lib/plivo/xml/break.rb +31 -0
  52. data/lib/plivo/xml/conference.rb +20 -0
  53. data/lib/plivo/xml/cont.rb +13 -0
  54. data/lib/plivo/xml/dial.rb +16 -0
  55. data/lib/plivo/xml/dtmf.rb +13 -0
  56. data/lib/plivo/xml/element.rb +106 -0
  57. data/lib/plivo/xml/emphasis.rb +17 -0
  58. data/lib/plivo/xml/get_digits.rb +15 -0
  59. data/lib/plivo/xml/get_input.rb +16 -0
  60. data/lib/plivo/xml/hangup.rb +12 -0
  61. data/lib/plivo/xml/lang.rb +29 -0
  62. data/lib/plivo/xml/message.rb +13 -0
  63. data/lib/plivo/xml/multipartycall.rb +188 -0
  64. data/lib/plivo/xml/number.rb +13 -0
  65. data/lib/plivo/xml/p.rb +12 -0
  66. data/lib/plivo/xml/phoneme.rb +20 -0
  67. data/lib/plivo/xml/play.rb +13 -0
  68. data/lib/plivo/xml/plivo_xml.rb +19 -0
  69. data/lib/plivo/xml/pre_answer.rb +12 -0
  70. data/lib/plivo/xml/prosody.rb +28 -0
  71. data/lib/plivo/xml/record.rb +17 -0
  72. data/lib/plivo/xml/redirect.rb +13 -0
  73. data/lib/plivo/xml/response.rb +21 -0
  74. data/lib/plivo/xml/s.rb +12 -0
  75. data/lib/plivo/xml/say_as.rb +24 -0
  76. data/lib/plivo/xml/speak.rb +28 -0
  77. data/lib/plivo/xml/sub.rb +16 -0
  78. data/lib/plivo/xml/user.rb +13 -0
  79. data/lib/plivo/xml/w.rb +17 -0
  80. data/lib/plivo/xml/wait.rb +12 -0
  81. data/lib/plivo/xml.rb +39 -0
  82. data/lib/plivo.rb +12 -815
  83. data/plivo.gemspec +44 -0
  84. metadata +181 -41
  85. data/ext/mkrf_conf.rb +0 -9
@@ -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
@@ -0,0 +1,83 @@
1
+ module Plivo
2
+ module Resources
3
+ class NodeInterface < Base::ResourceInterface
4
+ def initialize(client, resource_list_json=nil)
5
+ super
6
+ end
7
+
8
+ def getNode(node_id, node_type)
9
+ @_resource_uri = ['', 'v1', 'phlo', @_phlo_id, node_type, ''].join('/')
10
+ @_resource_type = configure_node_type(node_type)
11
+ perform_get(node_id)
12
+ end
13
+
14
+ private
15
+ def configure_node_type(node_type)
16
+ case node_type
17
+ when 'multi_party_call'
18
+ PhloMultiPartyCall
19
+ # when 'conference_bridge'
20
+ # ConferenceBridge
21
+ end
22
+ end
23
+ end
24
+
25
+ class Node < Base::Resource
26
+ def initialize(client,options=nil)
27
+ @_identifier_string = 'node_id'
28
+ super
29
+ configure_resource_uri
30
+ end
31
+
32
+ def to_s
33
+ {
34
+ api_id: @api_id,
35
+ node_id: @node_id,
36
+ phlo_id: @phlo_id,
37
+ name: @name,
38
+ node_type: @node_type,
39
+ created_on: @created_on
40
+ }.to_s
41
+ end
42
+
43
+ def member(member_address)
44
+ options = {'member_address' => member_address, 'node_id' => @id, 'phlo_id' => @phlo_id, 'node_type' => @node_type}
45
+ PhloMember.new(@_client, {resource_json: options})
46
+ end
47
+
48
+ private
49
+ def configure_resource_uri
50
+ @_resource_uri = ['', 'v1', 'phlo', @phlo_id, @node_type, @id, ''].join('/')
51
+ end
52
+ end
53
+
54
+ class PhloMultiPartyCall < Node
55
+ def initialize(client,options=nil)
56
+ @_name = 'multi_party_call'
57
+ super
58
+ end
59
+
60
+ def call(trigger_source, to, role)
61
+ payload = {action: 'call', trigger_source: trigger_source, to: to, role: role}
62
+ perform_update(payload)
63
+ end
64
+
65
+ def warm_transfer(trigger_source, to, role='agent')
66
+ payload = {action: 'warm_transfer', trigger_source: trigger_source, to: to, role: role}
67
+ perform_update(payload)
68
+ end
69
+
70
+ def cold_transfer(trigger_source, to, role='agent')
71
+ payload = {action: 'cold_transfer', trigger_source: trigger_source, to: to, role: role}
72
+ perform_update(payload)
73
+ end
74
+ end
75
+
76
+ # class ConferenceBridge < Node
77
+ # def initialize(client,options=nil)
78
+ # @_name = 'conference_bridge'
79
+ # super
80
+ # end
81
+ # end
82
+ end
83
+ end