Class: Plivo::Resources::SubaccountInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::SubaccountInterface
- Defined in:
- lib/plivo/resources/accounts.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
- #create(name, enabled = false) ⇒ Object
- #delete(subaccount_id, cascade = false) ⇒ 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
GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_signatureV3?, valid_subaccount?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ SubaccountInterface
Returns a new instance of SubaccountInterface.
54 55 56 57 58 59 |
# 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 |
Instance Method Details
#create(name, enabled = false) ⇒ Object
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 117 118 119 120 121 122 123 |
# File 'lib/plivo/resources/accounts.rb', line 53 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, cascade = false) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete(cascade) end end |
#delete(subaccount_id, cascade = false) ⇒ Object
119 120 121 122 |
# 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 ⇒ Object
105 106 107 108 109 110 111 112 113 |
# 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) ⇒ Object
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 117 118 119 120 121 122 123 |
# File 'lib/plivo/resources/accounts.rb', line 53 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, cascade = false) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete(cascade) end end |
#list(options = nil) ⇒ Object
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 117 118 119 120 121 122 123 |
# File 'lib/plivo/resources/accounts.rb', line 53 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, cascade = false) valid_subaccount?(subaccount_id, true) Subaccount.new(@_client, resource_id: subaccount_id).delete(cascade) end end |
#update(subaccount_id, name, enabled = false) ⇒ Object
115 116 117 |
# 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 |