Class: Plivo::Resources::SubaccountInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::SubaccountInterface
- Defined in:
- lib/plivo/resources/accounts.rb
Instance Method Summary collapse
- #create(name, enabled = false) ⇒ Object
- #delete(subaccount_id) ⇒ Object
- #each ⇒ Object
- #get(subaccount_id) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ SubaccountInterface
constructor
A new instance of SubaccountInterface.
- #list(options = nil) ⇒ Object
- #update(subaccount_id, name, enabled = false) ⇒ 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) ⇒ SubaccountInterface
Returns a new instance of SubaccountInterface.
47 48 49 50 51 52 |
# File 'lib/plivo/resources/accounts.rb', line 47 def initialize(client, resource_list_json = nil) @_name = 'Subaccount' @_resource_type = Subaccount @_identifier_string = 'auth_id' super end |
Instance Method Details
#create(name, enabled = false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/plivo/resources/accounts.rb', line 46 class SubaccountInterface < Base::ResourceInterface def initialize(client, resource_list_json = nil) @_name = 'Subaccount' @_resource_type = Subaccount @_identifier_string = 'auth_id' super end # @param [String] subaccount_id def get(subaccount_id) valid_subaccount?(subaccount_id, true) perform_get(subaccount_id) end # @param [String] name # @param [Boolean] enabled 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 # @param [Array] options 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 raise_invalid_request("Offset can't be negative") if .key?(:offset) && [:offset] < 0 perform_list(params) end 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 def update(subaccount_id, name, enabled = false) Subaccount.new(@_client, resource_id: subaccount_id).update(name, enabled) end def delete(subaccount_id) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete end end |
#delete(subaccount_id) ⇒ Object
112 113 114 115 |
# File 'lib/plivo/resources/accounts.rb', line 112 def delete(subaccount_id) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete end |
#each ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/plivo/resources/accounts.rb', line 98 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) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/plivo/resources/accounts.rb', line 46 class SubaccountInterface < Base::ResourceInterface def initialize(client, resource_list_json = nil) @_name = 'Subaccount' @_resource_type = Subaccount @_identifier_string = 'auth_id' super end # @param [String] subaccount_id def get(subaccount_id) valid_subaccount?(subaccount_id, true) perform_get(subaccount_id) end # @param [String] name # @param [Boolean] enabled 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 # @param [Array] options 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 raise_invalid_request("Offset can't be negative") if .key?(:offset) && [:offset] < 0 perform_list(params) end 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 def update(subaccount_id, name, enabled = false) Subaccount.new(@_client, resource_id: subaccount_id).update(name, enabled) end def delete(subaccount_id) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete end end |
#list(options = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/plivo/resources/accounts.rb', line 46 class SubaccountInterface < Base::ResourceInterface def initialize(client, resource_list_json = nil) @_name = 'Subaccount' @_resource_type = Subaccount @_identifier_string = 'auth_id' super end # @param [String] subaccount_id def get(subaccount_id) valid_subaccount?(subaccount_id, true) perform_get(subaccount_id) end # @param [String] name # @param [Boolean] enabled 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 # @param [Array] options 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 raise_invalid_request("Offset can't be negative") if .key?(:offset) && [:offset] < 0 perform_list(params) end 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 def update(subaccount_id, name, enabled = false) Subaccount.new(@_client, resource_id: subaccount_id).update(name, enabled) end def delete(subaccount_id) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete end end |
#update(subaccount_id, name, enabled = false) ⇒ Object
108 109 110 |
# File 'lib/plivo/resources/accounts.rb', line 108 def update(subaccount_id, name, enabled = false) Subaccount.new(@_client, resource_id: subaccount_id).update(name, enabled) end |