Class: Zm::Client::Base::AccountSearchObjectsCollection

Inherits:
AccountObjectsCollection show all
Defined in:
lib/zm/client/base/account_search_objects_collection.rb

Overview

Collection AccountSearchObjectsCollection

Constant Summary

Constants inherited from ObjectsCollection

ObjectsCollection::METHODS_MISSING_LIST

Instance Attribute Summary collapse

Attributes inherited from ObjectsCollection

#parent

Instance Method Summary collapse

Methods inherited from ObjectsCollection

#all, #first, #logger, #method_missing, #new, #page, #per_page, #respond_to_missing?

Methods included from Inspector

#inspect, #instance_variables_map, #to_h, #to_s

Constructor Details

#initialize(parent) ⇒ AccountSearchObjectsCollection

Returns a new instance of AccountSearchObjectsCollection.



10
11
12
13
14
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 10

def initialize(parent)
  super
  @more = true
  reset_query_params
end

Dynamic Method Handling

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

Instance Attribute Details

#moreObject

Returns the value of attribute more.



8
9
10
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 8

def more
  @more
end

Instance Method Details

#build_find(id) ⇒ Object



23
24
25
26
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 23

def build_find(id)
  SoapElement.mail(SoapMailConstants::GET_MSG_REQUEST)
             .add_attributes({ m: { id: id, html: SoapUtils::ON } })
end

#build_queryObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 89

def build_query
  jsns = {
    types: @type,
    offset: @offset,
    limit: @limit,
    sortBy: @sort_by,
    query: query,
    header: @headers
  }

  jsns.merge!(build_options)

  jsns.compact!

  SoapElement.mail(SoapMailConstants::SEARCH_REQUEST)
             .add_attributes(jsns)
end

#delete_all(ids) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 107

def delete_all(ids)
  attrs = {
    op: :delete,
    id: ids.join(',')
  }

  attrs.compact!

  soap_request = SoapElement.mail(SoapMailConstants::ITEM_ACTION_REQUEST)
  node_action = SoapElement.create(SoapConstants::ACTION).add_attributes(attrs)
  soap_request.add_node(node_action)
  @parent.soap_connector.invoke(soap_request)
end

#end_at(end_at) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 37

def end_at(end_at)
  @end_at = if end_at.is_a?(Time)
              end_at.to_i * 1000
            elsif end_at.is_a?(Date)
              end_at.to_time.to_i * 1000
            end
  self
end

#find(id) ⇒ Object



16
17
18
19
20
21
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 16

def find(id)
  rep = @parent.soap_connector.invoke(build_find(id))
  entry = rep[:GetMsgResponse][:m].first

  MessageJsnsInitializer.create(@parent, entry)
end

#folder_ids(*folder_ids) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 55

def folder_ids(*folder_ids)
  folder_ids.flatten!
  folder_ids.uniq!
  return self if @folder_ids == folder_ids

  @folder_ids = folder_ids
  self
end

#folders(*folders) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 46

def folders(*folders)
  folders.flatten!
  folders.select! { |folder| folder.is_a?(Zm::Client::Folder) }
  return self if folders.empty?

  @folders = folders
  folder_ids(*@folders.map(&:id))
end

#idsObject



76
77
78
79
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 76

def ids
  @resultMode = 'IDS'
  search_builder.ids
end

#make_queryObject



85
86
87
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 85

def make_query
  @parent.soap_connector.invoke(build_query)
end

#order(sort_by) ⇒ Object



69
70
71
72
73
74
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 69

def order(sort_by)
  return self if @sort_by == sort_by

  @sort_by = sort_by
  self
end

#resetObject



81
82
83
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 81

def reset
  reset_query_params
end

#start_at(start_at) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 28

def start_at(start_at)
  @start_at = if start_at.is_a?(Time)
                start_at.to_i * 1000
              elsif start_at.is_a?(Date)
                start_at.to_time.to_i * 1000
              end
  self
end

#where(query) ⇒ Object



64
65
66
67
# File 'lib/zm/client/base/account_search_objects_collection.rb', line 64

def where(query)
  @query = query
  self
end