Class: Plivo::Resources::PowerpackInterface

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

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

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, resource_list_json = nil) ⇒ PowerpackInterface

Returns a new instance of PowerpackInterface.



461
462
463
464
465
466
# File 'lib/plivo/resources/powerpacks.rb', line 461

def initialize(client, resource_list_json = nil)
  @_name = 'Powerpack'
  @_resource_type = Powerpack
  @_identifier_string = 'powerpack'
  super
end

Instance Method Details

#create(name, options = nil) ⇒ Object



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/plivo/resources/powerpacks.rb', line 468

def create(name, options = nil)
  valid_param?(:name, name, [String, Symbol], true)
  
  if name.nil? 
    raise InvalidRequestError, 'powerpack name cannot be empty'
  end
  
  
  params = {
    name: name
  }
  
  return perform_create(params) if options.nil?
  valid_param?(:options, options, Hash, true)
  
  if options.key?(:application_type) &&
     valid_param?(:application_type, options[:application_type], String, true)
    params[:application_type] = options[:application_type]
  end
  
  if options.key?(:application_id) &&
    valid_param?(:application_id, options[:application_id], String, true)
   params[:application_id] = options[:application_id]
 end
  
  if options.key?(:sticky_sender) &&
     valid_param?(:sticky_sender, options[:sticky_sender], [TrueClass, FalseClass], true)
    params[:sticky_sender] = options[:sticky_sender]
  end

  if options.key?(:local_connect) &&
    valid_param?(:local_connect, options[:local_connect], [TrueClass, FalseClass], true)
   params[:local_connect] = options[:local_connect]
 end
  perform_create(params)
end

#eachObject



531
532
533
534
535
536
537
538
539
# File 'lib/plivo/resources/powerpacks.rb', line 531

def each
  offset = 0
  loop do
    powerpack_list = list(offset: offset)
    powerpack_list[:objects].each { |message| yield message }
    offset += 20
    return unless powerpack_list.length == 20
  end
end

#get(uuid) ⇒ Object



505
506
507
508
# File 'lib/plivo/resources/powerpacks.rb', line 505

def get(uuid)
  valid_param?(:uuid, uuid, [String, Symbol], true)
  perform_get(uuid)
end

#list(options = nil) ⇒ Object



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/plivo/resources/powerpacks.rb', line 510

def list(options = nil)
  return perform_list 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
  perform_list(params)
end