class Plivo::Resources::SubaccountInterface

@!method get @!method create @!method list

Public Class Methods

new(client, resource_list_json = nil) click to toggle source
Calls superclass method Plivo::Base::ResourceInterface::new
# File lib/plivo/resources/accounts.rb, line 54
def initialize(client, resource_list_json = nil)
  @_name = 'Subaccount'
  @_resource_type = Subaccount
  @_identifier_string = 'auth_id'
  super
end

Public Instance Methods

create(name, enabled = false) click to toggle source

@param [String] name @param [Boolean] enabled

# File lib/plivo/resources/accounts.rb, line 69
def create(name, enabled = false)
  valid_param?(:name, name, [String, Symbol], true)
  valid_param?(:enabled, enabled, [TrueClass, FalseClass],
               true, [true, false])

  params = {
    name: name,
    enabled: enabled
  }

  perform_create(params)
end
delete(subaccount_id, cascade = false) click to toggle source
# File lib/plivo/resources/accounts.rb, line 119
def delete(subaccount_id, cascade = false)
  valid_subaccount?(subaccount_id, true)
  Subaccount.new(@_client, resource_id: subaccount_id).delete(cascade)
end
each() { |subaccount| ... } click to toggle source
# File lib/plivo/resources/accounts.rb, line 105
def each
  offset = 0
  loop do
    subaccount_list = list(offset: offset)
    subaccount_list[:objects].each { |subaccount| yield subaccount }
    offset += 20
    return unless subaccount_list.length == 20
  end
end
get(subaccount_id) click to toggle source

@param [String] subaccount_id

# File lib/plivo/resources/accounts.rb, line 62
def get(subaccount_id)
  valid_subaccount?(subaccount_id, true)
  perform_get(subaccount_id)
end
list(options = nil) click to toggle source

@param [Array] options

# File lib/plivo/resources/accounts.rb, line 83
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

  raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0

  perform_list(params)
end
update(subaccount_id, name, enabled = false) click to toggle source
# File lib/plivo/resources/accounts.rb, line 115
def update(subaccount_id, name, enabled = false)
  Subaccount.new(@_client, resource_id: subaccount_id).update(name, enabled)
end