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