plivo 0.3.19 → 4.0.0.beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +10 -0
  5. data/AUTHORS.md +4 -0
  6. data/CHANGELOG.md +19 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +19 -0
  9. data/README.md +105 -24
  10. data/Rakefile +7 -0
  11. data/lib/plivo.rb +9 -815
  12. data/lib/plivo/base.rb +9 -0
  13. data/lib/plivo/base/resource.rb +85 -0
  14. data/lib/plivo/base/resource_interface.rb +93 -0
  15. data/lib/plivo/base/response.rb +29 -0
  16. data/lib/plivo/exceptions.rb +50 -0
  17. data/lib/plivo/resources.rb +14 -0
  18. data/lib/plivo/resources/accounts.rb +174 -0
  19. data/lib/plivo/resources/applications.rb +233 -0
  20. data/lib/plivo/resources/calls.rb +492 -0
  21. data/lib/plivo/resources/conferences.rb +371 -0
  22. data/lib/plivo/resources/endpoints.rb +130 -0
  23. data/lib/plivo/resources/messages.rb +178 -0
  24. data/lib/plivo/resources/numbers.rb +302 -0
  25. data/lib/plivo/resources/pricings.rb +43 -0
  26. data/lib/plivo/resources/recordings.rb +114 -0
  27. data/lib/plivo/rest_client.rb +199 -0
  28. data/lib/plivo/utils.rb +107 -0
  29. data/lib/plivo/version.rb +3 -0
  30. data/lib/plivo/xml.rb +27 -0
  31. data/lib/plivo/xml/conference.rb +20 -0
  32. data/lib/plivo/xml/dial.rb +16 -0
  33. data/lib/plivo/xml/dtmf.rb +13 -0
  34. data/lib/plivo/xml/element.rb +83 -0
  35. data/lib/plivo/xml/get_digits.rb +15 -0
  36. data/lib/plivo/xml/hangup.rb +12 -0
  37. data/lib/plivo/xml/message.rb +13 -0
  38. data/lib/plivo/xml/number.rb +13 -0
  39. data/lib/plivo/xml/play.rb +13 -0
  40. data/lib/plivo/xml/plivo_xml.rb +19 -0
  41. data/lib/plivo/xml/pre_answer.rb +12 -0
  42. data/lib/plivo/xml/record.rb +17 -0
  43. data/lib/plivo/xml/redirect.rb +13 -0
  44. data/lib/plivo/xml/response.rb +21 -0
  45. data/lib/plivo/xml/speak.rb +17 -0
  46. data/lib/plivo/xml/user.rb +13 -0
  47. data/lib/plivo/xml/wait.rb +12 -0
  48. data/plivo.gemspec +44 -0
  49. metadata +134 -45
  50. data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,371 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class Conference < Base::Resource
