Class: Plivo::Resources::PowerpackInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::PowerpackInterface
- Defined in:
- lib/plivo/resources/powerpacks.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
- #create(name, options = nil) ⇒ Object
- #each ⇒ Object
- #get(uuid) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ PowerpackInterface
constructor
A new instance of PowerpackInterface.
- #list(options = nil) ⇒ Object
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, = 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 .nil? valid_param?(:options, , Hash, true) if .key?(:application_type) && valid_param?(:application_type, [:application_type], String, true) params[:application_type] = [:application_type] end if .key?(:application_id) && valid_param?(:application_id, [:application_id], String, true) params[:application_id] = [:application_id] end if .key?(:sticky_sender) && valid_param?(:sticky_sender, [:sticky_sender], [TrueClass, FalseClass], true) params[:sticky_sender] = [:sticky_sender] end if .key?(:local_connect) && valid_param?(:local_connect, [:local_connect], [TrueClass, FalseClass], true) params[:local_connect] = [:local_connect] end perform_create(params) end |
#each ⇒ Object
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 { || yield } 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( = nil) return perform_list if .nil? params = {} %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer, Integer], true) params[param] = [param] end end if .key?(:limit) && ([:limit] > 20 || [: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 .key?(:offset) && [:offset] < 0 raise_invalid_request("Offset can't be negative") end perform_list(params) end |