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
data/lib/plivo.rb
CHANGED
@@ -1,815 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
class XPlivoSignature
|
14
|
-
attr_accessor :signature, :uri, :post_params, :auth_token
|
15
|
-
|
16
|
-
def initialize(signature, uri, post_params, auth_token)
|
17
|
-
@signature = signature
|
18
|
-
@uri = uri
|
19
|
-
@post_params = post_params
|
20
|
-
@auth_token = auth_token
|
21
|
-
end
|
22
|
-
|
23
|
-
def is_valid?
|
24
|
-
uri = @post_params.sort.reduce(@uri) {|_, (key, val)| _ += key + val}
|
25
|
-
return Base64.encode64(OpenSSL::HMAC.digest('sha1', @auth_token, uri)).chomp.eql? @signature
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
class RestAPI
|
31
|
-
attr_accessor :auth_id, :auth_token, :url, :version, :api, :headers, :rest
|
32
|
-
|
33
|
-
def initialize(auth_id, auth_token, url="https://api.plivo.com", version="v1")
|
34
|
-
@auth_id = auth_id
|
35
|
-
@auth_token = auth_token
|
36
|
-
@url = url.chomp('/')
|
37
|
-
@version = version
|
38
|
-
@api = @url + '/' + @version + '/Account/' + @auth_id
|
39
|
-
@headers = {"User-Agent" => "RubyPlivo"}
|
40
|
-
@rest = RestClient::Resource.new(@api, @auth_id, @auth_token)
|
41
|
-
end
|
42
|
-
|
43
|
-
def hash_to_params(myhash)
|
44
|
-
return myhash.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
|
45
|
-
end
|
46
|
-
|
47
|
-
def request(method, path, params=nil)
|
48
|
-
if method == "POST"
|
49
|
-
if not params
|
50
|
-
params = {}
|
51
|
-
end
|
52
|
-
begin
|
53
|
-
r = @rest[path].post params.to_json, :content_type => 'application/json'
|
54
|
-
rescue => e
|
55
|
-
response = e
|
56
|
-
end
|
57
|
-
if not response
|
58
|
-
code = r.code
|
59
|
-
raw = r.to_str
|
60
|
-
response = JSON.parse(raw)
|
61
|
-
else
|
62
|
-
code = response.http_code
|
63
|
-
response = JSON.parse(response.response.to_s)
|
64
|
-
end
|
65
|
-
return [code, response]
|
66
|
-
elsif method == "GET"
|
67
|
-
if params
|
68
|
-
path = path + '?' + hash_to_params(params)
|
69
|
-
end
|
70
|
-
|
71
|
-
begin
|
72
|
-
r = @rest[path].get
|
73
|
-
rescue => e
|
74
|
-
response = e
|
75
|
-
end
|
76
|
-
if not response
|
77
|
-
code = r.code
|
78
|
-
raw = r.to_str
|
79
|
-
response = JSON.parse(raw)
|
80
|
-
else
|
81
|
-
code = response.http_code
|
82
|
-
response = JSON.parse(response.response.to_s)
|
83
|
-
end
|
84
|
-
return [code, response]
|
85
|
-
elsif method == "DELETE"
|
86
|
-
if params
|
87
|
-
path = path + '?' + hash_to_params(params)
|
88
|
-
end
|
89
|
-
begin
|
90
|
-
r = @rest[path].delete
|
91
|
-
rescue => e
|
92
|
-
response = e
|
93
|
-
end
|
94
|
-
if not response
|
95
|
-
code = r.code
|
96
|
-
else
|
97
|
-
code = response.http_code
|
98
|
-
response = JSON.parse(response.response.to_s)
|
99
|
-
end
|
100
|
-
return [code, ""]
|
101
|
-
end
|
102
|
-
return [405, 'Method Not Supported']
|
103
|
-
end
|
104
|
-
|
105
|
-
## Accounts ##
|
106
|
-
def get_account(params={})
|
107
|
-
return request('GET', "/", params)
|
108
|
-
end
|
109
|
-
|
110
|
-
def modify_account(params={})
|
111
|
-
return request('POST', "/", params)
|
112
|
-
end
|
113
|
-
|
114
|
-
def get_subaccounts(params={})
|
115
|
-
return request('GET', "/Subaccount/", params)
|
116
|
-
end
|
117
|
-
|
118
|
-
def create_subaccount(params={})
|
119
|
-
return request('POST', "/Subaccount/", params)
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_subaccount(params={})
|
123
|
-
subauth_id = params.delete("subauth_id") || params.delete(:subauth_id)
|
124
|
-
return request('GET', "/Subaccount/#{subauth_id}/", params)
|
125
|
-
end
|
126
|
-
|
127
|
-
def modify_subaccount(params={})
|
128
|
-
subauth_id = params.delete("subauth_id") || params.delete(:subauth_id)
|
129
|
-
return request('POST', "/Subaccount/#{subauth_id}/", params)
|
130
|
-
end
|
131
|
-
|
132
|
-
def delete_subaccount(params={})
|
133
|
-
subauth_id = params.delete("subauth_id") || params.delete(:subauth_id)
|
134
|
-
return request('DELETE', "/Subaccount/#{subauth_id}/", params)
|
135
|
-
end
|
136
|
-
|
137
|
-
## Applications ##
|
138
|
-
def get_applications(params={})
|
139
|
-
return request('GET', "/Application/", params)
|
140
|
-
end
|
141
|
-
|
142
|
-
def create_application(params={})
|
143
|
-
return request('POST', "/Application/", params)
|
144
|
-
end
|
145
|
-
|
146
|
-
def get_application(params={})
|
147
|
-
app_id = params.delete("app_id")
|
148
|
-
return request('GET', "/Application/#{app_id}/", params)
|
149
|
-
end
|
150
|
-
|
151
|
-
def modify_application(params={})
|
152
|
-
app_id = params.delete("app_id")
|
153
|
-
return request('POST', "/Application/#{app_id}/", params)
|
154
|
-
end
|
155
|
-
|
156
|
-
def delete_application(params={})
|
157
|
-
app_id = params.delete("app_id")
|
158
|
-
return request('DELETE', "/Application/#{app_id}/", params)
|
159
|
-
end
|
160
|
-
|
161
|
-
## Numbers ##
|
162
|
-
def search_phone_number(params={})
|
163
|
-
return request('GET', "/PhoneNumber/", params)
|
164
|
-
end
|
165
|
-
|
166
|
-
def buy_phone_number(params={})
|
167
|
-
number = params.delete("number")
|
168
|
-
return request('POST', "/PhoneNumber/#{number}/", params)
|
169
|
-
end
|
170
|
-
|
171
|
-
def get_numbers(params={})
|
172
|
-
return request('GET', "/Number/", params)
|
173
|
-
end
|
174
|
-
|
175
|
-
def modify_number(params={})
|
176
|
-
number = params.delete("number")
|
177
|
-
return request('POST', "/Number/#{number}/", params)
|
178
|
-
end
|
179
|
-
|
180
|
-
def search_numbers(params={})
|
181
|
-
return request('GET', "/AvailableNumber/", params)
|
182
|
-
end
|
183
|
-
|
184
|
-
def get_number(params={})
|
185
|
-
number = params.delete("number")
|
186
|
-
return request('GET', "/Number/#{number}/", params)
|
187
|
-
end
|
188
|
-
|
189
|
-
def rent_number(params={})
|
190
|
-
number = params.delete("number")
|
191
|
-
return request('POST', "/AvailableNumber/#{number}/", params)
|
192
|
-
end
|
193
|
-
|
194
|
-
def unrent_number(params={})
|
195
|
-
number = params.delete("number")
|
196
|
-
return request('DELETE', "/Number/#{number}/", params)
|
197
|
-
end
|
198
|
-
|
199
|
-
def link_application_number(params={})
|
200
|
-
number = params.delete("number")
|
201
|
-
return request('POST', "/Number/#{number}/", params)
|
202
|
-
end
|
203
|
-
|
204
|
-
def unlink_application_number(params={})
|
205
|
-
number = params.delete("number")
|
206
|
-
params = {"app_id" => ""}
|
207
|
-
return request('POST', "/Number/#{number}/", params)
|
208
|
-
end
|
209
|
-
|
210
|
-
def get_number_group(params={})
|
211
|
-
return request('GET', "/AvailableNumberGroup/", params)
|
212
|
-
end
|
213
|
-
|
214
|
-
def get_number_group_details(params={})
|
215
|
-
group_id = params.delete('group_id')
|
216
|
-
return request('GET', "/AvailableNumberGroup/#{group_id}/", params)
|
217
|
-
end
|
218
|
-
|
219
|
-
def rent_from_number_group(params={})
|
220
|
-
group_id = params.delete('group_id')
|
221
|
-
return request('POST', "/AvailableNumberGroup/#{group_id}/", params)
|
222
|
-
end
|
223
|
-
|
224
|
-
## Calls ##
|
225
|
-
def get_cdrs(params={})
|
226
|
-
return request('GET', "/Call/", params)
|
227
|
-
end
|
228
|
-
|
229
|
-
def get_cdr(params={})
|
230
|
-
record_id = params.delete('record_id')
|
231
|
-
return request('GET', "/Call/#{record_id}/", params)
|
232
|
-
end
|
233
|
-
|
234
|
-
def get_live_calls(params={})
|
235
|
-
params["status"] = "live"
|
236
|
-
return request('GET', "/Call/", params)
|
237
|
-
end
|
238
|
-
|
239
|
-
def get_live_call(params={})
|
240
|
-
call_uuid = params.delete('call_uuid')
|
241
|
-
params["status"] = "live"
|
242
|
-
return request('GET', "/Call/#{call_uuid}/", params)
|
243
|
-
end
|
244
|
-
|
245
|
-
def make_call(params={})
|
246
|
-
return request('POST', "/Call/", params)
|
247
|
-
end
|
248
|
-
|
249
|
-
def hangup_all_calls(params={})
|
250
|
-
return request('DELETE', "/Call/", params)
|
251
|
-
end
|
252
|
-
|
253
|
-
def transfer_call(params={})
|
254
|
-
call_uuid = params.delete('call_uuid')
|
255
|
-
return request('POST', "/Call/#{call_uuid}/", params)
|
256
|
-
end
|
257
|
-
|
258
|
-
def hangup_call(params={})
|
259
|
-
call_uuid = params.delete('call_uuid')
|
260
|
-
return request('DELETE', "/Call/#{call_uuid}/", params)
|
261
|
-
end
|
262
|
-
|
263
|
-
def record(params={})
|
264
|
-
call_uuid = params.delete('call_uuid')
|
265
|
-
return request('POST', "/Call/#{call_uuid}/Record/", params)
|
266
|
-
end
|
267
|
-
|
268
|
-
def stop_record(params={})
|
269
|
-
call_uuid = params.delete('call_uuid')
|
270
|
-
return request('DELETE', "/Call/#{call_uuid}/Record/", params)
|
271
|
-
end
|
272
|
-
|
273
|
-
def play(params={})
|
274
|
-
call_uuid = params.delete('call_uuid')
|
275
|
-
return request('POST', "/Call/#{call_uuid}/Play/", params)
|
276
|
-
end
|
277
|
-
|
278
|
-
def stop_play(params={})
|
279
|
-
call_uuid = params.delete('call_uuid')
|
280
|
-
return request('DELETE', "/Call/#{call_uuid}/Play/", params)
|
281
|
-
end
|
282
|
-
|
283
|
-
def speak(params={})
|
284
|
-
call_uuid = params.delete('call_uuid')
|
285
|
-
params.update({"text" => HTMLEntities.new(:html4).encode(params['text'], :decimal)})
|
286
|
-
return request('POST', "/Call/#{call_uuid}/Speak/", params)
|
287
|
-
end
|
288
|
-
|
289
|
-
def stop_speak(params={})
|
290
|
-
call_uuid = params.delete('call_uuid')
|
291
|
-
return request('DELETE', "/Call/#{call_uuid}/Speak/", params)
|
292
|
-
end
|
293
|
-
|
294
|
-
def send_digits(params={})
|
295
|
-
call_uuid = params.delete('call_uuid')
|
296
|
-
return request('POST', "/Call/#{call_uuid}/DTMF/", params)
|
297
|
-
end
|
298
|
-
|
299
|
-
## Calls requests ##
|
300
|
-
def hangup_request(params={})
|
301
|
-
request_uuid = params.delete('request_uuid')
|
302
|
-
return request('DELETE', "/Request/#{request_uuid}/", params)
|
303
|
-
end
|
304
|
-
|
305
|
-
## Conferences ##
|
306
|
-
def get_live_conferences(params={})
|
307
|
-
return request('GET', "/Conference/", params)
|
308
|
-
end
|
309
|
-
|
310
|
-
def hangup_all_conferences(params={})
|
311
|
-
return request('DELETE', "/Conference/", params)
|
312
|
-
end
|
313
|
-
|
314
|
-
def get_live_conference(params={})
|
315
|
-
conference_name = params.delete('conference_name')
|
316
|
-
return request('GET', "/Conference/#{conference_name}/", params)
|
317
|
-
end
|
318
|
-
|
319
|
-
def hangup_conference(params={})
|
320
|
-
conference_name = params.delete('conference_name')
|
321
|
-
return request('DELETE', "/Conference/#{conference_name}/", params)
|
322
|
-
end
|
323
|
-
|
324
|
-
def hangup_member(params={})
|
325
|
-
conference_name = params.delete('conference_name')
|
326
|
-
member_id = params.delete('member_id')
|
327
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/", params)
|
328
|
-
end
|
329
|
-
|
330
|
-
def play_member(params={})
|
331
|
-
conference_name = params.delete('conference_name')
|
332
|
-
member_id = params.delete('member_id')
|
333
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Play/", params)
|
334
|
-
end
|
335
|
-
|
336
|
-
def stop_play_member(params={})
|
337
|
-
conference_name = params.delete('conference_name')
|
338
|
-
member_id = params.delete('member_id')
|
339
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Play/", params)
|
340
|
-
end
|
341
|
-
|
342
|
-
def speak_member(params={})
|
343
|
-
conference_name = params.delete('conference_name')
|
344
|
-
member_id = params.delete('member_id')
|
345
|
-
params.update({"text" => HTMLEntities.new(:html4).encode(params['text'], :decimal)})
|
346
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Speak/", params)
|
347
|
-
end
|
348
|
-
|
349
|
-
def stop_speak_member(params={})
|
350
|
-
conference_name = params.delete('conference_name')
|
351
|
-
member_id = params.delete('member_id')
|
352
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Speak/", params)
|
353
|
-
end
|
354
|
-
|
355
|
-
def deaf_member(params={})
|
356
|
-
conference_name = params.delete('conference_name')
|
357
|
-
member_id = params.delete('member_id')
|
358
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Deaf/", params)
|
359
|
-
end
|
360
|
-
|
361
|
-
def undeaf_member(params={})
|
362
|
-
conference_name = params.delete('conference_name')
|
363
|
-
member_id = params.delete('member_id')
|
364
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Deaf/", params)
|
365
|
-
end
|
366
|
-
|
367
|
-
def mute_member(params={})
|
368
|
-
conference_name = params.delete('conference_name')
|
369
|
-
member_id = params.delete('member_id')
|
370
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Mute/", params)
|
371
|
-
end
|
372
|
-
|
373
|
-
def unmute_member(params={})
|
374
|
-
conference_name = params.delete('conference_name')
|
375
|
-
member_id = params.delete('member_id')
|
376
|
-
return request('DELETE', "/Conference/#{conference_name}/Member/#{member_id}/Mute/", params)
|
377
|
-
end
|
378
|
-
|
379
|
-
def kick_member(params={})
|
380
|
-
conference_name = params.delete('conference_name')
|
381
|
-
member_id = params.delete('member_id')
|
382
|
-
return request('POST', "/Conference/#{conference_name}/Member/#{member_id}/Kick/", params)
|
383
|
-
end
|
384
|
-
|
385
|
-
def record_conference(params={})
|
386
|
-
conference_name = params.delete('conference_name')
|
387
|
-
return request('POST', "/Conference/#{conference_name}/Record/", params)
|
388
|
-
end
|
389
|
-
|
390
|
-
def stop_record_conference(params={})
|
391
|
-
conference_name = params.delete('conference_name')
|
392
|
-
return request('DELETE', "/Conference/#{conference_name}/Record/", params)
|
393
|
-
end
|
394
|
-
|
395
|
-
## Recordings ##
|
396
|
-
def get_recordings(params={})
|
397
|
-
return request('GET', "/Recording/", params)
|
398
|
-
end
|
399
|
-
|
400
|
-
def get_recording(params={})
|
401
|
-
recording_id = params.delete('recording_id')
|
402
|
-
return request('GET', "/Recording/#{recording_id}/", params)
|
403
|
-
end
|
404
|
-
|
405
|
-
def delete_recording(params={})
|
406
|
-
recording_id = params.delete('recording_id')
|
407
|
-
return request('DELETE', "/Recording/#{recording_id}/", params)
|
408
|
-
end
|
409
|
-
|
410
|
-
## Endpoints ##
|
411
|
-
def get_endpoints(params={})
|
412
|
-
return request('GET', "/Endpoint/", params)
|
413
|
-
end
|
414
|
-
|
415
|
-
def create_endpoint(params={})
|
416
|
-
return request('POST', "/Endpoint/", params)
|
417
|
-
end
|
418
|
-
|
419
|
-
def get_endpoint(params={})
|
420
|
-
endpoint_id = params.delete('endpoint_id')
|
421
|
-
return request('GET', "/Endpoint/#{endpoint_id}/", params)
|
422
|
-
end
|
423
|
-
|
424
|
-
def modify_endpoint(params={})
|
425
|
-
endpoint_id = params.delete('endpoint_id')
|
426
|
-
return request('POST', "/Endpoint/#{endpoint_id}/", params)
|
427
|
-
end
|
428
|
-
|
429
|
-
def delete_endpoint(params={})
|
430
|
-
endpoint_id = params.delete('endpoint_id')
|
431
|
-
return request('DELETE', "/Endpoint/#{endpoint_id}/", params)
|
432
|
-
end
|
433
|
-
|
434
|
-
## Incoming Carriers ##
|
435
|
-
def get_incoming_carriers(params={})
|
436
|
-
return request('GET', "/IncomingCarrier/", params)
|
437
|
-
end
|
438
|
-
|
439
|
-
def create_incoming_carrier(params={})
|
440
|
-
return request('POST', "/IncomingCarrier/", params)
|
441
|
-
end
|
442
|
-
|
443
|
-
def get_incoming_carrier(params={})
|
444
|
-
carrier_id = params.delete('carrier_id')
|
445
|
-
return request('GET', "/IncomingCarrier/#{carrier_id}/", params)
|
446
|
-
end
|
447
|
-
|
448
|
-
def modify_incoming_carrier(params={})
|
449
|
-
carrier_id = params.delete('carrier_id')
|
450
|
-
return request('POST', "/IncomingCarrier/#{carrier_id}/", params)
|
451
|
-
end
|
452
|
-
|
453
|
-
def delete_incoming_carrier(params={})
|
454
|
-
carrier_id = params.delete('carrier_id')
|
455
|
-
return request('DELETE', "/IncomingCarrier/#{carrier_id}/", params)
|
456
|
-
end
|
457
|
-
|
458
|
-
## Outgoing Carriers ##
|
459
|
-
def get_outgoing_carriers(params={})
|
460
|
-
return request('GET', "/OutgoingCarrier/", params)
|
461
|
-
end
|
462
|
-
|
463
|
-
def create_outgoing_carrier(params={})
|
464
|
-
return request('POST', "/OutgoingCarrier/", params)
|
465
|
-
end
|
466
|
-
|
467
|
-
def get_outgoing_carrier(params={})
|
468
|
-
carrier_id = params.delete('carrier_id')
|
469
|
-
return request('GET', "/OutgoingCarrier/#{carrier_id}/", params)
|
470
|
-
end
|
471
|
-
|
472
|
-
def modify_outgoing_carrier(params={})
|
473
|
-
carrier_id = params.delete('carrier_id')
|
474
|
-
return request('POST', "/OutgoingCarrier/#{carrier_id}/", params)
|
475
|
-
end
|
476
|
-
|
477
|
-
def delete_outgoing_carrier(params={})
|
478
|
-
carrier_id = params.delete('carrier_id')
|
479
|
-
return request('DELETE', "/OutgoingCarrier/#{carrier_id}/", params)
|
480
|
-
end
|
481
|
-
|
482
|
-
## Outgoing Carrier Routings ##
|
483
|
-
def get_outgoing_carrier_routings(params={})
|
484
|
-
return request('GET', "/OutgoingCarrierRouting/", params)
|
485
|
-
end
|
486
|
-
|
487
|
-
def create_outgoing_carrier_routing(params={})
|
488
|
-
return request('POST', "/OutgoingCarrierRouting/", params)
|
489
|
-
end
|
490
|
-
|
491
|
-
def get_outgoing_carrier_routing(params={})
|
492
|
-
routing_id = params.delete('routing_id')
|
493
|
-
return request('GET', "/OutgoingCarrierRouting/#{routing_id}/", params)
|
494
|
-
end
|
495
|
-
|
496
|
-
def modify_outgoing_carrier_routing(params={})
|
497
|
-
routing_id = params.delete('routing_id')
|
498
|
-
return request('POST', "/OutgoingCarrierRouting/#{routing_id}/", params)
|
499
|
-
end
|
500
|
-
|
501
|
-
def delete_outgoing_carrier_routing(params={})
|
502
|
-
routing_id = params.delete('routing_id')
|
503
|
-
return request('DELETE', "/OutgoingCarrierRouting/#{routing_id}/", params)
|
504
|
-
end
|
505
|
-
|
506
|
-
## Pricing ##
|
507
|
-
def pricing(params={})
|
508
|
-
return request('GET', "/Pricing/", params)
|
509
|
-
end
|
510
|
-
|
511
|
-
## Outgoing Carrier ##
|
512
|
-
|
513
|
-
## To be added here ##
|
514
|
-
|
515
|
-
## Message ##
|
516
|
-
def send_message(params={})
|
517
|
-
return request('POST', "/Message/", params)
|
518
|
-
end
|
519
|
-
|
520
|
-
def get_messages(params={})
|
521
|
-
return request('GET', "/Message/", params)
|
522
|
-
end
|
523
|
-
|
524
|
-
def get_message(params={})
|
525
|
-
record_id = params.delete('record_id')
|
526
|
-
return request('GET', "/Message/#{record_id}/", params)
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
class Element
|
533
|
-
class << self
|
534
|
-
attr_accessor :valid_attributes, :nestables
|
535
|
-
end
|
536
|
-
@nestables = []
|
537
|
-
@valid_attributes = []
|
538
|
-
|
539
|
-
attr_accessor :node, :name
|
540
|
-
|
541
|
-
def initialize(body=nil, attributes={}, &block)
|
542
|
-
@name = self.class.name.split('::')[1]
|
543
|
-
@body = body
|
544
|
-
@node = REXML::Element.new @name
|
545
|
-
attributes.each do |k, v|
|
546
|
-
if self.class.valid_attributes.include?(k.to_s)
|
547
|
-
@node.attributes[k.to_s] = convert_value(v)
|
548
|
-
else
|
549
|
-
raise PlivoError, "invalid attribute #{k.to_s} for #{@name}"
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
if @body
|
554
|
-
@node.text = @body
|
555
|
-
end
|
556
|
-
|
557
|
-
# Allow for nested "nestable" elements using a code block
|
558
|
-
# ie
|
559
|
-
# Plivo::Response.new do |r|
|
560
|
-
# r.Dial do |n|
|
561
|
-
# n.Number '+15557779999'
|
562
|
-
# end
|
563
|
-
# end
|
564
|
-
yield(self) if block_given?
|
565
|
-
end
|
566
|
-
|
567
|
-
def method_missing(method, *args, &block)
|
568
|
-
# Handle the addElement methods
|
569
|
-
method = $1.to_sym if method.to_s =~ /^add(.*)/
|
570
|
-
# Add the element
|
571
|
-
add(Plivo.const_get(method).new(*args, &block))
|
572
|
-
end
|
573
|
-
|
574
|
-
|
575
|
-
def convert_value(v)
|
576
|
-
if v == true
|
577
|
-
return "true"
|
578
|
-
elsif v == false
|
579
|
-
return "false"
|
580
|
-
elsif v == nil
|
581
|
-
return "none"
|
582
|
-
elsif v == "get"
|
583
|
-
return "GET"
|
584
|
-
elsif v == "post"
|
585
|
-
return "POST"
|
586
|
-
else
|
587
|
-
return v
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def add(element)
|
592
|
-
if not element
|
593
|
-
raise PlivoError, "invalid element"
|
594
|
-
end
|
595
|
-
if self.class.nestables.include?(element.name)
|
596
|
-
@node.elements << element.node
|
597
|
-
return element
|
598
|
-
else
|
599
|
-
raise PlivoError, "#{element.name} not nestable in #{@name}"
|
600
|
-
end
|
601
|
-
end
|
602
|
-
|
603
|
-
def to_xml
|
604
|
-
return @node.to_s
|
605
|
-
end
|
606
|
-
|
607
|
-
def to_s
|
608
|
-
return @node.to_s
|
609
|
-
end
|
610
|
-
end
|
611
|
-
|
612
|
-
|
613
|
-
class Response < Element
|
614
|
-
@nestables = ['Speak', 'Play', 'GetDigits', 'Record', 'Dial', 'Message',
|
615
|
-
'Redirect', 'Wait', 'Hangup', 'PreAnswer', 'Conference', 'DTMF']
|
616
|
-
@valid_attributes = []
|
617
|
-
|
618
|
-
def initialize()
|
619
|
-
super(nil, {})
|
620
|
-
end
|
621
|
-
|
622
|
-
def to_xml()
|
623
|
-
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
624
|
-
end
|
625
|
-
|
626
|
-
def to_s()
|
627
|
-
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
628
|
-
end
|
629
|
-
end
|
630
|
-
|
631
|
-
|
632
|
-
class Speak < Element
|
633
|
-
@nestables = []
|
634
|
-
@valid_attributes = ['voice', 'language', 'loop']
|
635
|
-
|
636
|
-
def initialize(body, attributes={})
|
637
|
-
if not body
|
638
|
-
raise PlivoError, 'No text set for Speak'
|
639
|
-
else
|
640
|
-
body = HTMLEntities.new(:html4).encode(body, :decimal)
|
641
|
-
end
|
642
|
-
super(body, attributes)
|
643
|
-
end
|
644
|
-
end
|
645
|
-
|
646
|
-
|
647
|
-
class Play < Element
|
648
|
-
@nestables = []
|
649
|
-
@valid_attributes = ['loop']
|
650
|
-
|
651
|
-
def initialize(body, attributes={})
|
652
|
-
if not body
|
653
|
-
raise PlivoError 'No url set for Play'
|
654
|
-
end
|
655
|
-
super(body, attributes)
|
656
|
-
end
|
657
|
-
end
|
658
|
-
|
659
|
-
|
660
|
-
class Wait < Element
|
661
|
-
@nestables = []
|
662
|
-
@valid_attributes = ['length', 'silence', 'min_silence', 'beep']
|
663
|
-
|
664
|
-
def initialize(attributes={})
|
665
|
-
super(nil, attributes)
|
666
|
-
end
|
667
|
-
end
|
668
|
-
|
669
|
-
|
670
|
-
class Redirect < Element
|
671
|
-
@nestables = []
|
672
|
-
@valid_attributes = ['method']
|
673
|
-
|
674
|
-
def initialize(body, attributes={})
|
675
|
-
if not body
|
676
|
-
raise PlivoError 'No url set for Redirect'
|
677
|
-
end
|
678
|
-
super(body, attributes)
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
|
-
|
683
|
-
class Hangup < Element
|
684
|
-
@nestables = []
|
685
|
-
@valid_attributes = ['schedule', 'reason']
|
686
|
-
|
687
|
-
def initialize(attributes={})
|
688
|
-
super(nil, attributes)
|
689
|
-
end
|
690
|
-
end
|
691
|
-
|
692
|
-
|
693
|
-
class GetDigits < Element
|
694
|
-
@nestables = ['Speak', 'Play', 'Wait']
|
695
|
-
@valid_attributes = ['action', 'method', 'timeout', 'digitTimeout',
|
696
|
-
'numDigits', 'retries', 'invalidDigitsSound',
|
697
|
-
'validDigits', 'playBeep', 'redirect', "finishOnKey",
|
698
|
-
'digitTimeout', 'log']
|
699
|
-
|
700
|
-
def initialize(attributes={}, &block)
|
701
|
-
super(nil, attributes, &block)
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
|
706
|
-
class Number < Element
|
707
|
-
@nestables = []
|
708
|
-
@valid_attributes = ['sendDigits', 'sendOnPreanswer']
|
709
|
-
|
710
|
-
def initialize(body, attributes={})
|
711
|
-
if not body
|
712
|
-
raise PlivoError, 'No number set for Number'
|
713
|
-
end
|
714
|
-
super(body, attributes)
|
715
|
-
end
|
716
|
-
end
|
717
|
-
|
718
|
-
|
719
|
-
class User < Element
|
720
|
-
@nestables = []
|
721
|
-
@valid_attributes = ['sendDigits', 'sendOnPreanswer', 'sipHeaders']
|
722
|
-
|
723
|
-
def initialize(body, attributes={})
|
724
|
-
if not body
|
725
|
-
raise PlivoError, 'No user set for User'
|
726
|
-
end
|
727
|
-
super(body, attributes)
|
728
|
-
end
|
729
|
-
end
|
730
|
-
|
731
|
-
|
732
|
-
class Dial < Element
|
733
|
-
@nestables = ['Number', 'User']
|
734
|
-
@valid_attributes = ['action','method','timeout','hangupOnStar',
|
735
|
-
'timeLimit','callerId', 'callerName', 'confirmSound',
|
736
|
-
'dialMusic', 'confirmKey', 'redirect',
|
737
|
-
'callbackUrl', 'callbackMethod', 'digitsMatch', 'digitsMatchBLeg',
|
738
|
-
'sipHeaders']
|
739
|
-
|
740
|
-
def initialize(attributes={}, &block)
|
741
|
-
super(nil, attributes, &block)
|
742
|
-
end
|
743
|
-
end
|
744
|
-
|
745
|
-
|
746
|
-
class Conference < Element
|
747
|
-
@nestables = []
|
748
|
-
@valid_attributes = ['muted','beep','startConferenceOnEnter',
|
749
|
-
'endConferenceOnExit','waitSound','enterSound', 'exitSound',
|
750
|
-
'timeLimit', 'hangupOnStar', 'maxMembers',
|
751
|
-
'record', 'recordFileFormat', 'action', 'method', 'redirect',
|
752
|
-
'digitsMatch', 'callbackUrl', 'callbackMethod',
|
753
|
-
'stayAlone', 'floorEvent',
|
754
|
-
'transcriptionType', 'transcriptionUrl',
|
755
|
-
'transcriptionMethod', 'recordWhenAlone', 'relayDTMF']
|
756
|
-
|
757
|
-
def initialize(body, attributes={})
|
758
|
-
if not body
|
759
|
-
raise PlivoError, 'No conference name set for Conference'
|
760
|
-
end
|
761
|
-
super(body, attributes)
|
762
|
-
end
|
763
|
-
end
|
764
|
-
|
765
|
-
|
766
|
-
class Record < Element
|
767
|
-
@nestables = []
|
768
|
-
@valid_attributes = ['action', 'method', 'timeout','finishOnKey',
|
769
|
-
'maxLength', 'playBeep', 'recordSession',
|
770
|
-
'startOnDialAnswer', 'redirect', 'fileFormat',
|
771
|
-
'callbackUrl', 'callbackMethod',
|
772
|
-
'transcriptionType', 'transcriptionUrl',
|
773
|
-
'transcriptionMethod']
|
774
|
-
|
775
|
-
def initialize(attributes={})
|
776
|
-
super(nil, attributes)
|
777
|
-
end
|
778
|
-
end
|
779
|
-
|
780
|
-
|
781
|
-
class PreAnswer < Element
|
782
|
-
@nestables = ['Play', 'Speak', 'GetDigits', 'Wait', 'Redirect', 'Message', 'DTMF']
|
783
|
-
@valid_attributes = []
|
784
|
-
|
785
|
-
def initialize(attributes={}, &block)
|
786
|
-
super(nil, attributes, &block)
|
787
|
-
end
|
788
|
-
end
|
789
|
-
|
790
|
-
|
791
|
-
class Message < Element
|
792
|
-
@nestables = []
|
793
|
-
@valid_attributes = ['src', 'dst', 'type', 'callbackUrl', 'callbackMethod']
|
794
|
-
|
795
|
-
def initialize(body, attributes={})
|
796
|
-
if not body
|
797
|
-
raise PlivoError, 'No text set for Message'
|
798
|
-
end
|
799
|
-
super(body, attributes)
|
800
|
-
end
|
801
|
-
end
|
802
|
-
|
803
|
-
class DTMF < Element
|
804
|
-
@nestables = []
|
805
|
-
@valid_attributes = ['async']
|
806
|
-
|
807
|
-
def initialize(body, attributes={})
|
808
|
-
if not body
|
809
|
-
raise PlivoError, 'No digits set for DTMF'
|
810
|
-
end
|
811
|
-
super(body, attributes)
|
812
|
-
end
|
813
|
-
end
|
814
|
-
|
815
|
-
end
|
1
|
+
require_relative 'plivo/version'
|
2
|
+
require_relative 'plivo/exceptions'
|
3
|
+
require_relative 'plivo/utils'
|
4
|
+
require_relative 'plivo/base'
|
5
|
+
require_relative 'plivo/resources'
|
6
|
+
require_relative 'plivo/rest_client'
|
7
|
+
require_relative 'plivo/xml'
|
8
|
+
require_relative 'plivo/jwt'
|
9
|
+
require_relative 'plivo/phlo_client'
|
10
|
+
require_relative 'plivo/base_client'
|
11
|
+
|
12
|
+
module Plivo; end
|