plivo 0.3.19 → 4.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/AUTHORS.md +4 -0
- data/CHANGELOG.md +158 -0
- data/Gemfile +10 -0
- data/Jenkinsfile +7 -0
- data/LICENSE.txt +19 -0
- data/README.md +155 -24
- data/Rakefile +9 -0
- data/ci/config.yml +7 -0
- data/examples/conference_bridge.rb +108 -0
- data/examples/jwt.rb +32 -0
- data/examples/lookup.rb +24 -0
- data/examples/multi_party_call.rb +295 -0
- data/examples/phlos.rb +55 -0
- data/examples/regulatory_compliance.rb +167 -0
- data/lib/plivo/base/resource.rb +148 -0
- data/lib/plivo/base/resource_interface.rb +108 -0
- data/lib/plivo/base/response.rb +38 -0
- data/lib/plivo/base.rb +17 -0
- data/lib/plivo/base_client.rb +393 -0
- data/lib/plivo/exceptions.rb +50 -0
- data/lib/plivo/jwt.rb +120 -0
- data/lib/plivo/phlo_client.rb +29 -0
- data/lib/plivo/resources/accounts.rb +181 -0
- data/lib/plivo/resources/addresses.rb +302 -0
- data/lib/plivo/resources/applications.rb +258 -0
- data/lib/plivo/resources/call_feedback.rb +55 -0
- data/lib/plivo/resources/calls.rb +559 -0
- data/lib/plivo/resources/conferences.rb +367 -0
- data/lib/plivo/resources/endpoints.rb +132 -0
- data/lib/plivo/resources/identities.rb +319 -0
- data/lib/plivo/resources/lookup.rb +88 -0
- data/lib/plivo/resources/media.rb +97 -0
- data/lib/plivo/resources/messages.rb +215 -0
- data/lib/plivo/resources/multipartycalls.rb +554 -0
- data/lib/plivo/resources/nodes.rb +83 -0
- data/lib/plivo/resources/numbers.rb +319 -0
- data/lib/plivo/resources/phlo_member.rb +64 -0
- data/lib/plivo/resources/phlos.rb +55 -0
- data/lib/plivo/resources/powerpacks.rb +717 -0
- data/lib/plivo/resources/pricings.rb +43 -0
- data/lib/plivo/resources/recordings.rb +116 -0
- data/lib/plivo/resources/regulatory_compliance.rb +610 -0
- data/lib/plivo/resources.rb +25 -0
- data/lib/plivo/rest_client.rb +63 -0
- data/lib/plivo/utils.rb +294 -0
- data/lib/plivo/version.rb +3 -0
- data/lib/plivo/xml/break.rb +31 -0
- data/lib/plivo/xml/conference.rb +20 -0
- data/lib/plivo/xml/cont.rb +13 -0
- data/lib/plivo/xml/dial.rb +16 -0
- data/lib/plivo/xml/dtmf.rb +13 -0
- data/lib/plivo/xml/element.rb +106 -0
- data/lib/plivo/xml/emphasis.rb +17 -0
- data/lib/plivo/xml/get_digits.rb +15 -0
- data/lib/plivo/xml/get_input.rb +16 -0
- data/lib/plivo/xml/hangup.rb +12 -0
- data/lib/plivo/xml/lang.rb +29 -0
- data/lib/plivo/xml/message.rb +13 -0
- data/lib/plivo/xml/multipartycall.rb +188 -0
- data/lib/plivo/xml/number.rb +13 -0
- data/lib/plivo/xml/p.rb +12 -0
- data/lib/plivo/xml/phoneme.rb +20 -0
- data/lib/plivo/xml/play.rb +13 -0
- data/lib/plivo/xml/plivo_xml.rb +19 -0
- data/lib/plivo/xml/pre_answer.rb +12 -0
- data/lib/plivo/xml/prosody.rb +28 -0
- data/lib/plivo/xml/record.rb +17 -0
- data/lib/plivo/xml/redirect.rb +13 -0
- data/lib/plivo/xml/response.rb +21 -0
- data/lib/plivo/xml/s.rb +12 -0
- data/lib/plivo/xml/say_as.rb +24 -0
- data/lib/plivo/xml/speak.rb +28 -0
- data/lib/plivo/xml/sub.rb +16 -0
- data/lib/plivo/xml/user.rb +13 -0
- data/lib/plivo/xml/w.rb +17 -0
- data/lib/plivo/xml/wait.rb +12 -0
- data/lib/plivo/xml.rb +39 -0
- data/lib/plivo.rb +12 -815
- data/plivo.gemspec +44 -0
- metadata +181 -41
- data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,717 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
|
5
|
+
class Powerpack < Base::Resource
|
6
|
+
def initialize(client, options = nil)
|
7
|
+
@_name = 'Powerpack'
|
8
|
+
@_identifier_string = 'uuid'
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def numberpool
|
13
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
14
|
+
options = {'number_pool_id' => number_pool_uuid}
|
15
|
+
NumberPool.new(@_client, {resource_json: options})
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(unrent_numbers = false)
|
19
|
+
valid_param?(:unrent_numbers, unrent_numbers, [TrueClass, FalseClass],
|
20
|
+
false, [true, false])
|
21
|
+
|
22
|
+
params = {
|
23
|
+
:unrent_numbers => unrent_numbers
|
24
|
+
}
|
25
|
+
perform_action_apiresponse('', 'DELETE', params)
|
26
|
+
# perform_delete(params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def update(options = nil)
|
30
|
+
valid_param?(:options, options, Hash, true)
|
31
|
+
params = {}
|
32
|
+
if options.key?(:application_type)
|
33
|
+
params[:application_type] = options[:application_type]
|
34
|
+
end
|
35
|
+
|
36
|
+
if options.key?(:application_id)
|
37
|
+
params[:application_id] = options[:application_id]
|
38
|
+
end
|
39
|
+
|
40
|
+
if options.key?(:sticky_sender)
|
41
|
+
params[:sticky_sender] = options[:sticky_sender]
|
42
|
+
end
|
43
|
+
|
44
|
+
if options.key?(:local_connect)
|
45
|
+
params[:local_connect] = options[:local_connect]
|
46
|
+
end
|
47
|
+
if options.key?(:name)
|
48
|
+
params[:name] = options[:name]
|
49
|
+
end
|
50
|
+
if options.key?(:number_priority)
|
51
|
+
params[:number_priority] = options[:number_priority]
|
52
|
+
end
|
53
|
+
perform_action_apiresponse('', 'POST', params)
|
54
|
+
end
|
55
|
+
|
56
|
+
def list_numbers(options = nil)
|
57
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
58
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
|
59
|
+
'GET') if options.nil?
|
60
|
+
|
61
|
+
params = {}
|
62
|
+
|
63
|
+
%i[offset limit].each do |param|
|
64
|
+
if options.key?(param) && valid_param?(param, options[param],
|
65
|
+
[Integer, Integer], true)
|
66
|
+
params[param] = options[param]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
71
|
+
raise_invalid_request('The maximum number of results that can be '\
|
72
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
73
|
+
end
|
74
|
+
|
75
|
+
if options.key?(:offset) && options[:offset] < 0
|
76
|
+
raise_invalid_request("Offset can't be negative")
|
77
|
+
end
|
78
|
+
|
79
|
+
if options.key?(:starts_with) &&
|
80
|
+
valid_param?(:starts_with, options[:starts_with], String, true)
|
81
|
+
params[:starts_with] = options[:starts_with]
|
82
|
+
end
|
83
|
+
if options.key?(:country_iso2) &&
|
84
|
+
valid_param?(:country_iso2, options[:country_iso2], String, true)
|
85
|
+
params[:country_iso2] = options[:country_iso2]
|
86
|
+
end
|
87
|
+
if options.key?(:type) &&
|
88
|
+
valid_param?(:type, options[:type], String, true)
|
89
|
+
params[:type] = options[:type]
|
90
|
+
end
|
91
|
+
if options.key?(:service) &&
|
92
|
+
valid_param?(:service, options[:service], String, true)
|
93
|
+
params[:service] = options[:service]
|
94
|
+
end
|
95
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
|
96
|
+
'GET', params, true)
|
97
|
+
end
|
98
|
+
|
99
|
+
def getnumberpool_uuid(uuid)
|
100
|
+
valid_param?(:uuid, uuid, [String, Symbol], true)
|
101
|
+
response = perform_action()
|
102
|
+
numberpool_path = response.number_pool
|
103
|
+
numberpool_array = numberpool_path.split("/")
|
104
|
+
numberpool_array[5]
|
105
|
+
end
|
106
|
+
|
107
|
+
def count_numbers(options = nil)
|
108
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
109
|
+
if options.nil?
|
110
|
+
response = perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
|
111
|
+
'GET')
|
112
|
+
meta = response['meta']
|
113
|
+
return meta['total_count']
|
114
|
+
end
|
115
|
+
|
116
|
+
params = {}
|
117
|
+
|
118
|
+
%i[offset limit].each do |param|
|
119
|
+
if options.key?(param) && valid_param?(param, options[param],
|
120
|
+
[Integer, Integer], true)
|
121
|
+
params[param] = options[param]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
126
|
+
raise_invalid_request('The maximum number of results that can be '\
|
127
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
128
|
+
end
|
129
|
+
|
130
|
+
if options.key?(:offset) && options[:offset] < 0
|
131
|
+
raise_invalid_request("Offset can't be negative")
|
132
|
+
end
|
133
|
+
|
134
|
+
if options.key?(:starts_with) &&
|
135
|
+
valid_param?(:starts_with, options[:starts_with], String, true)
|
136
|
+
params[:starts_with] = options[:starts_with]
|
137
|
+
end
|
138
|
+
if options.key?(:country_iso2) &&
|
139
|
+
valid_param?(:country_iso2, options[:country_iso2], String, true)
|
140
|
+
params[:country_iso2] = options[:country_iso2]
|
141
|
+
end
|
142
|
+
if options.key?(:type) &&
|
143
|
+
valid_param?(:type, options[:type], String, true)
|
144
|
+
params[:type] = options[:type]
|
145
|
+
end
|
146
|
+
if options.key?(:service) &&
|
147
|
+
valid_param?(:service, options[:service], String, true)
|
148
|
+
params[:service] = options[:service]
|
149
|
+
end
|
150
|
+
response = perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number',
|
151
|
+
'GET', param, true)
|
152
|
+
meta = response['meta']
|
153
|
+
return meta['total_count']
|
154
|
+
end
|
155
|
+
|
156
|
+
def find_number(number, options = nil)
|
157
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
158
|
+
if options.nil?
|
159
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
|
160
|
+
'GET')
|
161
|
+
end
|
162
|
+
params = {}
|
163
|
+
if options.key?(:service) &&
|
164
|
+
valid_param?(:service, options[:service], String, true)
|
165
|
+
params[:service] = options[:service]
|
166
|
+
end
|
167
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
|
168
|
+
'GET', params)
|
169
|
+
end
|
170
|
+
|
171
|
+
def add_number(number, options = nil)
|
172
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
173
|
+
if options.nil?
|
174
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
|
175
|
+
'POST')
|
176
|
+
return
|
177
|
+
end
|
178
|
+
params = {}
|
179
|
+
if options.key?(:service) &&
|
180
|
+
valid_param?(:service, options[:service], String, true)
|
181
|
+
params[:service] = options[:service]
|
182
|
+
end
|
183
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
|
184
|
+
'POST', params)
|
185
|
+
end
|
186
|
+
|
187
|
+
def add_tollfree(tollfree)
|
188
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
189
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + tollfree.to_s ,
|
190
|
+
'POST')
|
191
|
+
end
|
192
|
+
|
193
|
+
def remove_number(number, unrent= false)
|
194
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
195
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + number.to_s ,
|
196
|
+
'DELETE', { unrent: unrent }, false)
|
197
|
+
end
|
198
|
+
|
199
|
+
def remove_tollfree(number, unrent= false)
|
200
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
201
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + number.to_s ,
|
202
|
+
'DELETE', { unrent: unrent }, false)
|
203
|
+
end
|
204
|
+
|
205
|
+
def remove_shortcode(number)
|
206
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
207
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode/' + number.to_s ,
|
208
|
+
'DELETE', { unrent: false }, false)
|
209
|
+
end
|
210
|
+
|
211
|
+
def list_shortcodes(options = nil)
|
212
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
213
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode',
|
214
|
+
'GET') if options.nil?
|
215
|
+
params = {}
|
216
|
+
%i[offset limit].each do |param|
|
217
|
+
if options.key?(param) && valid_param?(param, options[param],
|
218
|
+
[Integer, Integer], true)
|
219
|
+
params[param] = options[param]
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
224
|
+
raise_invalid_request('The maximum number of results that can be '\
|
225
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
226
|
+
end
|
227
|
+
|
228
|
+
if options.key?(:offset) && options[:offset] < 0
|
229
|
+
raise_invalid_request("Offset can't be negative")
|
230
|
+
end
|
231
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode',
|
232
|
+
'GET', params)
|
233
|
+
end
|
234
|
+
|
235
|
+
def list_tollfree(options = nil)
|
236
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
237
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree',
|
238
|
+
'GET') if options.nil?
|
239
|
+
params = {}
|
240
|
+
%i[offset limit].each do |param|
|
241
|
+
if options.key?(param) && valid_param?(param, options[param],
|
242
|
+
[Integer, Integer], true)
|
243
|
+
params[param] = options[param]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
248
|
+
raise_invalid_request('The maximum number of results that can be '\
|
249
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
250
|
+
end
|
251
|
+
|
252
|
+
if options.key?(:offset) && options[:offset] < 0
|
253
|
+
raise_invalid_request("Offset can't be negative")
|
254
|
+
end
|
255
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree',
|
256
|
+
'GET', params)
|
257
|
+
end
|
258
|
+
|
259
|
+
def find_shortcode(shortcode)
|
260
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
261
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Shortcode/' + shortcode.to_s ,
|
262
|
+
'GET')
|
263
|
+
end
|
264
|
+
|
265
|
+
def find_tollfree(tollfree)
|
266
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
267
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Tollfree/' + tollfree.to_s ,
|
268
|
+
'GET')
|
269
|
+
end
|
270
|
+
|
271
|
+
def buy_add_number(options = nil)
|
272
|
+
number_pool_uuid = getnumberpool_uuid(uuid)
|
273
|
+
params = {}
|
274
|
+
params[:rent] = true
|
275
|
+
if options.key?(:service) &&
|
276
|
+
valid_param?(:service, options[:service], String, true)
|
277
|
+
params[:service] = options[:service]
|
278
|
+
end
|
279
|
+
if options.key?(:number)
|
280
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + options[:number].to_s ,
|
281
|
+
'POST', params)
|
282
|
+
end
|
283
|
+
if options.key?(:country_iso2).nil?
|
284
|
+
raise_invalid_request('country_iso is cannot be empty')
|
285
|
+
end
|
286
|
+
|
287
|
+
%i[offset limit].each do |param|
|
288
|
+
if options.key?(param) && valid_param?(param, options[param],
|
289
|
+
[Integer, Integer], true)
|
290
|
+
params[param] = options[param]
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
295
|
+
raise_invalid_request('The maximum number of results that can be '\
|
296
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
297
|
+
end
|
298
|
+
|
299
|
+
if options.key?(:offset) && options[:offset] < 0
|
300
|
+
raise_invalid_request("Offset can't be negative")
|
301
|
+
end
|
302
|
+
|
303
|
+
if options.key?(:pattern) &&
|
304
|
+
valid_param?(:pattern, options[:pattern], String, true)
|
305
|
+
params[:starts_with] = options[:pattern]
|
306
|
+
end
|
307
|
+
if options.key?(:country_iso2) &&
|
308
|
+
valid_param?(:country_iso2, options[:country_iso2], String, true)
|
309
|
+
params[:country_iso] = options[:country_iso2]
|
310
|
+
end
|
311
|
+
if options.key?(:type) &&
|
312
|
+
valid_param?(:type, options[:type], String, true)
|
313
|
+
params[:type] = options[:type]
|
314
|
+
end
|
315
|
+
|
316
|
+
response = perform_custom_action_apiresponse('PhoneNumber',
|
317
|
+
'GET', params, true)
|
318
|
+
numbers = response['objects'][0]['number']
|
319
|
+
perform_custom_action_apiresponse('NumberPool/' + number_pool_uuid + '/Number/' + numbers.to_s,
|
320
|
+
'POST', params)
|
321
|
+
end
|
322
|
+
|
323
|
+
def to_s
|
324
|
+
{
|
325
|
+
name: @name,
|
326
|
+
application_type: @application_type,
|
327
|
+
application_id: @application_id,
|
328
|
+
sticky_sender: @sticky_sender,
|
329
|
+
local_connect: @local_connect,
|
330
|
+
uuid: @uuid,
|
331
|
+
number_pool:@number_pool,
|
332
|
+
created_on:@created_on,
|
333
|
+
number_priority:@number_priority
|
334
|
+
}.to_s
|
335
|
+
end
|
336
|
+
end
|
337
|
+
class NumberPool< Base::Resource
|
338
|
+
def initialize(client, options = nil)
|
339
|
+
@_name = 'Numberpool'
|
340
|
+
@_identifier_string = 'number_pool_id'
|
341
|
+
super
|
342
|
+
end
|
343
|
+
|
344
|
+
def numbers
|
345
|
+
options = {'number_pool_id' => @number_pool_id}
|
346
|
+
Numbers.new(@_client, {resource_json:options })
|
347
|
+
end
|
348
|
+
def shortcodes
|
349
|
+
options = {'number_pool_id' => @number_pool_id}
|
350
|
+
Shortcode.new(@_client, {resource_json: options})
|
351
|
+
end
|
352
|
+
def tollfree
|
353
|
+
options = {'number_pool_id' => @number_pool_id}
|
354
|
+
Tollfree.new(@_client, {resource_json: options})
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class Numbers < Base::Resource
|
359
|
+
def initialize(client, options = nil)
|
360
|
+
@_name = 'Numbers'
|
361
|
+
@_identifier_string = 'number_pool_id'
|
362
|
+
super
|
363
|
+
end
|
364
|
+
|
365
|
+
def list(options = nil)
|
366
|
+
return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
|
367
|
+
'GET') if options.nil?
|
368
|
+
|
369
|
+
params = {}
|
370
|
+
%i[offset limit].each do |param|
|
371
|
+
if options.key?(param) && valid_param?(param, options[param],
|
372
|
+
[Integer, Integer], true)
|
373
|
+
params[param] = options[param]
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
378
|
+
raise_invalid_request('The maximum number of results that can be '\
|
379
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
380
|
+
end
|
381
|
+
|
382
|
+
if options.key?(:offset) && options[:offset] < 0
|
383
|
+
raise_invalid_request("Offset can't be negative")
|
384
|
+
end
|
385
|
+
|
386
|
+
if options.key?(:pattern) &&
|
387
|
+
valid_param?(:pattern, options[:pattern], String, true)
|
388
|
+
params[:starts_with] = options[:pattern]
|
389
|
+
end
|
390
|
+
if options.key?(:country_iso2) &&
|
391
|
+
valid_param?(:country_iso2, options[:country_iso2], String, true)
|
392
|
+
params[:country_iso2] = options[:country_iso2]
|
393
|
+
end
|
394
|
+
if options.key?(:type) &&
|
395
|
+
valid_param?(:type, options[:type], String, true)
|
396
|
+
params[:type] = options[:type]
|
397
|
+
end
|
398
|
+
if options.key?(:service) &&
|
399
|
+
valid_param?(:service, options[:service], String, true)
|
400
|
+
params[:service] = options[:service]
|
401
|
+
end
|
402
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
|
403
|
+
'GET', params, true)
|
404
|
+
end
|
405
|
+
def count(options = nil)
|
406
|
+
if options.nil?
|
407
|
+
response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
|
408
|
+
'GET')
|
409
|
+
meta = response['meta']
|
410
|
+
return meta['total_count']
|
411
|
+
end
|
412
|
+
|
413
|
+
params = {}
|
414
|
+
|
415
|
+
%i[offset limit].each do |param|
|
416
|
+
if options.key?(param) && valid_param?(param, options[param],
|
417
|
+
[Integer, Integer], true)
|
418
|
+
params[param] = options[param]
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
423
|
+
raise_invalid_request('The maximum number of results that can be '\
|
424
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
425
|
+
end
|
426
|
+
|
427
|
+
if options.key?(:offset) && options[:offset] < 0
|
428
|
+
raise_invalid_request("Offset can't be negative")
|
429
|
+
end
|
430
|
+
|
431
|
+
if options.key?(:pattern) &&
|
432
|
+
valid_param?(:pattern, options[:pattern], String, true)
|
433
|
+
params[:starts_with] = options[:pattern]
|
434
|
+
end
|
435
|
+
if options.key?(:country_iso2) &&
|
436
|
+
valid_param?(:country_iso2, options[:country_iso2], String, true)
|
437
|
+
params[:country_iso2] = options[:country_iso2]
|
438
|
+
end
|
439
|
+
if options.key?(:type) &&
|
440
|
+
valid_param?(:type, options[:type], String, true)
|
441
|
+
params[:type] = options[:type]
|
442
|
+
end
|
443
|
+
if options.key?(:service) &&
|
444
|
+
valid_param?(:service, options[:service], String, true)
|
445
|
+
params[:service] = options[:service]
|
446
|
+
end
|
447
|
+
response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
|
448
|
+
'GET', params, true)
|
449
|
+
meta = response['meta']
|
450
|
+
return meta['total_count']
|
451
|
+
end
|
452
|
+
|
453
|
+
def find(number, options = nil)
|
454
|
+
if options.nil?
|
455
|
+
return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
|
456
|
+
'GET')
|
457
|
+
end
|
458
|
+
params = {}
|
459
|
+
if options.key?(:service) &&
|
460
|
+
valid_param?(:service, options[:service], String, true)
|
461
|
+
params[:service] = options[:service]
|
462
|
+
end
|
463
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
|
464
|
+
'GET', params)
|
465
|
+
end
|
466
|
+
|
467
|
+
def add(number, options = nil)
|
468
|
+
if options.nil?
|
469
|
+
return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
|
470
|
+
'POST')
|
471
|
+
end
|
472
|
+
params = {}
|
473
|
+
if options.key?(:service) &&
|
474
|
+
valid_param?(:service, options[:service], String, true)
|
475
|
+
params[:service] = options[:service]
|
476
|
+
end
|
477
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
|
478
|
+
'POST', params)
|
479
|
+
end
|
480
|
+
|
481
|
+
def remove(number, unrent= false)
|
482
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
|
483
|
+
'DELETE', { unrent: unrent }, false)
|
484
|
+
end
|
485
|
+
|
486
|
+
def buy_add_number(options = nil)
|
487
|
+
params = {}
|
488
|
+
params[:rent] = true
|
489
|
+
if options.key?(:service) &&
|
490
|
+
valid_param?(:service, options[:service], String, true)
|
491
|
+
params[:service] = options[:service]
|
492
|
+
end
|
493
|
+
if options.key?(:number)
|
494
|
+
return perform_custom_action_apiresponse('NumberPool/' + number_pool_id + '/Number/' + options[:number].to_s ,
|
495
|
+
'POST', params)
|
496
|
+
end
|
497
|
+
if options.key?(:country_iso2).nil?
|
498
|
+
raise_invalid_request('country_iso is cannot be empty')
|
499
|
+
end
|
500
|
+
params = {}
|
501
|
+
|
502
|
+
%i[offset limit].each do |param|
|
503
|
+
if options.key?(param) && valid_param?(param, options[param],
|
504
|
+
[Integer, Integer], true)
|
505
|
+
params[param] = options[param]
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
510
|
+
raise_invalid_request('The maximum number of results that can be '\
|
511
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
512
|
+
end
|
513
|
+
|
514
|
+
if options.key?(:offset) && options[:offset] < 0
|
515
|
+
raise_invalid_request("Offset can't be negative")
|
516
|
+
end
|
517
|
+
|
518
|
+
if options.key?(:pattern) &&
|
519
|
+
valid_param?(:pattern, options[:pattern], String, true)
|
520
|
+
params[:starts_with] = options[:pattern]
|
521
|
+
end
|
522
|
+
if options.key?(:country_iso2) &&
|
523
|
+
valid_param?(:country_iso2, options[:country_iso2], String, true)
|
524
|
+
params[:country_iso] = options[:country_iso2]
|
525
|
+
end
|
526
|
+
if options.key?(:type) &&
|
527
|
+
valid_param?(:type, options[:type], String, true)
|
528
|
+
params[:type] = options[:type]
|
529
|
+
end
|
530
|
+
|
531
|
+
response = perform_custom_action_apiresponse('PhoneNumber',
|
532
|
+
'GET', params, true)
|
533
|
+
numbers = response['objects'][0]['number']
|
534
|
+
params[:rent] = true
|
535
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + numbers.to_s,
|
536
|
+
'POST', params)
|
537
|
+
end
|
538
|
+
|
539
|
+
end
|
540
|
+
|
541
|
+
class Shortcode < Base::Resource
|
542
|
+
def initialize(client, options = nil)
|
543
|
+
@_name = 'Shortcode'
|
544
|
+
@_identifier_string = 'number_pool_id'
|
545
|
+
super
|
546
|
+
end
|
547
|
+
def list(options = nil)
|
548
|
+
return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Shortcode',
|
549
|
+
'GET') if options.nil?
|
550
|
+
params = {}
|
551
|
+
%i[offset limit].each do |param|
|
552
|
+
if options.key?(param) && valid_param?(param, options[param],
|
553
|
+
[Integer, Integer], true)
|
554
|
+
params[param] = options[param]
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
559
|
+
raise_invalid_request('The maximum number of results that can be '\
|
560
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
561
|
+
end
|
562
|
+
|
563
|
+
if options.key?(:offset) && options[:offset] < 0
|
564
|
+
raise_invalid_request("Offset can't be negative")
|
565
|
+
end
|
566
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Shortcode',
|
567
|
+
'GET')
|
568
|
+
end
|
569
|
+
|
570
|
+
def find(shortcode)
|
571
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Shortcode/' + shortcode.to_s ,
|
572
|
+
'GET')
|
573
|
+
end
|
574
|
+
|
575
|
+
def remove(shortcode)
|
576
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Shortcode/' + shortcode.to_s ,
|
577
|
+
'DELETE', { unrent: false }, false)
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
class Tollfree < Base::Resource
|
582
|
+
def initialize(client, options = nil)
|
583
|
+
@_name = 'Tollfree'
|
584
|
+
@_identifier_string = 'number_pool_id'
|
585
|
+
super
|
586
|
+
end
|
587
|
+
|
588
|
+
def add(tollfree)
|
589
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree/' + tollfree.to_s ,
|
590
|
+
'POST')
|
591
|
+
end
|
592
|
+
|
593
|
+
def list(options = nil)
|
594
|
+
return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree',
|
595
|
+
'GET') if options.nil?
|
596
|
+
params = {}
|
597
|
+
%i[offset limit].each do |param|
|
598
|
+
if options.key?(param) && valid_param?(param, options[param],
|
599
|
+
[Integer, Integer], true)
|
600
|
+
params[param] = options[param]
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
605
|
+
raise_invalid_request('The maximum number of results that can be '\
|
606
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
607
|
+
end
|
608
|
+
|
609
|
+
if options.key?(:offset) && options[:offset] < 0
|
610
|
+
raise_invalid_request("Offset can't be negative")
|
611
|
+
end
|
612
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree',
|
613
|
+
'GET')
|
614
|
+
end
|
615
|
+
|
616
|
+
def find(tollfree)
|
617
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree/' + tollfree.to_s ,
|
618
|
+
'GET')
|
619
|
+
end
|
620
|
+
|
621
|
+
def remove(tollfree, unrent= false)
|
622
|
+
perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Tollfree/' + tollfree.to_s ,
|
623
|
+
'DELETE', { unrent: unrent }, false)
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
class PowerpackInterface < Base::ResourceInterface
|
628
|
+
def initialize(client, resource_list_json = nil)
|
629
|
+
@_name = 'Powerpack'
|
630
|
+
@_resource_type = Powerpack
|
631
|
+
@_identifier_string = 'powerpack'
|
632
|
+
super
|
633
|
+
end
|
634
|
+
|
635
|
+
def create(name, options = nil)
|
636
|
+
valid_param?(:name, name, [String, Symbol], true)
|
637
|
+
|
638
|
+
if name.nil?
|
639
|
+
raise InvalidRequestError, 'powerpack name cannot be empty'
|
640
|
+
end
|
641
|
+
|
642
|
+
|
643
|
+
params = {
|
644
|
+
name: name
|
645
|
+
}
|
646
|
+
|
647
|
+
return perform_create(params) if options.nil?
|
648
|
+
valid_param?(:options, options, Hash, true)
|
649
|
+
|
650
|
+
if options.key?(:application_type) &&
|
651
|
+
valid_param?(:application_type, options[:application_type], String, true)
|
652
|
+
params[:application_type] = options[:application_type]
|
653
|
+
end
|
654
|
+
|
655
|
+
if options.key?(:application_id) &&
|
656
|
+
valid_param?(:application_id, options[:application_id], String, true)
|
657
|
+
params[:application_id] = options[:application_id]
|
658
|
+
end
|
659
|
+
|
660
|
+
if options.key?(:sticky_sender) &&
|
661
|
+
valid_param?(:sticky_sender, options[:sticky_sender], [TrueClass, FalseClass], true)
|
662
|
+
params[:sticky_sender] = options[:sticky_sender]
|
663
|
+
end
|
664
|
+
|
665
|
+
if options.key?(:local_connect) &&
|
666
|
+
valid_param?(:local_connect, options[:local_connect], [TrueClass, FalseClass], true)
|
667
|
+
params[:local_connect] = options[:local_connect]
|
668
|
+
end
|
669
|
+
|
670
|
+
if options.key?(:number_priority) &&
|
671
|
+
valid_param?(:number_priority, options[:number_priority], Array, true)
|
672
|
+
params[:number_priority] = options[:number_priority]
|
673
|
+
end
|
674
|
+
|
675
|
+
perform_create(params)
|
676
|
+
end
|
677
|
+
|
678
|
+
def get(uuid)
|
679
|
+
valid_param?(:uuid, uuid, [String, Symbol], true)
|
680
|
+
perform_get(uuid)
|
681
|
+
end
|
682
|
+
|
683
|
+
def list(options = nil)
|
684
|
+
return perform_list if options.nil?
|
685
|
+
params = {}
|
686
|
+
%i[offset limit].each do |param|
|
687
|
+
if options.key?(param) && valid_param?(param, options[param],
|
688
|
+
[Integer, Integer], true)
|
689
|
+
params[param] = options[param]
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
694
|
+
raise_invalid_request('The maximum number of results that can be '\
|
695
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
696
|
+
end
|
697
|
+
|
698
|
+
if options.key?(:offset) && options[:offset] < 0
|
699
|
+
raise_invalid_request("Offset can't be negative")
|
700
|
+
end
|
701
|
+
perform_list(params)
|
702
|
+
end
|
703
|
+
|
704
|
+
def each
|
705
|
+
offset = 0
|
706
|
+
loop do
|
707
|
+
powerpack_list = list(offset: offset)
|
708
|
+
powerpack_list[:objects].each { |message| yield message }
|
709
|
+
offset += 20
|
710
|
+
return unless powerpack_list.length == 20
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
end
|