plivo 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rst +5 -0
- data/lib/plivo.rb +714 -699
- data/lib/plivo_call.rb +7 -0
- metadata +23 -6
data/README.rst
CHANGED
data/lib/plivo.rb
CHANGED
@@ -3,703 +3,718 @@ require 'restclient'
|
|
3
3
|
require 'json'
|
4
4
|
require 'rexml/document'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
6
|
+
module Plivo
|
7
|
+
class PlivoError < Exception
|
8
|
+
end
|
9
|
+
|
10
|
+
class RestAPI
|
11
|
+
attr_accessor :auth_id, :auth_token, :url, :version, :api, :headers, :rest
|
12
|
+
|
13
|
+
def initialize(auth_id, auth_token, url="https://api.plivo.com", version="v1")
|
14
|
+
@auth_id = auth_id
|
15
|
+
@auth_token = auth_token
|
16
|
+
@url = url.chomp('/')
|
17
|
+
@version = version
|
18
|
+
@api = @url + '/' + @version + '/Account/' + @auth_id
|
19
|
+
@headers = {"User-Agent" => "RubyPlivo"}
|
20
|
+
@rest = RestClient::Resource.new(@api, @auth_id, @auth_token)
|
21
|
+
end
|
22
|
+
|
23
|
+
def hash_to_params(myhash)
|
24
|
+
return myhash.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
|
25
|
+
end
|
26
|
+
|
27
|
+
def request(method, path, params=nil)
|
28
|
+
if method == "POST"
|
29
|
+
if params
|
30
|
+
begin
|
31
|
+
r = @rest[path].post params.to_json, :content_type => 'application/json'
|
32
|
+
rescue => e
|
33
|
+
response = e
|
34
|
+
end
|
35
|
+
else
|
36
|
+
begin
|
37
|
+
r = @rest[path].post
|
38
|
+
rescue => e
|
39
|
+
response = e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
if not response
|
43
|
+
code = r.code
|
44
|
+
raw = r.to_str
|
45
|
+
response = JSON.parse(raw)
|
46
|
+
end
|
47
|
+
return [code, response]
|
48
|
+
elsif method == "GET"
|
49
|
+
if params
|
50
|
+
path = path + '?' + hash_to_params(params)
|
51
|
+
end
|
52
|
+
|
53
|
+
begin
|
54
|
+
r = @rest[path].get
|
55
|
+
rescue => e
|
56
|
+
response = e
|
57
|
+
end
|
58
|
+
if not response
|
59
|
+
code = r.code
|
60
|
+
raw = r.to_str
|
61
|
+
response = JSON.parse(raw)
|
62
|
+
end
|
63
|
+
return [code, response]
|
64
|
+
elsif method == "DELETE"
|
65
|
+
if params
|
66
|
+
path = path + '?' + hash_to_params(params)
|
67
|
+
end
|
68
|
+
begin
|
69
|
+
r = @rest[path].delete
|
70
|
+
rescue => e
|
71
|
+
response = e
|
72
|
+
end
|
73
|
+
if not response
|
74
|
+
code = r.code
|
75
|
+
end
|
76
|
+
return [code, ""]
|
77
|
+
end
|
78
|
+
return [405, 'Method Not Supported']
|
79
|
+
end
|
80
|
+
|
81
|
+
## Accounts ##
|
82
|
+
def get_account(params={})
|
83
|
+
return request('GET', '/')
|
84
|
+
end
|
85
|
+
|
86
|
+
def modify_account(params={})
|
87
|
+
return request('POST', '/', params)
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_subaccounts(params={})
|
91
|
+
return request('GET', '/Subaccount/')
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_subaccount(params={})
|
95
|
+
return request('POST', '/Subaccount/', params)
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_subaccount(params={})
|
99
|
+
subauth_id = params.delete("subauth_id")
|
100
|
+
return request('GET', '/Subaccount/#{subauth_id}/')
|
101
|
+
end
|
102
|
+
|
103
|
+
def modify_subaccount(params={})
|
104
|
+
subauth_id = params.delete("subauth_id")
|
105
|
+
return request('POST', '/Subaccount/#{subauth_id}/', params)
|
106
|
+
end
|
107
|
+
|
108
|
+
def delete_subaccount(params={})
|
109
|
+
subauth_id = params.delete("subauth_id")
|
110
|
+
return request('DELETE', '/Subaccount/#{subauth_id}/')
|
111
|
+
end
|
112
|
+
|
113
|
+
## Applications ##
|
114
|
+
def get_applications(params={})
|
115
|
+
return request('GET', '/Application/', params)
|
116
|
+
end
|
117
|
+
|
118
|
+
def create_application(params={})
|
119
|
+
return request('POST', '/Application/', params)
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_application(params={})
|
123
|
+
app_id = params.delete("app_id")
|
124
|
+
return request('GET', '/Application/#{app_id}/')
|
125
|
+
end
|
126
|
+
|
127
|
+
def modify_application(params={})
|
128
|
+
app_id = params.delete("app_id")
|
129
|
+
return request('POST', '/Application/#{app_id}/', params)
|
130
|
+
end
|
131
|
+
|
132
|
+
def delete_application(params={})
|
133
|
+
app_id = params.delete("app_id")
|
134
|
+
return request('DELETE', '/Application/#{app_id}/')
|
135
|
+
end
|
136
|
+
|
137
|
+
## Numbers ##
|
138
|
+
def get_numbers(params={})
|
139
|
+
return request('GET', '/Number/', params)
|
140
|
+
end
|
141
|
+
|
142
|
+
def search_numbers(params={})
|
143
|
+
return request('GET', '/AvailableNumber/', params)
|
144
|
+
end
|
145
|
+
|
146
|
+
def get_number(params={})
|
147
|
+
number = params.delete("number")
|
148
|
+
return request('GET', '/Number/#{number}/')
|
149
|
+
end
|
150
|
+
|
151
|
+
def rent_number(params={})
|
152
|
+
number = params.delete("number")
|
153
|
+
return request('POST', '/AvailableNumber/#{number}/')
|
154
|
+
end
|
155
|
+
|
156
|
+
def unrent_number(params={})
|
157
|
+
number = params.delete("number")
|
158
|
+
return request('DELETE', '/Number/#{number}/')
|
159
|
+
end
|
160
|
+
|
161
|
+
def link_application_number(params={})
|
162
|
+
number = params.delete("number")
|
163
|
+
return request('POST', '/Number/#{number}/', params)
|
164
|
+
end
|
165
|
+
|
166
|
+
def unlink_application_number(params={})
|
167
|
+
number = params.delete("number")
|
168
|
+
params = {"app_id" => ""}
|
169
|
+
return request('POST', '/Number/#{number}/', params)
|
170
|
+
end
|
171
|
+
|
172
|
+
## Schedule ##
|
173
|
+
def get_scheduled_tasks(params={})
|
174
|
+
return request('GET', '/Schedule/')
|
175
|
+
end
|
176
|
+
|
177
|
+
def cancel_scheduled_task(params={})
|
178
|
+
task_id = params.delete("task_id")
|
179
|
+
return request('DELETE', '/Schedule/#{task_id}/')
|
180
|
+
end
|
181
|
+
|
182
|
+
## Calls ##
|
183
|
+
def get_cdrs(params={})
|
184
|
+
return request('GET', '/Call/', params)
|
185
|
+
end
|
186
|
+
|
187
|
+
def get_cdr(params={})
|
188
|
+
record_id = params.delete('record_id')
|
189
|
+
return request('GET', '/Call/#{record_id}/')
|
190
|
+
end
|
191
|
+
|
192
|
+
def get_live_calls(params={})
|
193
|
+
return request('GET', '/Call/', params={'status'=>'live'})
|
194
|
+
end
|
195
|
+
|
196
|
+
def get_live_call(params={})
|
197
|
+
call_uuid = params.delete('call_uuid')
|
198
|
+
return request('GET', '/Call/#{call_uuid}/', params={'status'=>'live'})
|
199
|
+
end
|
200
|
+
|
201
|
+
def make_call(params={})
|
202
|
+
return request('POST', '/Call/', params)
|
203
|
+
end
|
204
|
+
|
205
|
+
def hangup_all_calls(params={})
|
206
|
+
return request('DELETE', '/Call/')
|
207
|
+
end
|
208
|
+
|
209
|
+
def transfer_call(params={})
|
210
|
+
call_uuid = params.delete('call_uuid')
|
211
|
+
return request('POST', '/Call/#{call_uuid}/', params)
|
212
|
+
end
|
213
|
+
|
214
|
+
def hangup_call(params={})
|
215
|
+
call_uuid = params.delete('call_uuid')
|
216
|
+
return request('DELETE', '/Call/#{call_uuid}/')
|
217
|
+
end
|
218
|
+
|
219
|
+
def record(params={})
|
220
|
+
call_uuid = params.delete('call_uuid')
|
221
|
+
return request('POST', '/Call/#{call_uuid}/Record/', params)
|
222
|
+
end
|
223
|
+
|
224
|
+
def stop_record(params={})
|
225
|
+
call_uuid = params.delete('call_uuid')
|
226
|
+
return request('DELETE', '/Call/#{call_uuid}/Record/')
|
227
|
+
end
|
228
|
+
|
229
|
+
def play(params={})
|
230
|
+
call_uuid = params.delete('call_uuid')
|
231
|
+
return request('POST', '/Call/#{call_uuid}/Play/', params)
|
232
|
+
end
|
233
|
+
|
234
|
+
def stop_play(params={})
|
235
|
+
call_uuid = params.delete('call_uuid')
|
236
|
+
return request('DELETE', '/Call/#{call_uuid}/Play/')
|
237
|
+
end
|
238
|
+
|
239
|
+
def speak(params={})
|
240
|
+
call_uuid = params.delete('call_uuid')
|
241
|
+
return request('POST', '/Call/#{call_uuid}/Speak/', params)
|
242
|
+
end
|
243
|
+
|
244
|
+
def send_digits(params={})
|
245
|
+
call_uuid = params.delete('call_uuid')
|
246
|
+
return request('POST', '/Call/#{call_uuid}/DTMF/', params)
|
247
|
+
end
|
248
|
+
|
249
|
+
## Calls requests ##
|
250
|
+
def hangup_request(params={})
|
251
|
+
request_uuid = params.delete('request_uuid')
|
252
|
+
return request('DELETE', '/Request/#{request_uuid}/')
|
253
|
+
end
|
254
|
+
|
255
|
+
## Conferences ##
|
256
|
+
def get_live_conferences(params={})
|
257
|
+
return request('GET', '/Conference/', params)
|
258
|
+
end
|
259
|
+
|
260
|
+
def hangup_all_conferences(params={})
|
261
|
+
return request('DELETE', '/Conference/')
|
262
|
+
end
|
263
|
+
|
264
|
+
def get_live_conference(params={})
|
265
|
+
conference_id = params.delete('conference_id')
|
266
|
+
return request('GET', '/Conference/#{conference_id}/', params)
|
267
|
+
end
|
268
|
+
|
269
|
+
def hangup_conference(params={})
|
270
|
+
conference_id = params.delete('conference_id')
|
271
|
+
return request('DELETE', '/Conference/#{conference_id}/')
|
272
|
+
end
|
273
|
+
|
274
|
+
def hangup_member(params={})
|
275
|
+
conference_id = params.delete('conference_id')
|
276
|
+
member_id = params.delete('member_id')
|
277
|
+
return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/')
|
278
|
+
end
|
279
|
+
|
280
|
+
def play_member(params={})
|
281
|
+
conference_id = params.delete('conference_id')
|
282
|
+
member_id = params.delete('member_id')
|
283
|
+
return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Play/', params)
|
284
|
+
end
|
285
|
+
|
286
|
+
def stop_play_member(params={})
|
287
|
+
conference_id = params.delete('conference_id')
|
288
|
+
member_id = params.delete('member_id')
|
289
|
+
return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/Play/')
|
290
|
+
end
|
291
|
+
|
292
|
+
def speak_member(params={})
|
293
|
+
conference_id = params.delete('conference_id')
|
294
|
+
member_id = params.delete('member_id')
|
295
|
+
return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Speak/', params)
|
296
|
+
end
|
297
|
+
|
298
|
+
def deaf_member(params={})
|
299
|
+
conference_id = params.delete('conference_id')
|
300
|
+
member_id = params.delete('member_id')
|
301
|
+
return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Deaf/')
|
302
|
+
end
|
303
|
+
|
304
|
+
def undeaf_member(params={})
|
305
|
+
conference_id = params.delete('conference_id')
|
306
|
+
member_id = params.delete('member_id')
|
307
|
+
return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/Deaf/')
|
308
|
+
end
|
309
|
+
|
310
|
+
def mute_member(params={})
|
311
|
+
conference_id = params.delete('conference_id')
|
312
|
+
member_id = params.delete('member_id')
|
313
|
+
return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Mute/')
|
314
|
+
end
|
315
|
+
|
316
|
+
def unmute_member(params={})
|
317
|
+
conference_id = params.delete('conference_id')
|
318
|
+
member_id = params.delete('member_id')
|
319
|
+
return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/Mute/')
|
320
|
+
end
|
321
|
+
|
322
|
+
def kick_member(params={})
|
323
|
+
conference_id = params.delete('conference_id')
|
324
|
+
member_id = params.delete('member_id')
|
325
|
+
return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Kick/')
|
326
|
+
end
|
327
|
+
|
328
|
+
def record_conference(params={})
|
329
|
+
conference_id = params.delete('conference_id')
|
330
|
+
return request('POST', '/Conference/#{conference_id}/Record/', params)
|
331
|
+
end
|
332
|
+
|
333
|
+
def stop_record_conference(params={})
|
334
|
+
conference_id = params.delete('conference_id')
|
335
|
+
return request('DELETE', '/Conference/#{conference_id}/Record/')
|
336
|
+
end
|
337
|
+
|
338
|
+
## Recordings ##
|
339
|
+
def get_recordings(params={})
|
340
|
+
return request('GET', '/Recording/', params)
|
341
|
+
end
|
342
|
+
|
343
|
+
def get_recording(params={})
|
344
|
+
recording_id = params.delete('recording_id')
|
345
|
+
return request('GET', '/Recording/#{recording_id}/')
|
346
|
+
end
|
347
|
+
|
348
|
+
## Endpoints ##
|
349
|
+
def get_endpoints(params={})
|
350
|
+
return request('GET', '/Endpoint/', params)
|
351
|
+
end
|
352
|
+
|
353
|
+
def create_endpoint(params={})
|
354
|
+
return request('POST', '/Endpoint/', params)
|
355
|
+
end
|
356
|
+
|
357
|
+
def get_endpoint(params={})
|
358
|
+
endpoint_id = params.delete('endpoint_id')
|
359
|
+
return request('GET', '/Endpoint/#{endpoint_id}/')
|
360
|
+
end
|
361
|
+
|
362
|
+
def modify_endpoint(params={})
|
363
|
+
endpoint_id = params.delete('endpoint_id')
|
364
|
+
return request('POST', '/Endpoint/#{endpoint_id}/', params)
|
365
|
+
end
|
366
|
+
|
367
|
+
def delete_endpoint(params={})
|
368
|
+
endpoint_id = params.delete('endpoint_id')
|
369
|
+
return request('DELETE', '/Endpoint/#{endpoint_id}/')
|
370
|
+
end
|
371
|
+
|
372
|
+
## Carriers ##
|
373
|
+
def get_carriers(params={})
|
374
|
+
return request('GET', '/Carrier/', params)
|
375
|
+
end
|
376
|
+
|
377
|
+
def create_carrier(params={})
|
378
|
+
return request('POST', '/Carrier/', params)
|
379
|
+
end
|
380
|
+
|
381
|
+
def get_carrier(params={})
|
382
|
+
carrier_id = params.delete('carrier_id')
|
383
|
+
return request('GET', '/Carrier/#{carrier_id}/')
|
384
|
+
end
|
385
|
+
|
386
|
+
def modify_carrier(params={})
|
387
|
+
carrier_id = params.delete('carrier_id')
|
388
|
+
return request('POST', '/Carrier/#{carrier_id}/', params)
|
389
|
+
end
|
390
|
+
|
391
|
+
def delete_carrier(params={})
|
392
|
+
carrier_id = params.delete('carrier_id')
|
393
|
+
return request('DELETE', '/Carrier/#{carrier_id}/')
|
394
|
+
end
|
395
|
+
|
396
|
+
## Carrier Routings ##
|
397
|
+
def get_carrier_routings(params={})
|
398
|
+
return request('GET', '/CarrierRouting/', params)
|
399
|
+
end
|
400
|
+
|
401
|
+
def create_carrier_routing(params={})
|
402
|
+
return request('POST', '/CarrierRouting/', params)
|
403
|
+
end
|
404
|
+
|
405
|
+
def get_carrier_routing(params={})
|
406
|
+
routing_id = params.delete('routing_id')
|
407
|
+
return request('GET', '/CarrierRouting/#{routing_id}/')
|
408
|
+
end
|
409
|
+
|
410
|
+
def modify_carrier_routing(params={})
|
411
|
+
routing_id = params.delete('routing_id')
|
412
|
+
return request('POST', '/CarrierRouting/#{routing_id}/', params)
|
413
|
+
end
|
414
|
+
|
415
|
+
def delete_carrier_routing(params={})
|
416
|
+
routing_id = params.delete('routing_id')
|
417
|
+
return request('DELETE', '/CarrierRouting/#{routing_id}/')
|
418
|
+
end
|
419
|
+
|
420
|
+
## Message ##
|
421
|
+
def send_message(params={})
|
422
|
+
return request('POST', '/Message/', params)
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
class Element
|
429
|
+
class << self
|
430
|
+
attr_accessor :valid_attributes, :nestables
|
431
|
+
end
|
432
|
+
@nestables = []
|
433
|
+
@valid_attributes = []
|
434
|
+
|
435
|
+
attr_accessor :name, :node
|
436
|
+
|
437
|
+
def initialize(body=nil, attributes={})
|
438
|
+
@name = self.class.name
|
439
|
+
@body = body
|
440
|
+
@node = REXML::Element.new @name
|
441
|
+
attributes.each do |k, v|
|
442
|
+
if self.class.valid_attributes.include?(k)
|
443
|
+
@node.attributes[k] = convert_value(v)
|
444
|
+
else
|
445
|
+
raise PlivoError, 'invalid attribute ' + k + ' for ' + @name
|
446
|
+
end
|
447
|
+
end
|
448
|
+
if @body
|
449
|
+
@node.text = @body
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
def convert_value(v)
|
454
|
+
if v == true
|
455
|
+
return "true"
|
456
|
+
elsif v == false
|
457
|
+
return "false"
|
458
|
+
elsif v == nil
|
459
|
+
return "none"
|
460
|
+
elsif v == "get"
|
461
|
+
return "GET"
|
462
|
+
elsif v == "post"
|
463
|
+
return "POST"
|
464
|
+
else
|
465
|
+
return v
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
def add(element)
|
470
|
+
if self.class.nestables.include?(element.name)
|
471
|
+
@node.elements << element.node
|
472
|
+
return element
|
473
|
+
else
|
474
|
+
raise PlivoError, element.name + ' not nestable in ' + @name
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
def to_xml
|
479
|
+
return @node.to_s
|
480
|
+
end
|
481
|
+
|
482
|
+
def to_s
|
483
|
+
return @node.to_s
|
484
|
+
end
|
485
|
+
|
486
|
+
def addSpeak(body, attributes={})
|
487
|
+
return add(Speak.new(body, attributes))
|
488
|
+
end
|
489
|
+
|
490
|
+
def addPlay(body, attributes={})
|
491
|
+
return add(Play.new(body, attributes))
|
492
|
+
end
|
493
|
+
|
494
|
+
def addGetDigits(attributes={})
|
495
|
+
return add(GetDigits.new(attributes))
|
496
|
+
end
|
497
|
+
|
498
|
+
def addRecord(attributes={})
|
499
|
+
return add(Record.new(attributes))
|
500
|
+
end
|
501
|
+
|
502
|
+
def addDial(attributes={})
|
503
|
+
return add(Dial.new(attributes))
|
504
|
+
end
|
505
|
+
|
506
|
+
def addNumber(body, attributes={})
|
507
|
+
return add(Number.new(body, attributes))
|
508
|
+
end
|
509
|
+
|
510
|
+
def addUser(body, attributes={})
|
511
|
+
return add(User.new(body, attributes))
|
512
|
+
end
|
513
|
+
|
514
|
+
def addRedirect(body, attributes={})
|
515
|
+
return add(Redirect.new(body, attributes))
|
516
|
+
end
|
517
|
+
|
518
|
+
def addWait(attributes={})
|
519
|
+
return add(Wait.new(attributes))
|
520
|
+
end
|
521
|
+
|
522
|
+
def addHangup(attributes={})
|
523
|
+
return add(Hangup.new(attributes))
|
524
|
+
end
|
525
|
+
|
526
|
+
def addPreAnswer(attributes={})
|
527
|
+
return add(PreAnswer.new(attributes))
|
528
|
+
end
|
529
|
+
|
530
|
+
def addConference(body, attributes={})
|
531
|
+
return add(Conference.new(body, attributes))
|
532
|
+
end
|
533
|
+
|
534
|
+
def addMessage(body, attributes={})
|
535
|
+
return add(Message.new(body, attributes))
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
|
540
|
+
class Response < Element
|
541
|
+
@nestables = ['Speak', 'Play', 'GetDigits', 'Record', 'Dial', 'Message',
|
542
|
+
'Redirect', 'Wait', 'Hangup', 'PreAnswer', 'Conference']
|
543
|
+
@valid_attributes = []
|
544
|
+
|
545
|
+
def initialize()
|
546
|
+
super(nil, {})
|
547
|
+
end
|
548
|
+
|
549
|
+
def to_xml()
|
550
|
+
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
551
|
+
end
|
552
|
+
|
553
|
+
def to_s()
|
554
|
+
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
|
559
|
+
class Speak < Element
|
560
|
+
@nestables = []
|
561
|
+
@valid_attributes = ['voice', 'language', 'loop']
|
562
|
+
|
563
|
+
def initialize(body, attributes={})
|
564
|
+
if not body
|
565
|
+
raise PlivoError, 'No text set for ' + @name
|
566
|
+
end
|
567
|
+
super(body, attributes)
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
|
572
|
+
class Play < Element
|
573
|
+
@nestables = []
|
574
|
+
@valid_attributes = ['loop']
|
575
|
+
|
576
|
+
def initialize(body, attributes={})
|
577
|
+
if not body
|
578
|
+
raise PlivoError 'No url set for ' + @name
|
579
|
+
end
|
580
|
+
super(body, attributes)
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
|
585
|
+
class Wait < Element
|
586
|
+
@nestables = []
|
587
|
+
@valid_attributes = ['length']
|
588
|
+
|
589
|
+
def initialize(attributes={})
|
590
|
+
super(nil, attributes)
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
|
595
|
+
class Redirect < Element
|
596
|
+
@nestables = []
|
597
|
+
@valid_attributes = ['method']
|
598
|
+
|
599
|
+
def initialize(body, attributes={})
|
600
|
+
if not body
|
601
|
+
raise PlivoError 'No url set for ' + @name
|
602
|
+
end
|
603
|
+
super(body, attributes)
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
|
608
|
+
class Hangup < Element
|
609
|
+
@nestables = []
|
610
|
+
@valid_attributes = ['schedule', 'reason']
|
611
|
+
|
612
|
+
def initialize(attributes={})
|
613
|
+
super(nil, attributes)
|
614
|
+
end
|
615
|
+
end
|
616
|
+
|
617
|
+
|
618
|
+
class GetDigits < Element
|
619
|
+
@nestables = ['Speak', 'Play', 'Wait']
|
620
|
+
@valid_attributes = ['action', 'method', 'timeout', 'finishOnKey',
|
621
|
+
'numDigits', 'retries', 'invalidDigitsSound',
|
622
|
+
'validDigits', 'playBeep']
|
623
|
+
|
624
|
+
def initialize(attributes={})
|
625
|
+
super(nil, attributes)
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
|
630
|
+
class Number < Element
|
631
|
+
@nestables = []
|
632
|
+
@valid_attributes = ['sendDigits', 'sendOnPreanswer']
|
633
|
+
|
634
|
+
def initialize(body, attributes={})
|
635
|
+
if not body
|
636
|
+
raise PlivoError, 'No number set for ' + @name
|
637
|
+
end
|
638
|
+
super(body, attributes)
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
642
|
+
|
643
|
+
class User < Element
|
644
|
+
@nestables = []
|
645
|
+
@valid_attributes = ['sendDigits', 'sendOnPreanswer']
|
646
|
+
|
647
|
+
def initialize(body, attributes={})
|
648
|
+
if not body
|
649
|
+
raise PlivoError, 'No user set for ' + @name
|
650
|
+
end
|
651
|
+
super(body, attributes)
|
652
|
+
end
|
653
|
+
end
|
654
|
+
|
655
|
+
|
656
|
+
class Dial < Element
|
657
|
+
@nestables = ['Number', 'User']
|
658
|
+
@valid_attributes = ['action','method','timeout','hangupOnStar',
|
659
|
+
'timeLimit','callerId', 'callerName', 'confirmSound',
|
660
|
+
'dialMusic', 'confirmKey', 'redirect',
|
661
|
+
'callbackUrl', 'callbackMethod', 'digitsMatch']
|
662
|
+
|
663
|
+
def initialize(attributes={})
|
664
|
+
super(nil, attributes)
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
|
669
|
+
class Conference < Element
|
670
|
+
@nestables = []
|
671
|
+
@valid_attributes = ['muted','beep','startConferenceOnEnter',
|
672
|
+
'endConferenceOnExit','waitSound','enterSound', 'exitSound',
|
673
|
+
'timeLimit', 'hangupOnStar', 'maxMembers',
|
674
|
+
'record', 'recordFileFormat', 'action', 'method', 'redirect',
|
675
|
+
'digitsMatch', 'callbackUrl', 'callbackMethod',
|
676
|
+
'stayAlone', 'floorEvent']
|
677
|
+
|
678
|
+
def initialize(body, attributes={})
|
679
|
+
if not body
|
680
|
+
raise PlivoError, 'No conference name set for ' + @name
|
681
|
+
end
|
682
|
+
super(body, attributes)
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
|
687
|
+
class Record < Element
|
688
|
+
@nestables = []
|
689
|
+
@valid_attributes = ['action', 'method', 'timeout','finishOnKey',
|
690
|
+
'maxLength', 'bothLegs', 'playBeep',
|
691
|
+
'redirect', 'fileFormat']
|
692
|
+
|
693
|
+
def initialize(attributes={})
|
694
|
+
super(nil, attributes)
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
|
699
|
+
class PreAnswer < Element
|
700
|
+
@nestables = ['Play', 'Speak', 'GetDigits', 'Wait', 'Redirect', 'Message']
|
701
|
+
@valid_attributes = []
|
702
|
+
|
703
|
+
def initialize(attributes={})
|
704
|
+
super(nil, attributes)
|
705
|
+
end
|
706
|
+
end
|
707
|
+
|
708
|
+
|
709
|
+
class Message < Element
|
710
|
+
@nestables = []
|
711
|
+
@valid_attributes = ['src', 'dst', 'type', 'callbackUrl', 'callbackMethod']
|
712
|
+
|
713
|
+
def initialize(body, attributes={})
|
714
|
+
if not body
|
715
|
+
raise PlivoError, 'No text set for ' + @name
|
716
|
+
end
|
717
|
+
super(body, attributes)
|
718
|
+
end
|
719
|
+
end
|
408
720
|
end
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
class Element
|
413
|
-
class << self
|
414
|
-
attr_accessor :valid_attributes, :nestables
|
415
|
-
end
|
416
|
-
@nestables = []
|
417
|
-
@valid_attributes = []
|
418
|
-
|
419
|
-
attr_accessor :name, :node
|
420
|
-
|
421
|
-
def initialize(body=nil, attributes={})
|
422
|
-
@name = self.class.name
|
423
|
-
@body = body
|
424
|
-
@node = REXML::Element.new @name
|
425
|
-
attributes.each do |k, v|
|
426
|
-
if self.class.valid_attributes.include?(k)
|
427
|
-
@node.attributes[k] = convert_value(v)
|
428
|
-
else
|
429
|
-
raise PlivoError, 'invalid attribute ' + k + ' for ' + @name
|
430
|
-
end
|
431
|
-
end
|
432
|
-
if @body
|
433
|
-
@node.text = @body
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
def convert_value(v)
|
438
|
-
if v == true
|
439
|
-
return "true"
|
440
|
-
elsif v == false
|
441
|
-
return "false"
|
442
|
-
elsif v == nil
|
443
|
-
return "none"
|
444
|
-
elsif v == "get"
|
445
|
-
return "GET"
|
446
|
-
elsif v == "post"
|
447
|
-
return "POST"
|
448
|
-
else
|
449
|
-
return v
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
def add(element)
|
454
|
-
if self.class.nestables.include?(element.name)
|
455
|
-
@node.elements << element.node
|
456
|
-
return element
|
457
|
-
else
|
458
|
-
raise PlivoError, element.name + ' not nestable in ' + @name
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
def to_xml
|
463
|
-
return @node.to_s
|
464
|
-
end
|
465
|
-
|
466
|
-
def to_s
|
467
|
-
return @node.to_s
|
468
|
-
end
|
469
|
-
|
470
|
-
def addSpeak(body, attributes={})
|
471
|
-
return add(Speak.new(body, attributes))
|
472
|
-
end
|
473
|
-
|
474
|
-
def addPlay(body, attributes={})
|
475
|
-
return add(Play.new(body, attributes))
|
476
|
-
end
|
477
|
-
|
478
|
-
def addGetDigits(attributes={})
|
479
|
-
return add(GetDigits.new(attributes))
|
480
|
-
end
|
481
|
-
|
482
|
-
def addRecord(attributes={})
|
483
|
-
return add(Record.new(attributes))
|
484
|
-
end
|
485
|
-
|
486
|
-
def addDial(attributes={})
|
487
|
-
return add(Dial.new(attributes))
|
488
|
-
end
|
489
|
-
|
490
|
-
def addNumber(body, attributes={})
|
491
|
-
return add(Number.new(body, attributes))
|
492
|
-
end
|
493
|
-
|
494
|
-
def addUser(body, attributes={})
|
495
|
-
return add(User.new(body, attributes))
|
496
|
-
end
|
497
|
-
|
498
|
-
def addRedirect(body, attributes={})
|
499
|
-
return add(Redirect.new(body, attributes))
|
500
|
-
end
|
501
|
-
|
502
|
-
def addWait(attributes={})
|
503
|
-
return add(Wait.new(attributes))
|
504
|
-
end
|
505
|
-
|
506
|
-
def addHangup(attributes={})
|
507
|
-
return add(Hangup.new(attributes))
|
508
|
-
end
|
509
|
-
|
510
|
-
def addPreAnswer(attributes={})
|
511
|
-
return add(PreAnswer.new(attributes))
|
512
|
-
end
|
513
|
-
|
514
|
-
def addConference(body, attributes={})
|
515
|
-
return add(Conference.new(body, attributes))
|
516
|
-
end
|
517
|
-
|
518
|
-
def addMessage(body, attributes={})
|
519
|
-
return add(Message.new(body, attributes))
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
|
524
|
-
class Response < Element
|
525
|
-
@nestables = ['Speak', 'Play', 'GetDigits', 'Record', 'Dial', 'Message',
|
526
|
-
'Redirect', 'Wait', 'Hangup', 'PreAnswer', 'Conference']
|
527
|
-
@valid_attributes = []
|
528
|
-
|
529
|
-
def initialize()
|
530
|
-
super(nil, {})
|
531
|
-
end
|
532
|
-
|
533
|
-
def to_xml()
|
534
|
-
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
535
|
-
end
|
536
|
-
|
537
|
-
def to_s()
|
538
|
-
return '<?xml version="1.0" encoding="utf-8" ?>' + super()
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
|
543
|
-
class Speak < Element
|
544
|
-
@nestables = []
|
545
|
-
@valid_attributes = ['voice', 'language', 'loop']
|
546
|
-
|
547
|
-
def initialize(body, attributes={})
|
548
|
-
if not body
|
549
|
-
raise PlivoError, 'No text set for ' + @name
|
550
|
-
end
|
551
|
-
super(body, attributes)
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
|
556
|
-
class Play < Element
|
557
|
-
@nestables = []
|
558
|
-
@valid_attributes = ['loop']
|
559
|
-
|
560
|
-
def initialize(body, attributes={})
|
561
|
-
if not body
|
562
|
-
raise PlivoError 'No url set for ' + @name
|
563
|
-
end
|
564
|
-
super(body, attributes)
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
|
569
|
-
class Wait < Element
|
570
|
-
@nestables = []
|
571
|
-
@valid_attributes = ['length']
|
572
|
-
|
573
|
-
def initialize(attributes={})
|
574
|
-
super(nil, attributes)
|
575
|
-
end
|
576
|
-
end
|
577
|
-
|
578
|
-
|
579
|
-
class Redirect < Element
|
580
|
-
@nestables = []
|
581
|
-
@valid_attributes = ['method']
|
582
|
-
|
583
|
-
def initialize(body, attributes={})
|
584
|
-
if not body
|
585
|
-
raise PlivoError 'No url set for ' + @name
|
586
|
-
end
|
587
|
-
super(body, attributes)
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
|
592
|
-
class Hangup < Element
|
593
|
-
@nestables = []
|
594
|
-
@valid_attributes = ['schedule', 'reason']
|
595
|
-
|
596
|
-
def initialize(attributes={})
|
597
|
-
super(nil, attributes)
|
598
|
-
end
|
599
|
-
end
|
600
|
-
|
601
|
-
|
602
|
-
class GetDigits < Element
|
603
|
-
@nestables = ['Speak', 'Play', 'Wait']
|
604
|
-
@valid_attributes = ['action', 'method', 'timeout', 'finishOnKey',
|
605
|
-
'numDigits', 'retries', 'invalidDigitsSound',
|
606
|
-
'validDigits', 'playBeep']
|
607
|
-
|
608
|
-
def initialize(attributes={})
|
609
|
-
super(nil, attributes)
|
610
|
-
end
|
611
|
-
end
|
612
|
-
|
613
|
-
|
614
|
-
class Number < Element
|
615
|
-
@nestables = []
|
616
|
-
@valid_attributes = ['sendDigits', 'sendOnPreanswer']
|
617
|
-
|
618
|
-
def initialize(body, attributes={})
|
619
|
-
if not body
|
620
|
-
raise PlivoError, 'No number set for ' + @name
|
621
|
-
end
|
622
|
-
super(body, attributes)
|
623
|
-
end
|
624
|
-
end
|
625
|
-
|
626
|
-
|
627
|
-
class User < Element
|
628
|
-
@nestables = []
|
629
|
-
@valid_attributes = ['sendDigits', 'sendOnPreanswer']
|
630
|
-
|
631
|
-
def initialize(body, attributes={})
|
632
|
-
if not body
|
633
|
-
raise PlivoError, 'No user set for ' + @name
|
634
|
-
end
|
635
|
-
super(body, attributes)
|
636
|
-
end
|
637
|
-
end
|
638
|
-
|
639
|
-
|
640
|
-
class Dial < Element
|
641
|
-
@nestables = ['Number', 'User']
|
642
|
-
@valid_attributes = ['action','method','timeout','hangupOnStar',
|
643
|
-
'timeLimit','callerId', 'callerName', 'confirmSound',
|
644
|
-
'dialMusic', 'confirmKey', 'redirect',
|
645
|
-
'callbackUrl', 'callbackMethod', 'digitsMatch']
|
646
|
-
|
647
|
-
def initialize(attributes={})
|
648
|
-
super(nil, attributes)
|
649
|
-
end
|
650
|
-
end
|
651
|
-
|
652
|
-
|
653
|
-
class Conference < Element
|
654
|
-
@nestables = []
|
655
|
-
@valid_attributes = ['muted','beep','startConferenceOnEnter',
|
656
|
-
'endConferenceOnExit','waitSound','enterSound', 'exitSound',
|
657
|
-
'timeLimit', 'hangupOnStar', 'maxMembers',
|
658
|
-
'record', 'recordFileFormat', 'action', 'method', 'redirect',
|
659
|
-
'digitsMatch', 'callbackUrl', 'callbackMethod',
|
660
|
-
'stayAlone', 'floorEvent']
|
661
|
-
|
662
|
-
def initialize(body, attributes={})
|
663
|
-
if not body
|
664
|
-
raise PlivoError, 'No conference name set for ' + @name
|
665
|
-
end
|
666
|
-
super(body, attributes)
|
667
|
-
end
|
668
|
-
end
|
669
|
-
|
670
|
-
|
671
|
-
class Record < Element
|
672
|
-
@nestables = []
|
673
|
-
@valid_attributes = ['action', 'method', 'timeout','finishOnKey',
|
674
|
-
'maxLength', 'bothLegs', 'playBeep',
|
675
|
-
'redirect', 'fileFormat']
|
676
|
-
|
677
|
-
def initialize(attributes={})
|
678
|
-
super(nil, attributes)
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
|
-
|
683
|
-
class PreAnswer < Element
|
684
|
-
@nestables = ['Play', 'Speak', 'GetDigits', 'Wait', 'Redirect', 'Message']
|
685
|
-
@valid_attributes = []
|
686
|
-
|
687
|
-
def initialize(attributes={})
|
688
|
-
super(nil, attributes)
|
689
|
-
end
|
690
|
-
end
|
691
|
-
|
692
|
-
|
693
|
-
class Message < Element
|
694
|
-
@nestables = []
|
695
|
-
@valid_attributes = ['src', 'dst', 'type', 'callbackUrl', 'callbackMethod']
|
696
|
-
|
697
|
-
def initialize(body, attributes={})
|
698
|
-
if not body
|
699
|
-
raise PlivoError, 'No text set for ' + @name
|
700
|
-
end
|
701
|
-
super(body, attributes)
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
|