Class: Plivo::Resources::Numbers

Inherits:
Base::Resource show all
Defined in:
lib/plivo/resources/powerpacks.rb

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

Instance Attribute Summary

Attributes inherited from Base::Resource

#id

Instance Method Summary collapse

Methods included from Utils

expected_type?, expected_value?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_subaccount?

Constructor Details

#initialize(client, options = nil) ⇒ Numbers

Returns a new instance of Numbers.



273
274
275
276
277
# File 'lib/plivo/resources/powerpacks.rb', line 273

def initialize(client, options = nil)
  @_name = 'Numbers'
  @_identifier_string = 'number_pool_id'
  super
end

Instance Method Details

#add(number) ⇒ Object



364
365
366
367
# File 'lib/plivo/resources/powerpacks.rb', line 364

def add(number)
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
               'POST')
end

#buy_add_number(options = nil) ⇒ Object



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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/plivo/resources/powerpacks.rb', line 374

def buy_add_number(options = nil)
  params = {}
  params[:rent] = true
  if options.key?(:number)
    return perform_custom_action_apiresponse('NumberPool/' + number_pool_id + '/Number/' + options[:number].to_s ,
               'POST', params)
  end
  if options.key?(:country_iso2).nil?
    raise_invalid_request('country_iso is cannot be empty')
  end
  params = {}
  
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  if options.key?(:pattern) &&
    valid_param?(:pattern, options[:pattern], String, true)
   params[:starts_with] = options[:pattern]
  end
  if options.key?(:country_iso2) &&
    valid_param?(:country_iso2, options[:country_iso2], String, true)
   params[:country_iso] = options[:country_iso2]
  end
  if options.key?(:type) &&
    valid_param?(:type, options[:type], String, true)
   params[:type] = options[:type]
  end

 response = perform_custom_action_apiresponse('PhoneNumber',
 'GET', params, true)
  numbers = response['objects'][0]['number']
  params[:rent] = true
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + numbers.to_s,
               'POST', params)
end

#count(options = nil) ⇒ Object



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
# File 'lib/plivo/resources/powerpacks.rb', line 315

def count(options = nil)
  if options.nil?
   response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
   'GET')
   meta = response['meta']
   return meta['total_count']
  end
 
  params = {}
  
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  if options.key?(:pattern) &&
    valid_param?(:pattern, options[:pattern], String, true)
   params[:starts_with] = options[:pattern]
  end
  if options.key?(:country_iso2) &&
    valid_param?(:country_iso2, options[:country_iso2], String, true)
   params[:country_iso2] = options[:country_iso2]
  end
  if options.key?(:type) &&
    valid_param?(:type, options[:type], String, true)
   params[:type] = options[:type]
  end
  response = perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
  'GET', params, true)
  meta = response['meta']
  return meta['total_count']
end

#find(number) ⇒ Object



359
360
361
362
# File 'lib/plivo/resources/powerpacks.rb', line 359

def find(number)
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
               'GET')
end

#list(options = nil) ⇒ Object



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
# File 'lib/plivo/resources/powerpacks.rb', line 279

def list(options = nil)
  return perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
  'GET') if options.nil?

  params = {}
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  if options.key?(:pattern) &&
    valid_param?(:pattern, options[:pattern], String, true)
   params[:starts_with] = options[:pattern]
  end
  if options.key?(:country_iso2) &&
    valid_param?(:country_iso2, options[:country_iso2], String, true)
   params[:country_iso2] = options[:country_iso2]
  end
  if options.key?(:type) &&
    valid_param?(:type, options[:type], String, true)
   params[:type] = options[:type]
  end
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number',
  'GET', params, true)
end

#remove(number, unrent = false) ⇒ Object



369
370
371
372
# File 'lib/plivo/resources/powerpacks.rb', line 369

def remove(number, unrent= false)
  perform_custom_action_apiresponse('NumberPool/' + @number_pool_id + '/Number/' + number.to_s ,
               'DELETE', { unrent: unrent }, false)
end