Class: Zm::Client::AccountsCollection

Inherits:
Base::AdminObjectsCollection show all
Defined in:
lib/zm/client/account/accounts_collection.rb

Overview

Collection Accounts

Constant Summary

Constants inherited from Base::ObjectsCollection

Base::ObjectsCollection::METHODS_MISSING_LIST

Instance Attribute Summary

Attributes inherited from Base::ObjectsCollection

#parent

Instance Method Summary collapse

Methods inherited from Base::AdminObjectsCollection

#attrs, #clear, #count, #find_by, #find_by_or_nil, #find_each, #ldap, #where

Methods inherited from Base::ObjectsCollection

#all, #all!, #find, #first, #logger, #method_missing, #new, #order, #page, #per_page, #respond_to_missing?

Methods included from Inspector

#inspect, #instance_variables_map, #to_h, #to_s

Constructor Details

#initialize(parent) ⇒ AccountsCollection

Returns a new instance of AccountsCollection.



7
8
9
10
11
12
# File 'lib/zm/client/account/accounts_collection.rb', line 7

def initialize(parent)
  @child_class = Account
  @builder_class = AccountsBuilder
  @search_type = SearchType::ACCOUNT
  super(parent)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zm::Client::Base::ObjectsCollection

Instance Method Details

#find_by!(hash) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/zm/client/account/accounts_collection.rb', line 14

def find_by!(hash)
  soap_request = SoapElement.admin(SoapAdminConstants::GET_ACCOUNT_REQUEST)
   = SoapElement.create(SoapConstants::ACCOUNT).add_attribute(SoapConstants::BY, hash.keys.first).add_content(hash.values.first)
  soap_request.add_node()
  soap_request.add_attribute(SoapConstants::ATTRS, attrs_comma)
  soap_request.add_attribute(SoapConstants::APPLY_COS, @apply_cos)
  entry = sac.invoke(soap_request)[:GetAccountResponse][:account].first

  reset_query_params
  AccountJsnsInitializer.create(@parent, entry)
end

#quotas(domain_name: @domain_name, target_server_id: @target_server_id) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zm/client/account/accounts_collection.rb', line 26

def quotas(domain_name: @domain_name, target_server_id: @target_server_id)
  return nil if domain_name.nil? && target_server_id.nil?

  if target_server_id.nil?
    @all_servers = SoapUtils::ON
  else
    sac.context.target_server(target_server_id)
  end

  jsns = {
    domain: domain_name,
    allServers: @all_servers,
    limit: @limit,
    offset: @offset,
    sortBy: @sort_by,
    sortAscending: @sort_ascending,
    refresh: @refresh
  }.delete_if { |_, value| value.nil? }

  soap_request = SoapElement.admin(SoapAdminConstants::GET_QUOTA_USAGE_REQUEST)
  soap_request.add_attributes(jsns)
  json = sac.invoke(soap_request)

  sac.context.target_server(nil) unless target_server_id.nil?

  reset_query_params
  @builder_class.new(@parent, json).make
end