plivo 0.3.19 → 4.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/AUTHORS.md +4 -0
- data/CHANGELOG.md +158 -0
- data/Gemfile +10 -0
- data/Jenkinsfile +7 -0
- data/LICENSE.txt +19 -0
- data/README.md +155 -24
- data/Rakefile +9 -0
- data/ci/config.yml +7 -0
- data/examples/conference_bridge.rb +108 -0
- data/examples/jwt.rb +32 -0
- data/examples/lookup.rb +24 -0
- data/examples/multi_party_call.rb +295 -0
- data/examples/phlos.rb +55 -0
- data/examples/regulatory_compliance.rb +167 -0
- data/lib/plivo/base/resource.rb +148 -0
- data/lib/plivo/base/resource_interface.rb +108 -0
- data/lib/plivo/base/response.rb +38 -0
- data/lib/plivo/base.rb +17 -0
- data/lib/plivo/base_client.rb +393 -0
- data/lib/plivo/exceptions.rb +50 -0
- data/lib/plivo/jwt.rb +120 -0
- data/lib/plivo/phlo_client.rb +29 -0
- data/lib/plivo/resources/accounts.rb +181 -0
- data/lib/plivo/resources/addresses.rb +302 -0
- data/lib/plivo/resources/applications.rb +258 -0
- data/lib/plivo/resources/call_feedback.rb +55 -0
- data/lib/plivo/resources/calls.rb +559 -0
- data/lib/plivo/resources/conferences.rb +367 -0
- data/lib/plivo/resources/endpoints.rb +132 -0
- data/lib/plivo/resources/identities.rb +319 -0
- data/lib/plivo/resources/lookup.rb +88 -0
- data/lib/plivo/resources/media.rb +97 -0
- data/lib/plivo/resources/messages.rb +215 -0
- data/lib/plivo/resources/multipartycalls.rb +554 -0
- data/lib/plivo/resources/nodes.rb +83 -0
- data/lib/plivo/resources/numbers.rb +319 -0
- data/lib/plivo/resources/phlo_member.rb +64 -0
- data/lib/plivo/resources/phlos.rb +55 -0
- data/lib/plivo/resources/powerpacks.rb +717 -0
- data/lib/plivo/resources/pricings.rb +43 -0
- data/lib/plivo/resources/recordings.rb +116 -0
- data/lib/plivo/resources/regulatory_compliance.rb +610 -0
- data/lib/plivo/resources.rb +25 -0
- data/lib/plivo/rest_client.rb +63 -0
- data/lib/plivo/utils.rb +294 -0
- data/lib/plivo/version.rb +3 -0
- data/lib/plivo/xml/break.rb +31 -0
- data/lib/plivo/xml/conference.rb +20 -0
- data/lib/plivo/xml/cont.rb +13 -0
- data/lib/plivo/xml/dial.rb +16 -0
- data/lib/plivo/xml/dtmf.rb +13 -0
- data/lib/plivo/xml/element.rb +106 -0
- data/lib/plivo/xml/emphasis.rb +17 -0
- data/lib/plivo/xml/get_digits.rb +15 -0
- data/lib/plivo/xml/get_input.rb +16 -0
- data/lib/plivo/xml/hangup.rb +12 -0
- data/lib/plivo/xml/lang.rb +29 -0
- data/lib/plivo/xml/message.rb +13 -0
- data/lib/plivo/xml/multipartycall.rb +188 -0
- data/lib/plivo/xml/number.rb +13 -0
- data/lib/plivo/xml/p.rb +12 -0
- data/lib/plivo/xml/phoneme.rb +20 -0
- data/lib/plivo/xml/play.rb +13 -0
- data/lib/plivo/xml/plivo_xml.rb +19 -0
- data/lib/plivo/xml/pre_answer.rb +12 -0
- data/lib/plivo/xml/prosody.rb +28 -0
- data/lib/plivo/xml/record.rb +17 -0
- data/lib/plivo/xml/redirect.rb +13 -0
- data/lib/plivo/xml/response.rb +21 -0
- data/lib/plivo/xml/s.rb +12 -0
- data/lib/plivo/xml/say_as.rb +24 -0
- data/lib/plivo/xml/speak.rb +28 -0
- data/lib/plivo/xml/sub.rb +16 -0
- data/lib/plivo/xml/user.rb +13 -0
- data/lib/plivo/xml/w.rb +17 -0
- data/lib/plivo/xml/wait.rb +12 -0
- data/lib/plivo/xml.rb +39 -0
- data/lib/plivo.rb +12 -815
- data/plivo.gemspec +44 -0
- metadata +181 -41
- data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,559 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
class Call < Base::Resource
|
5
|
+
def initialize(client, options = nil)
|
6
|
+
@_name = 'Call'
|
7
|
+
@_identifier_string = 'call_uuid'
|
8
|
+
super
|
9
|
+
@_is_voice_request = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(options)
|
13
|
+
valid_param?(:options, options, Hash, true)
|
14
|
+
|
15
|
+
params = {}
|
16
|
+
|
17
|
+
if options.key?(:legs) &&
|
18
|
+
valid_param?(:legs, options[:legs],
|
19
|
+
[String, Symbol], true, %w[aleg bleg both])
|
20
|
+
params[:legs] = options[:legs]
|
21
|
+
end
|
22
|
+
|
23
|
+
unless options.key?(:legs)
|
24
|
+
unless options.key?(:aleg_url)
|
25
|
+
raise_invalid_request('default leg is aleg, aleg_url has to be specified')
|
26
|
+
end
|
27
|
+
params[:aleg_url] = options[:aleg_url]
|
28
|
+
end
|
29
|
+
|
30
|
+
if options[:legs] == 'aleg'
|
31
|
+
unless options.key?(:aleg_url)
|
32
|
+
raise_invalid_request('leg is aleg, aleg_url has to be specified')
|
33
|
+
end
|
34
|
+
params[:aleg_url] = options[:aleg_url]
|
35
|
+
end
|
36
|
+
|
37
|
+
if options[:legs] == 'bleg'
|
38
|
+
unless options.key?(:bleg_url)
|
39
|
+
raise_invalid_request('leg is bleg, bleg_url has to be specified')
|
40
|
+
end
|
41
|
+
params[:bleg_url] = options[:bleg_url]
|
42
|
+
end
|
43
|
+
|
44
|
+
if options[:legs] == 'both'
|
45
|
+
unless options.key?(:aleg_url) && options.key?(:bleg_url)
|
46
|
+
raise_invalid_request('leg is both, aleg_url & bleg_url have to be specified')
|
47
|
+
end
|
48
|
+
params[:aleg_url] = options[:aleg_url]
|
49
|
+
params[:bleg_url] = options[:bleg_url]
|
50
|
+
end
|
51
|
+
|
52
|
+
%i[aleg_method bleg_method].each do |param|
|
53
|
+
if options.key?(param) &&
|
54
|
+
valid_param?(param, options[param], [String, Symbol], true, %w[GET POST])
|
55
|
+
params[param] = options[param]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
perform_update(params)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete
|
63
|
+
perform_delete
|
64
|
+
end
|
65
|
+
|
66
|
+
def record(options = nil)
|
67
|
+
return perform_action('Record', 'POST', nil, true) if options.nil?
|
68
|
+
valid_param?(:options, options, Hash, true)
|
69
|
+
|
70
|
+
params = {}
|
71
|
+
%i[transcription_url callback_url].each do |param|
|
72
|
+
if options.key?(param) &&
|
73
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
74
|
+
params[param] = options[param]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
%i[transcription_method callback_method].each do |param|
|
79
|
+
if options.key?(param) &&
|
80
|
+
valid_param?(param, options[param], [String, Symbol], true, %w[GET POST])
|
81
|
+
params[param] = options[param]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if options.key?(:time_limit) &&
|
86
|
+
valid_param?(:time_limit, options[:time_limit], Integer, true)
|
87
|
+
params[:time_limit] = options[:time_limit]
|
88
|
+
end
|
89
|
+
|
90
|
+
if options.key?(:file_format) &&
|
91
|
+
valid_param?(:file_format, options[:file_format],
|
92
|
+
[String, Symbol], true, %w[wav mp3])
|
93
|
+
params[:file_format] = options[:file_format]
|
94
|
+
end
|
95
|
+
|
96
|
+
if options.key?(:transcription_type) &&
|
97
|
+
valid_param?(:transcription_type, options[:transcription_type],
|
98
|
+
[String, Symbol], true, %w[auto hybrid])
|
99
|
+
params[:transcription_type] = options[:transcription_type]
|
100
|
+
end
|
101
|
+
|
102
|
+
perform_action('Record', 'POST', params, true)
|
103
|
+
end
|
104
|
+
|
105
|
+
def stop_record(url = nil)
|
106
|
+
if !url.nil? &&
|
107
|
+
valid_param?(:URL, url, [String, Symbol], true)
|
108
|
+
return perform_action('Record', 'DELETE', { URL: url }, false)
|
109
|
+
end
|
110
|
+
perform_action('Record', 'DELETE')
|
111
|
+
end
|
112
|
+
|
113
|
+
def play(urls, options = nil)
|
114
|
+
valid_param?(:urls, urls, Array, true)
|
115
|
+
if options.nil?
|
116
|
+
return perform_action('Play', 'POST', { urls: urls.join(',') }, true)
|
117
|
+
end
|
118
|
+
valid_param?(:options, options, Hash, true)
|
119
|
+
|
120
|
+
params = { urls: urls.join(',') }
|
121
|
+
|
122
|
+
if options.key?(:length) &&
|
123
|
+
valid_param?(:length, options[:length], Integer, true)
|
124
|
+
params[:length] = options[:length]
|
125
|
+
end
|
126
|
+
|
127
|
+
if options.key?(:legs) &&
|
128
|
+
valid_param?(:legs, options[:legs],
|
129
|
+
[String, Symbol], true, %w[aleg bleg both])
|
130
|
+
params[:legs] = options[:legs]
|
131
|
+
end
|
132
|
+
|
133
|
+
%i[loop mix].each do |param|
|
134
|
+
if options.key?(param) &&
|
135
|
+
valid_param?(param, options[param], [TrueClass, FalseClass], true)
|
136
|
+
params[param] = options[param]
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
perform_action('Play', 'POST', params, true)
|
141
|
+
end
|
142
|
+
|
143
|
+
def stop_play
|
144
|
+
perform_action('Play', 'DELETE', nil, false)
|
145
|
+
end
|
146
|
+
|
147
|
+
def speak(text, options = nil)
|
148
|
+
valid_param?(:text, text, String, true)
|
149
|
+
if options.nil?
|
150
|
+
return perform_action('Speak', 'POST', { text: text }, true)
|
151
|
+
end
|
152
|
+
valid_param?(:options, options, Hash, true)
|
153
|
+
|
154
|
+
params = { text: text }
|
155
|
+
|
156
|
+
if options.key?(:language) &&
|
157
|
+
valid_param?(:language, options[:language], String, true)
|
158
|
+
params[:language] = options[:language]
|
159
|
+
end
|
160
|
+
|
161
|
+
if options.key?(:voice) &&
|
162
|
+
valid_param?(:voice, options[:voice],
|
163
|
+
[String, Symbol], true, %w[MAN WOMAN])
|
164
|
+
params[:voice] = options[:voice]
|
165
|
+
end
|
166
|
+
|
167
|
+
if options.key?(:legs) &&
|
168
|
+
valid_param?(:legs, options[:legs],
|
169
|
+
[String, Symbol], true, %w[aleg bleg both])
|
170
|
+
params[:legs] = options[:legs]
|
171
|
+
end
|
172
|
+
|
173
|
+
%i[loop mix].each do |param|
|
174
|
+
if options.key?(param) &&
|
175
|
+
valid_param?(param, options[param], [TrueClass, FalseClass], true)
|
176
|
+
params[param] = options[param]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
perform_action('Speak', 'POST', params, true)
|
181
|
+
end
|
182
|
+
|
183
|
+
def stop_speak
|
184
|
+
perform_action('Speak', 'DELETE', nil, false)
|
185
|
+
end
|
186
|
+
|
187
|
+
def send_digits(digits, leg = nil)
|
188
|
+
valid_param?(:digits, digits, String, true)
|
189
|
+
|
190
|
+
params = { digits: digits }
|
191
|
+
|
192
|
+
if !leg.nil? &&
|
193
|
+
valid_param?(:leg, leg,
|
194
|
+
[String, Symbol], true, %w[aleg bleg both])
|
195
|
+
params[:leg] = leg
|
196
|
+
end
|
197
|
+
|
198
|
+
perform_action('DTMF', 'POST', params, true)
|
199
|
+
end
|
200
|
+
|
201
|
+
def cancel_request
|
202
|
+
resource_path = @_resource_uri.sub('Call', 'Request')
|
203
|
+
@_client.send_request(resource_path, 'DELETE', nil, nil, false , is_voice_request: @_is_voice_request)
|
204
|
+
end
|
205
|
+
|
206
|
+
def to_s
|
207
|
+
call_details = {
|
208
|
+
answer_time: @answer_time,
|
209
|
+
api_id: @api_id,
|
210
|
+
bill_duration: @bill_duration,
|
211
|
+
billed_duration: @billed_duration,
|
212
|
+
call_direction: @call_direction,
|
213
|
+
call_duration: @call_duration,
|
214
|
+
call_status: @call_status,
|
215
|
+
call_state: @call_state,
|
216
|
+
call_uuid: @call_uuid,
|
217
|
+
conference_uuid: @conference_uuid,
|
218
|
+
end_time: @end_time,
|
219
|
+
from_number: @from_number,
|
220
|
+
initiation_time: @initiation_time,
|
221
|
+
parent_call_uuid: @parent_call_uuid,
|
222
|
+
hangup_cause_code: @hangup_cause_code,
|
223
|
+
hangup_cause_name: @hangup_cause_name,
|
224
|
+
hangup_source: @hangup_source,
|
225
|
+
resource_uri: @resource_uri,
|
226
|
+
to_number: @to_number,
|
227
|
+
total_amount: @total_amount,
|
228
|
+
total_rate: @total_rate,
|
229
|
+
to: @to,
|
230
|
+
from: @from,
|
231
|
+
request_uuid: @request_uuid,
|
232
|
+
direction: @direction,
|
233
|
+
caller_name: @caller_name,
|
234
|
+
stir_verification: @stir_verification
|
235
|
+
}
|
236
|
+
call_details = call_details.select {|k, v| !v.nil? }
|
237
|
+
call_details.to_s
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
class CallInterface < Base::ResourceInterface
|
242
|
+
def initialize(client, resource_list_json = nil)
|
243
|
+
@_name = 'Call'
|
244
|
+
@_resource_type = Call
|
245
|
+
@_identifier_string = 'call_uuid'
|
246
|
+
super
|
247
|
+
@_is_voice_request = true
|
248
|
+
end
|
249
|
+
|
250
|
+
##
|
251
|
+
# Makes an outbound call
|
252
|
+
#
|
253
|
+
# @param [String] from
|
254
|
+
# @param [Array] to
|
255
|
+
# @param [String] answer_url
|
256
|
+
# @param [Hash] options
|
257
|
+
# @option options [String] :answer_method - The method used to call the answer_url. Defaults to POST.
|
258
|
+
# @option options [String] :ring_url - The URL that is notified by Plivo when the call is ringing. Defaults not set.
|
259
|
+
# @option options [String] :ring_method - The method used to call the ring_url. Defaults to POST.
|
260
|
+
# @option options [String] :hangup_url - The URL that will be notified by Plivo when the call hangs up. Defaults to answer_url.
|
261
|
+
# @option options [String] :hangup_method - The method used to call the hangup_url. Defaults to POST.
|
262
|
+
# @option options [String] :fallback_url - Invoked by Plivo only if answer_url is unavailable or the XML response is invalid. Should contain a XML response.
|
263
|
+
# @option options [String] :fallback_method - The method used to call the fallback_answer_url. Defaults to POST.
|
264
|
+
# @option options [String] :caller_name - Caller name to use with the call.
|
265
|
+
# @option options [String] :send_digits - Plivo plays DTMF tones when the call is answered. This is useful when dialing a phone number and an extension. Plivo will dial the number, and when the automated system picks up, sends the DTMF tones to connect to the extension. E.g. If you want to dial the 2410 extension after the call is connected, and you want to wait for a few seconds before sending the extension, add a few leading 'w' characters. Each 'w' character waits 0.5 second before sending a digit. Each 'W' character waits 1 second before sending a digit. You can also add the tone duration in ms by appending @duration after the string (default duration is 2000 ms). For example, 1w2w3@1000 See the DTMF API for additional information.
|
266
|
+
# @option options [Boolean] :send_on_preanswer - If set to true and send_digits is also set, digits are sent when the call is in preanswer state. Defaults to false.
|
267
|
+
# @option options [Int] :time_limit - Schedules the call for hangup at a specified time after the call is answered. Value should be an integer > 0(in seconds).
|
268
|
+
# @option options [Int] :hangup_on_ring - Schedules the call for hangup at a specified time after the call starts ringing. Value should be an integer >= 0 (in seconds).
|
269
|
+
# @option options [String] :machine_detection - Used to detect if the call has been answered by a machine. The valid values are true and hangup. Default time to analyze is 5000 milliseconds (or 5 seconds). You can change it with the machine_detection_time parameter. Note that no XML is processed during the analysis phase. If a machine is detected during the call and machine_detection is set to true, the Machine parameter will be set to true and will be sent to the answer_url, hangup_url, or any other URL that is invoked by the call. If a machine is detected during the call and machine_detection is set to hangup, the call hangs up immediately and a request is made to the hangup_url with the Machine parameter set to true
|
270
|
+
# @option options [Int] :machine_detection_time - Time allotted to analyze if the call has been answered by a machine. It should be an integer >= 2000 and <= 10000 and the unit is ms. The default value is 5000 ms.
|
271
|
+
# @option options [String] :machine_detection_url - A URL where machine detection parameters will be sent by Plivo. This parameter should be used to make machine detection asynchronous
|
272
|
+
# @option options [String] :machine_detection_method - The HTTP method which will be used by Plivo to request the machine_detection_url. Defaults to POST.
|
273
|
+
# @option options [String] :sip_headers- List of SIP headers in the form of 'key=value' pairs, separated by commas. E.g. head1=val1,head2=val2,head3=val3,...,headN=valN. The SIP headers are always prefixed with X-PH-. The SIP headers are present for every HTTP request made by the outbound call. Only [A-Z], [a-z] and [0-9] characters are allowed for the SIP headers key and value. Additionally, the '%' character is also allowed for the SIP headers value so that you can encode this value in the URL.
|
274
|
+
# @option options [Int] :ring_timeout - Determines the time in seconds the call should ring. If the call is not answered within the ring_timeout value or the default value of 120s, it is canceled.
|
275
|
+
# @option options [String] :parent_call_uuid - The call_uuid of the first leg in an ongoing conference call. It is recommended to use this parameter in scenarios where a member who is already present in the conference intends to add new members by initiating outbound API calls. This minimizes the delay in adding a new memeber to the conference.
|
276
|
+
# @option options [Boolean] :error_parent_not_found - if set to true and the parent_call_uuid cannot be found, the API request would return an error. If set to false, the outbound call API request will be executed even if the parent_call_uuid is not found. Defaults to false.
|
277
|
+
# @return [Call] Call
|
278
|
+
def create(from, to, answer_url, options = nil)
|
279
|
+
valid_param?(:from, from, [String, Symbol, Integer], true)
|
280
|
+
valid_param?(:to, to, Array, true)
|
281
|
+
to.each do |to_num|
|
282
|
+
valid_param?(:to_num, to_num, [Integer, String, Symbol], true)
|
283
|
+
end
|
284
|
+
valid_param?(:answer_url, answer_url, [String, Symbol], true)
|
285
|
+
|
286
|
+
|
287
|
+
params = {
|
288
|
+
from: from,
|
289
|
+
to: to.join('<'),
|
290
|
+
answer_url: answer_url,
|
291
|
+
}
|
292
|
+
|
293
|
+
return perform_create(params, false) if options.nil?
|
294
|
+
|
295
|
+
perform_create(params.merge(options), false)
|
296
|
+
end
|
297
|
+
|
298
|
+
##
|
299
|
+
# Get details of a call
|
300
|
+
# @param [String] call_uuid
|
301
|
+
def get(call_uuid)
|
302
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
303
|
+
perform_get(call_uuid)
|
304
|
+
end
|
305
|
+
|
306
|
+
# @param [String] call_uuid
|
307
|
+
def get_live(call_uuid)
|
308
|
+
perform_get(call_uuid, status: 'live')
|
309
|
+
end
|
310
|
+
|
311
|
+
# @param [String] call_uuid
|
312
|
+
def get_queued(call_uuid)
|
313
|
+
perform_get(call_uuid, status: 'queued')
|
314
|
+
end
|
315
|
+
|
316
|
+
# @param [Hash] options
|
317
|
+
# @option options [String] :subaccount - The id of the subaccount, if call details of the subaccount are needed.
|
318
|
+
# @option options [String] :call_direction - Filter the results by call direction. The valid inputs are inbound and outbound.
|
319
|
+
# @option options [String] :from_number - Filter the results by the number from where the call originated. For example:
|
320
|
+
# - To filter out those numbers that contain a particular number sequence, use from_number={ sequence}
|
321
|
+
# - To filter out a number that matches an exact number, use from_number={ exact_number}
|
322
|
+
# @option options [String] :to_number - Filter the results by the number to which the call was made. Tips to use this filter are:
|
323
|
+
# - To filter out those numbers that contain a particular number sequence, use to_number={ sequence}
|
324
|
+
# - To filter out a number that matches an exact number, use to_number={ exact_number}
|
325
|
+
# @option options [String] :bill_duration - Filter the results according to billed duration. The value of billed duration is in seconds. The filter can be used in one of the following five forms:
|
326
|
+
# - bill_duration: Input the exact value. E.g., to filter out calls that were exactly three minutes long, use bill_duration=180
|
327
|
+
# - bill_duration\__gt: gt stands for greater than. E.g., to filter out calls that were more than two hours in duration bill_duration\__gt=7200
|
328
|
+
# - bill_duration\__gte: gte stands for greater than or equal to. E.g., to filter out calls that were two hours or more in duration bill_duration\__gte=7200
|
329
|
+
# - bill_duration\__lt: lt stands for lesser than. E.g., to filter out calls that were less than seven minutes in duration bill_duration\__lt=420
|
330
|
+
# - bill_duration\__lte: lte stands for lesser than or equal to. E.g., to filter out calls that were two hours or less in duration bill_duration\__lte=7200
|
331
|
+
# @option options [String] :end_time - Filter out calls according to the time of completion. The filter can be used in the following five forms:
|
332
|
+
# - end_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. E.g., To get all calls that ended at 2012-03-21 11:47[:30], use end_time=2012-03-21 11:47[:30]
|
333
|
+
# - end_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. E.g., To get all calls that ended after 2012-03-21 11:47, use end_time\__gt=2012-03-21 11:47
|
334
|
+
# - end_time\__gte: gte stands for greater than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. E.g., To get all calls that ended after or exactly at 2012-03-21 11:47[:30], use end_time\__gte=2012-03-21 11:47[:30]
|
335
|
+
# - end_time\__lt: lt stands for lesser than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. E.g., To get all calls that ended before 2012-03-21 11:47, use end_time\__lt=2012-03-21 11:47
|
336
|
+
# - end_time\__lte: lte stands for lesser than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. E.g., To get all calls that ended before or exactly at 2012-03-21 11:47[:30], use end_time\__lte=2012-03-21 11:47[:30]
|
337
|
+
# - Note: The above filters can be combined to get calls that ended in a particular time range. The timestamps need to be UTC timestamps.
|
338
|
+
# @option options [String] :parent_call_uuid - Filter the results by parent call uuid.
|
339
|
+
# @option options [String] :hangup_source - Filter the results by hangup source
|
340
|
+
# @option options [String] :hangup_cause_code - Filter the results by hangup cause code
|
341
|
+
# @option options [Int] :limit - Used to display the number of results per page. The maximum number of results that can be fetched is 20.
|
342
|
+
# @option options [Int] :offset - Denotes the number of value items by which the results should be offset. E.g., 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.
|
343
|
+
|
344
|
+
def list(options = nil)
|
345
|
+
return perform_list if options.nil?
|
346
|
+
valid_param?(:options, options, Hash, true)
|
347
|
+
|
348
|
+
params = {}
|
349
|
+
params_expected = %i[
|
350
|
+
subaccount bill_duration bill_duration__gt bill_duration__gte
|
351
|
+
bill_duration__lt bill_duration__lte end_time end_time__gt
|
352
|
+
end_time__gte end_time__lt end_time__lte parent_call_uuid hangup_source
|
353
|
+
]
|
354
|
+
params_expected.each do |param|
|
355
|
+
if options.key?(param) &&
|
356
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
357
|
+
params[param] = options[param]
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
if options.key?(:call_direction) &&
|
362
|
+
valid_param?(:call_direction, options[:call_direction],
|
363
|
+
[String, Symbol], true, %w[inbound outbound])
|
364
|
+
params[:call_direction] = options[:call_direction]
|
365
|
+
end
|
366
|
+
|
367
|
+
%i[offset limit hangup_cause_code].each do |param|
|
368
|
+
if options.key?(param) && valid_param?(param, options[param], [Integer, Integer], true)
|
369
|
+
params[param] = options[param]
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0
|
374
|
+
|
375
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
376
|
+
raise_invalid_request('The maximum number of results that can be '\
|
377
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
378
|
+
end
|
379
|
+
|
380
|
+
perform_list(params)
|
381
|
+
end
|
382
|
+
|
383
|
+
def each
|
384
|
+
offset = 0
|
385
|
+
loop do
|
386
|
+
call_list = list(offset: offset)
|
387
|
+
call_list[:objects].each { |call| yield call }
|
388
|
+
offset += 20
|
389
|
+
return unless call_list.length == 20
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
# @param [Hash] options
|
394
|
+
# @option options [String] :call_direction - Filter the results by call direction. The valid inputs are inbound and outbound.
|
395
|
+
# @option options [String] :from_number - Filter the results by the number from where the call originated. For example:
|
396
|
+
# - To filter out those numbers that contain a particular number sequence, use from_number={ sequence}
|
397
|
+
# - To filter out a number that matches an exact number, use from_number={ exact_number}
|
398
|
+
# @option options [String] :to_number - Filter the results by the number to which the call was made. Tips to use this filter are:
|
399
|
+
# - To filter out those numbers that contain a particular number sequence, use to_number={ sequence}
|
400
|
+
# - To filter out a number that matches an exact number, use to_number={ exact_number}
|
401
|
+
def list_live(options = nil)
|
402
|
+
|
403
|
+
if options.nil?
|
404
|
+
options = {}
|
405
|
+
else
|
406
|
+
valid_param?(:options, options, Hash, true)
|
407
|
+
end
|
408
|
+
|
409
|
+
params = {}
|
410
|
+
params[:status] = 'live'
|
411
|
+
params_expected = %i[
|
412
|
+
from_number to_number
|
413
|
+
]
|
414
|
+
params_expected.each do |param|
|
415
|
+
if options.key?(param) &&
|
416
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
417
|
+
params[param] = options[param]
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
if options.key?(:call_direction) &&
|
422
|
+
valid_param?(:call_direction, options[:call_direction],
|
423
|
+
[String, Symbol], true, %w[inbound outbound])
|
424
|
+
params[:call_direction] = options[:call_direction]
|
425
|
+
end
|
426
|
+
|
427
|
+
perform_list_without_object(params)
|
428
|
+
{
|
429
|
+
api_id: @api_id,
|
430
|
+
calls: @calls
|
431
|
+
}
|
432
|
+
end
|
433
|
+
|
434
|
+
def list_queued
|
435
|
+
perform_list_without_object(status: 'queued')
|
436
|
+
{
|
437
|
+
api_id: @api_id,
|
438
|
+
calls: @calls
|
439
|
+
}
|
440
|
+
end
|
441
|
+
|
442
|
+
def each_live
|
443
|
+
call_list = list_live
|
444
|
+
call_list[:calls].each { |call| yield call }
|
445
|
+
end
|
446
|
+
|
447
|
+
def each_queued
|
448
|
+
call_queued = list_queued
|
449
|
+
call_queued[:calls].each { |call| yield call}
|
450
|
+
end
|
451
|
+
|
452
|
+
##
|
453
|
+
# Transfer a call
|
454
|
+
# @param [String] call_uuid
|
455
|
+
# @param [Hash] details
|
456
|
+
# @option details [String] :legs - aleg, bleg or both Defaults to aleg. aleg will transfer call_uuid ; bleg will transfer the bridged leg (if found) of call_uuid ; both will transfer call_uuid and bridged leg of call_uuid
|
457
|
+
# @option details [String] :aleg_url - URL to transfer for aleg, if legs is aleg or both, then aleg_url has to be specified.
|
458
|
+
# @option details [String] :aleg_method - HTTP method to invoke aleg_url. Defaults to POST.
|
459
|
+
# @option details [String] :bleg_url - URL to transfer for bridged leg, if legs is bleg or both, then bleg_url has to be specified.
|
460
|
+
# @option details [String] :bleg_method - HTTP method to invoke bleg_url. Defaults to POST.
|
461
|
+
# @return [Call] Call
|
462
|
+
def update(call_uuid, details)
|
463
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
464
|
+
Call.new(@_client, resource_id: call_uuid).update(details)
|
465
|
+
end
|
466
|
+
|
467
|
+
# @param [String] call_uuid
|
468
|
+
def delete(call_uuid)
|
469
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
470
|
+
Call.new(@_client, resource_id: call_uuid).delete
|
471
|
+
end
|
472
|
+
|
473
|
+
# @param [String] call_uuid
|
474
|
+
# @param [Hash] options
|
475
|
+
# @option options [Int] :time_limit - Max recording duration in seconds. Defaults to 60.
|
476
|
+
# @option options [String] :file_format - The format of the recording. The valid formats are mp3 and wav formats. Defaults to mp3.
|
477
|
+
# @option options [String] :transcription_type - The type of transcription required. The following values are allowed:
|
478
|
+
# - auto - This is the default value. Transcription is completely automated; turnaround time is about 5 minutes.
|
479
|
+
# - hybrid - Transcription is a combination of automated and human verification processes; turnaround time is about 10-15 minutes.
|
480
|
+
# - *Our transcription service is primarily for the voicemail use case (limited to recorded files lasting for up to 2 minutes). Currently the service is available only in English and you will be charged for the usage. Please check out the price details.
|
481
|
+
# @option options [String] :transcription_url - The URL where the transcription is available.
|
482
|
+
# @option options [String] :transcription_method - The method used to invoke the transcription_url. Defaults to POST.
|
483
|
+
# @option options [String] :callback_url - The URL invoked by the API when the recording ends. The following parameters are sent to the callback_url:
|
484
|
+
# - api_id - the same API ID returned by the call record API.
|
485
|
+
# - record_url - the URL to access the recorded file.
|
486
|
+
# - call_uuid - the call uuid of the recorded call.
|
487
|
+
# - recording_id - the recording ID of the recorded call.
|
488
|
+
# - recording_duration - duration in seconds of the recording.
|
489
|
+
# - recording_duration_ms - duration in milliseconds of the recording.
|
490
|
+
# - recording_start_ms - when the recording started (epoch time UTC) in milliseconds.
|
491
|
+
# - recording_end_ms - when the recording ended (epoch time UTC) in milliseconds.
|
492
|
+
# @option options [String] :callback_method - The method which is used to invoke the callback_url URL. Defaults to POST.
|
493
|
+
def record(call_uuid, options = nil)
|
494
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
495
|
+
Call.new(@_client, resource_id: call_uuid).record(options)
|
496
|
+
end
|
497
|
+
|
498
|
+
# @param [String] call_uuid
|
499
|
+
# @param [String] url - You can specify a record URL to stop only one record. By default all recordings are stopped.
|
500
|
+
def stop_record(call_uuid, url = nil)
|
501
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
502
|
+
Call.new(@_client, resource_id: call_uuid).stop_record(url)
|
503
|
+
end
|
504
|
+
|
505
|
+
# @param [String] call_uuid
|
506
|
+
# @param [Array] urls
|
507
|
+
# @param [Hash] options
|
508
|
+
# @option options [Array of strings] :urls - A single URL or a list of comma separated URLs linking to an mp3 or wav file.
|
509
|
+
# @option options [Int] :length - Maximum length in seconds that the audio should be played.
|
510
|
+
# @option options [String] :legs - The leg on which the music will be played, can be aleg (i.e., A-leg is the first leg of the call or current call), bleg (i.e., B-leg is the second leg of the call),or both (i.e., both legs of the call).
|
511
|
+
# @option options [Boolean] :loop - If set to true, the audio file will play indefinitely.
|
512
|
+
# @option options [Boolean] :mix - If set to true, sounds are mixed with current audio flow.
|
513
|
+
def play(call_uuid, urls, options = nil)
|
514
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
515
|
+
valid_param?(:urls, urls, Array, true)
|
516
|
+
Call.new(@_client, resource_id: call_uuid).play(urls, options)
|
517
|
+
end
|
518
|
+
|
519
|
+
# @param [String] call_uuid
|
520
|
+
def stop_play(call_uuid)
|
521
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
522
|
+
Call.new(@_client, resource_id: call_uuid).stop_play
|
523
|
+
end
|
524
|
+
|
525
|
+
# @param [String] call_uuid
|
526
|
+
# @param [String] text
|
527
|
+
# @param [Hash] options
|
528
|
+
# @option options [String] :voice - The voice to be used, can be MAN, WOMAN.
|
529
|
+
# @option options [Int] :language - The language to be used, see Supported voices and languages {https://www.plivo.com/docs/api/call/speak/#supported-voices-and-languages}
|
530
|
+
# @option options [String] :legs - The leg on which the music will be played, can be aleg (i.e., A-leg is the first leg of the call or current call), bleg (i.e., B-leg is the second leg of the call),or both (i.e., both legs of the call).
|
531
|
+
# @option options [Boolean] :loop - If set to true, the audio file will play indefinitely.
|
532
|
+
# @option options [Boolean] :mix - If set to true, sounds are mixed with current audio flow.
|
533
|
+
def speak(call_uuid, text, options = nil)
|
534
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
535
|
+
Call.new(@_client, resource_id: call_uuid).speak(text, options)
|
536
|
+
end
|
537
|
+
|
538
|
+
# @param [String] call_uuid
|
539
|
+
def stop_speak(call_uuid)
|
540
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
541
|
+
Call.new(@_client, resource_id: call_uuid).stop_speak
|
542
|
+
end
|
543
|
+
|
544
|
+
# @param [String] call_uuid
|
545
|
+
# @param [String] digits - Digits to be sent.
|
546
|
+
# @param [String] leg - The leg to be used, can be aleg (the current call) or bleg (the other party in a Dial). Defaults to aleg.
|
547
|
+
def send_digits(call_uuid, digits, leg = nil)
|
548
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
549
|
+
Call.new(@_client, resource_id: call_uuid).send_digits(digits, leg)
|
550
|
+
end
|
551
|
+
|
552
|
+
# @param [String] call_uuid
|
553
|
+
def cancel_request(call_uuid)
|
554
|
+
valid_param?(:call_uuid, call_uuid, [String, Symbol], true)
|
555
|
+
Call.new(@_client, resource_id: call_uuid).cancel_request
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|