5
+ def initialize(client, options = nil)
6
+ @_name = 'Conference'
7
+ @_identifier_string = 'conference_name'
8
+ super
9
+ end
10
+
11
+ def delete
12
+ perform_delete
13
+ end
14
+
15
+ # @param [String] member_id
16
+ def delete_member(member_id)
17
+ valid_param?(:member_id, member_id, [String, Symbol, Integer, Integer], true)
18
+ perform_action('Member/' + member_id.to_s, 'DELETE', nil, true)
19
+ end
20
+
21
+ # @param [String] member_id
22
+ def kick_member(member_id)
23
+ valid_param?(:member_id, member_id, [String, Symbol, Integer, Integer], true)
24
+ perform_action('Member/' + member_id.to_s + '/Kick', 'POST', nil, true)
25
+ end
26
+
27
+ # @param [Array] member_id
28
+ def mute_member(member_id)
29
+ valid_param?(:member_id, member_id, Array, true)
30
+ member_id.each do |member|
31
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
32
+ end
33
+ perform_action('Member/' + member_id.join(',') + '/Mute',
34
+ 'POST', nil, true)
35
+ end
36
+
37
+ # @param [Array] member_id
38
+ def unmute_member(member_id)
39
+ valid_param?(:member_id, member_id, Array, true)
40
+ member_id.each do |member|
41
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
42
+ end
43
+ perform_action('Member/' + member_id.join(',') + '/Mute', 'DELETE')
44
+ end
45
+
46
+ # @param [Array] member_id
47
+ # @param [String] url
48
+ def play_member(member_id, url)
49
+ valid_param?(:member_id, member_id, Array, true)
50
+ valid_param?(:url, url, String, true)
51
+ member_id.each do |member|
52
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
53
+ end
54
+ perform_action('Member/' + member_id.join(',') + '/Play',
55
+ 'POST', { url: url }, true)
56
+ end
57
+
58
+ # @param [Array] member_id
59
+ def stop_play_member(member_id)
60
+ valid_param?(:member_id, member_id, Array, true)
61
+ member_id.each do |member|
62
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
63
+ end
64
+ perform_action('Member/' + member_id.join(',') + '/Play',
65
+ 'DELETE', nil, true)
66
+ end
67
+
68
+ # @param [Array] member_id
69
+ # @param [String] text - The text that the member must hear.
70
+ # @param [Hash] options
71
+ # @option options [String] :voice - The voice to be used. Can be MAN or WOMAN. Defaults to WOMAN.
72
+ # @option options [String] :language - The language to be used, see Supported voices and languages {https://www.plivo.com/docs/api/conference/member/#supported-voice-and-languages}. Defaults to en-US .
73
+ def speak_member(member_id, text, options = nil)
74
+ valid_param?(:member_id, member_id, Array, true)
75
+ valid_param?(:text, text, String, true)
76
+ member_id.each do |member|
77
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
78
+ end
79
+
80
+ params = { text: text }
81
+
82
+ if options.nil?
83
+ return perform_action('Member/' + member_id.join(',') + '/Speak',
84
+ 'POST', params, true)
85
+ end
86
+
87
+ if options.key?(:voice) &&
88
+ valid_param?(:voice, options[:voice],
89
+ [String, Symbol], true, %w[MAN WOMAN])
90
+ params[:voice] = options[:voice]
91
+ end
92
+
93
+ if options.key?(:language) &&
94
+ valid_param?(:language, options[:language],
95
+ String, true)
96
+ params[:language] = options[:language]
97
+ end
98
+
99
+ perform_action('Member/' + member_id.join(',') + '/Speak',
100
+ 'POST', params, true)
101
+ end
102
+
103
+ # @param [Array] member_id
104
+ def stop_speak_member(member_id)
105
+ valid_param?(:member_id, member_id, Array, true)
106
+ member_id.each do |member|
107
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
108
+ end
109
+ perform_action('Member/' + member_id.join(',') + '/Speak',
110
+ 'DELETE', nil, true)
111
+ end
112
+
113
+ # @param [Array] member_id
114
+ def deaf_member(member_id)
115
+ valid_param?(:member_id, member_id, Array, true)
116
+ member_id.each do |member|
117
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
118
+ end
119
+ perform_action('Member/' + member_id.join(',') + '/Deaf',
120
+ 'POST', nil, true)
121
+ end
122
+
123
+ # @param [Array] member_id
124
+ def undeaf_member(member_id)
125
+ valid_param?(:member_id, member_id, Array, true)
126
+ member_id.each do |member|
127
+ valid_param?(:member, member, [String, Symbol, Integer, Integer], true)
128
+ end
129
+ perform_action('Member/' + member_id.join(',') + '/Deaf',
130
+ 'DELETE', nil, true)
131
+ end
132
+
133
+ # @param [Hash] options
134
+ # @option options [String] :file_format The file format of the record can be of mp3 or wav format. Defaults to mp3 format.
135
+ # @option options [String] :transcription_type The type of transcription required. The following values are allowed:
136
+ # - auto - This is the default value. Transcription is completely automated; turnaround time is about 5 minutes.
137
+ # - hybrid - Transcription is a combination of automated and human verification processes; turnaround time is about 10-15 minutes.
138
+ # @option options [String] :transcription_url The URL where the transcription is available.
139
+ # @option options [String] :transcription_method The method used to invoke the transcription_url. Defaults to POST.
140
+ # @option options [String] :callback_url The URL invoked by the API when the recording ends. The following parameters are sent to the callback_url:
141
+ # - api_id - the same API ID returned by the conference record API.
142
+ # - record_url - the URL to access the recorded file.
143
+ # - recording_id - recording ID of the recorded file.
144
+ # - conference_name - the conference name recorded.
145
+ # - recording_duration - duration in seconds of the recording.
146
+ # - recording_duration_ms - duration in milliseconds of the recording.
147
+ # - recording_start_ms - when the recording started (epoch time UTC) in milliseconds.
148
+ # - recording_end_ms - when the recording ended (epoch time UTC) in milliseconds.
149
+ # @option options [String] :callback_method The method which is used to invoke the callback_url URL. Defaults to POST.
150
+ def record(options = nil)
151
+ return perform_action('Record', 'POST', nil, true) if options.nil?
152
+ valid_param?(:options, options, Hash, true)
153
+
154
+ params = {}
155
+ %i[transcription_url callback_url].each do |param|
156
+ if options.key?(param) &&
157
+ valid_param?(param, options[param], [String, Symbol], true)
158
+ params[param] = options[param]
159
+ end
160
+ end
161
+
162
+ %i[transcription_method callback_method].each do |param|
163
+ if options.key?(param) &&
164
+ valid_param?(param, options[param], [String, Symbol], true, %w[GET POST])
165
+ params[param] = options[param]
166
+ end
167
+ end
168
+
169
+ if options.key?(:file_format) &&
170
+ valid_param?(:file_format, options[:file_format],
171
+ [String, Symbol], true, %w[wav mp3])
172
+ params[:file_format] = options[:file_format]
173
+ end
174
+
175
+ if options.key?(:transcription_type) &&
176
+ valid_param?(:transcription_type, options[:transcription_type],
177
+ [String, Symbol], true, %w[auto hybrid])
178
+ params[:transcription_type] = options[:transcription_type]
179
+ end
180
+
181
+ perform_action('Record', 'POST', params, true)
182
+ end
183
+
184
+ def stop_record
185
+ perform_action('Record', 'DELETE')
186
+ end
187
+
188
+ def to_s
189
+ unless @members.nil?
190
+ members_json = @members.map do |member|
191
+ JSON.parse(to_json_member(member))
192
+ end
193
+ end
194
+ {
195
+ conference_name: @conference_name,
196
+ conference_run_time: @conference_run_time,
197
+ conference_member_count: @conference_member_count,
198
+ members: members_json,
199
+ api_id: @api_id
200
+ }.to_s
201
+ end
202
+
203
+ def to_json_member(member)
204
+ {
205
+ muted: member['muted'],
206
+ member_id: member['member_id'],
207
+ deaf: member['deaf'],
208
+ from: member['from'],
209
+ to: member['to'],
210
+ caller_name: member['caller_name'],
211
+ direction: member['direction'],
212
+ call_uuid: member['call_uuid'],
213
+ join_time: member['join_time']
214
+ }.to_json
215
+ end
216
+ end
217
+
218
+ class ConferenceInterface < Base::ResourceInterface
219
+ def initialize(client, resource_list_json = nil)
220
+ @_name = 'Conference'
221
+ @_resource_type = Conference
222
+ @_identifier_string = 'conference_name'
223
+ super
224
+ end
225
+
226
+ def get(conference_name)
227
+ perform_get(conference_name)
228
+ end
229
+
230
+ def list
231
+ perform_list_without_object
232
+ {
233
+ api_id: @api_id,
234
+ conferences: @conferences
235
+ }
236
+ end
237
+
238
+ def each
239
+ conference_list = list
240
+ conference_list[:conferences].each { |conference| yield conference }
241
+ end
242
+
243
+ def delete_all
244
+ Conference.new(@_client, resource_id: '').delete
245
+ end
246
+
247
+ def delete(conference_name)
248
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
249
+ if conference_name.empty?
250
+ raise_invalid_request('Invalid conference_name passed')
251
+ end
252
+ Conference.new(@_client, resource_id: conference_name).delete
253
+ end
254
+
255
+ # @param [String] conference_name
256
+ # @param [String] member_id
257
+ def delete_member(conference_name, member_id)
258
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
259
+ Conference.new(@_client, resource_id: conference_name)
260
+ .delete_member(member_id)
261
+ end
262
+
263
+ # @param [String] conference_name
264
+ # @param [String] member_id
265
+ def kick_member(conference_name, member_id)
266
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
267
+ Conference.new(@_client, resource_id: conference_name)
268
+ .kick_member(member_id)
269
+ end
270
+
271
+ # @param [String] conference_name
272
+ # @param [Array] member_id
273
+ def mute_member(conference_name, member_id)
274
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
275
+ Conference.new(@_client, resource_id: conference_name)
276
+ .mute_member(member_id)
277
+ end
278
+
279
+ # @param [String] conference_name
280
+ # @param [Array] member_id
281
+ def unmute_member(conference_name, member_id)
282
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
283
+ Conference.new(@_client, resource_id: conference_name)
284
+ .unmute_member(member_id)
285
+ end
286
+
287
+ # @param [String] conference_name
288
+ # @param [Array] member_id
289
+ def play_member(conference_name, member_id, url)
290
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
291
+ Conference.new(@_client, resource_id: conference_name)
292
+ .play_member(member_id, url)
293
+ end
294
+
295
+ # @param [String] conference_name
296
+ # @param [Array] member_id
297
+ def stop_play_member(conference_name, member_id)
298
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
299
+ Conference.new(@_client, resource_id: conference_name)
300
+ .stop_play_member(member_id)
301
+ end
302
+
303
+ # @param [String] conference_name
304
+ # @param [Array] member_id
305
+ # @param [String] text - The text that the member must hear.
306
+ # @param [Hash] options
307
+ # @option options [String] :voice - The voice to be used. Can be MAN or WOMAN. Defaults to WOMAN.
308
+ # @option options [String] :language - The language to be used, see Supported voices and languages {https://www.plivo.com/docs/api/conference/member/#supported-voice-and-languages}. Defaults to en-US .
309
+ def speak_member(conference_name, member_id, text, options = nil)
310
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
311
+ Conference.new(@_client, resource_id: conference_name)
312
+ .speak_member(member_id, text, options)
313
+ end
314
+
315
+ # @param [String] conference_name
316
+ # @param [Array] member_id
317
+ def stop_speak_member(conference_name, member_id)
318
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
319
+ Conference.new(@_client, resource_id: conference_name)
320
+ .stop_speak_member(member_id)
321
+ end
322
+
323
+ # @param [String] conference_name
324
+ # @param [Array] member_id
325
+ def deaf_member(conference_name, member_id)
326
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
327
+ Conference.new(@_client, resource_id: conference_name)
328
+ .deaf_member(member_id)
329
+ end
330
+
331
+ # @param [String] conference_name
332
+ # @param [Array] member_id
333
+ def undeaf_member(conference_name, member_id)
334
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
335
+ Conference.new(@_client, resource_id: conference_name)
336
+ .undeaf_member(member_id)
337
+ end
338
+
339
+ # @param [String] conference_name
340
+ # @param [Hash] options
341
+ # @option options [String] :file_format The file format of the record can be of mp3 or wav format. Defaults to mp3 format.
342
+ # @option options [String] :transcription_type The type of transcription required. The following values are allowed:
343
+ # - auto - This is the default value. Transcription is completely automated; turnaround time is about 5 minutes.
344
+ # - hybrid - Transcription is a combination of automated and human verification processes; turnaround time is about 10-15 minutes.
345
+ # @option options [String] :transcription_url The URL where the transcription is available.
346
+ # @option options [String] :transcription_method The method used to invoke the transcription_url. Defaults to POST.
347
+ # @option options [String] :callback_url The URL invoked by the API when the recording ends. The following parameters are sent to the callback_url:
348
+ # - api_id - the same API ID returned by the conference record API.
349
+ # - record_url - the URL to access the recorded file.
350
+ # - recording_id - recording ID of the recorded file.
351
+ # - conference_name - the conference name recorded.
352
+ # - recording_duration - duration in seconds of the recording.
353
+ # - recording_duration_ms - duration in milliseconds of the recording.
354
+ # - recording_start_ms - when the recording started (epoch time UTC) in milliseconds.
355
+ # - recording_end_ms - when the recording ended (epoch time UTC) in milliseconds.
356
+ # @option options [String] :callback_method The method which is used to invoke the callback_url URL. Defaults to POST.
357
+ def record(conference_name, options = nil)
358
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
359
+ Conference.new(@_client, resource_id: conference_name)
360
+ .record(options)
361
+ end
362
+
363
+ # @param [String] conference_name
364
+ def stop_record(conference_name)
365
+ valid_param?(:conference_name, conference_name, [String, Symbol], true)
366
+ Conference.new(@_client, resource_id: conference_name)
367
+ .stop_record
368
+ end
369
+ end
370
+ end
371
+ end
@@ -0,0 +1,130 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class Endpoint < Base::Resource
5
+ def initialize(client, options = nil)
6
+ @_name = 'Endpoint'
7
+ @_identifier_string = 'endpoint_id'
8
+ super
9
+ end
10
+
11
+ # @param [Hash] options
12
+ # @option options [String] :password The password for your endpoint username.
13
+ # @option options [String] :alias Alias for this endpoint
14
+ # @option options [String] :app_id The app_id of the application that is to be attached to this endpoint. If app_id is not specified, then the endpoint does not point to any application.
15
+ def update(options = nil)
16
+ return if options.nil?
17
+ valid_param?(:options, options, Hash, true)
18
+
19
+ params = {}
20
+ params_expected = %i[password alias app_id]
21
+ params_expected.each do |param|
22
+ if options.key?(param) &&
23
+ valid_param?(param, options[param], [String, Symbol], true)
24
+ params[param] = options[param]
25
+ end
26
+ end
27
+
28
+ perform_update(params)
29
+ end
30
+
31
+ def delete
32
+ perform_delete
33
+ end
34
+
35
+ attr_reader :password
36
+
37
+ attr_reader :sip_expires
38
+
39
+ def sip_contact
40
+ @sip_expires
41
+ end
42
+
43
+ def sip_user_agent
44
+ @sip_expires
45
+ end
46
+
47
+ def to_s
48
+ {
49
+ alias: @alias,
50
+ application: @application,
51
+ endpoint_id: @endpoint_id,
52
+ resource_uri: @resource_uri,
53
+ sip_contact: @sip_contact,
54
+ sip_expires: @sip_expires,
55
+ sip_registered: @sip_registered,
56
+ sip_uri: @sip_uri,
57
+ sip_user_agent: @sip_user_agent,
58
+ sub_account: @sub_account,
59
+ username: @username,
60
+ password: @password
61
+ }.to_s
62
+ end
63
+ end
64
+
65
+ # @!method get
66
+ # @!method create
67
+ # @!method list
68
+ class EndpointInterface < Base::ResourceInterface
69
+ def initialize(client, resource_list_json = nil)
70
+ @_name = 'Endpoint'
71
+ @_resource_type = Endpoint
72
+ @_identifier_string = 'endpoint_id'
73
+ super
74
+ end
75
+
76
+ # @param [String] endpoint_id
77
+ def get(endpoint_id)
78
+ valid_param?(:endpoint_id, endpoint_id, [String, Symbol], true)
79
+ perform_get(endpoint_id)
80
+ end
81
+
82
+ # @param [String] username
83
+ # @param [String] password
84
+ # @param [String] alias_
85
+ # @param [String] app_id
86
+ def create(username, password, alias_, app_id = nil)
87
+ valid_param?(:username, username, [String, Symbol], true)
88
+ valid_param?(:password, password, [String, Symbol], true)
89
+ valid_param?(:alias, alias_, [String, Symbol], true)
90
+
91
+ params = {
92
+ username: username,
93
+ password: password,
94
+ alias: alias_
95
+ }
96
+
97
+ params[:app_id] = app_id unless app_id.nil?
98
+
99
+ perform_create(params)
100
+ end
101
+
102
+ def list
103
+ perform_list
104
+ end
105
+
106
+ def each
107
+ endpoint_list = list
108
+ endpoint_list[:objects].each { |endpoint| yield endpoint }
109
+ end
110
+
111
+ # @param [String] endpoint_id
112
+ # @param [Hash] options
113
+ # @option options [String] :password The password for your endpoint username.
114
+ # @option options [String] :alias Alias for this endpoint
115
+ # @option options [String] :app_id The app_id of the application that is to be attached to this endpoint. If app_id is not specified, then the endpoint does not point to any application.
116
+ def update(endpoint_id, options = nil)
117
+ valid_param?(:endpoint_id, endpoint_id, [String, Symbol], true)
118
+ Endpoint.new(@_client,
119
+ resource_id: endpoint_id).update(options)
120
+ end
121
+
122
+ # @param [String] endpoint_id
123
+ def delete(endpoint_id)
124
+ valid_param?(:endpoint_id, endpoint_id, [String, Symbol], true)
125
+ Endpoint.new(@_client,
126
+ resource_id: endpoint_id).delete
127
+ end
128
+ end
129
+ end
130
+ end