Class: Zm::Client::Folder

Inherits:
Base::AccountObject show all
Defined in:
lib/zm/client/folder/folder.rb

Overview

class for account folder

Constant Summary collapse

INSTANCE_VARIABLE_KEYS =
%i[type id uuid name absFolderPath l url luuid f
view rev ms webOfflineSyncDays activesyncdisabled n s i4ms i4next zid rid
ruuid owner reminder acl itemCount broken deletable color rgb fb]

Instance Attribute Summary collapse

Attributes inherited from Base::Object

#grantee_type, #id, #name, #parent, #token

Instance Method Summary collapse

Methods inherited from Base::AccountObject

#soap_account_connector

Methods inherited from Base::Object

#arrow_name, #clone, #convert_json_string_value, #instance_variables_array, #instance_variables_hash, #recorded?, #save!, #to_s

Constructor Details

#initialize(parent, json = nil, key = :folder) {|_self| ... } ⇒ Folder

Returns a new instance of Folder.

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
28
29
30
31
32
33
# File 'lib/zm/client/folder/folder.rb', line 24

def initialize(parent, json = nil, key = :folder)
  @parent = parent
  @type = key
  @folders = []
  @grants = []
  @retention_policies = []
  init_from_json(json) if json.is_a?(Hash)
  yield(self) if block_given?
  extend(DocumentFolder) if view == 'document'
end

Instance Attribute Details

#foldersObject

Returns the value of attribute folders.



13
14
15
# File 'lib/zm/client/folder/folder.rb', line 13

def folders
  @folders
end

#grantsObject

Returns the value of attribute grants.



13
14
15
# File 'lib/zm/client/folder/folder.rb', line 13

def grants
  @grants
end

#retention_policiesObject

Returns the value of attribute retention_policies.



13
14
15
# File 'lib/zm/client/folder/folder.rb', line 13

def retention_policies
  @retention_policies
end

Instance Method Details

#add_retention_policy!(retention_policies) ⇒ Object



85
86
87
88
# File 'lib/zm/client/folder/folder.rb', line 85

def add_retention_policy!(retention_policies)
  options = retention_policies.is_a?(Hash) ? retention_policies : retention_policies.map(&:to_h).reduce({}, :merge)
  @parent.sacc.folder_action(@parent.token, 'retentionPolicy', @id, retentionPolicy: options)
end

#color!(new_color) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/zm/client/folder/folder.rb', line 95

def color!(new_color)
  key = new_color.to_i.zero? ? :rgb : :color
  options = {}
  options[key] = new_color
  @parent.sacc.folder_action(@parent.token, 'color', @id, options)
  instance_variable_set("@#{key}", new_color)
end

#concatObject



15
16
17
# File 'lib/zm/client/folder/folder.rb', line 15

def concat
  INSTANCE_VARIABLE_KEYS.map { |key| instance_variable_get(arrow_name(key)) }
end

#create!Object



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

def create!
  options = to_h
  options.delete_if { |_, v| v.nil? }
  rep = @parent.sacc.create_folder(@parent.token, options)
  # rep = @parent.sacc.create_folder(@parent.token, @l, @name, @view, @color)
  init_from_json(rep[:Body][:CreateFolderResponse][:folder].first)
end

#delete!Object



122
123
124
# File 'lib/zm/client/folder/folder.rb', line 122

def delete!
  @parent.sacc.folder_action(@parent.token, :delete, @id)
end

#download(dest_file_path, fmt = 'tgz') ⇒ Object



176
177
178
179
180
# File 'lib/zm/client/folder/folder.rb', line 176

def download(dest_file_path, fmt = 'tgz')
  uploader = Upload.new(@parent, RestAccountConnector.new)
  # uploader.download_file(absFolderPath, fmt, [view], nil, dest_file_path)
  uploader.download_folder(@id, fmt, dest_file_path)
end

#empty!Object Also known as: clear



112
113
114
115
116
117
118
119
# File 'lib/zm/client/folder/folder.rb', line 112

def empty!
  @parent.sacc.folder_action(
    @parent.token,
    :empty,
    @id,
    recursive: false
  )
end

#empty?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/zm/client/folder/folder.rb', line 108

def empty?
  @n.zero?
end

#export(dest_file_path) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/zm/client/folder/folder.rb', line 182

def export(dest_file_path)
  h = {
    fmt: 'tgz',
    emptyname: 'Vide',
    charset: 'UTF-8',
    auth: 'qp',
    zauthtoken: @parent.token,
    query: to_query
  }

  url_query = absFolderPath + '?' + h.map { |k, v| [k, v].join('=') }.join('&')

  @parent.uploader.download_file_with_url(url_query, dest_file_path)
end

#grant!(folder_grant) ⇒ Object

folder_grant: Zm::Client::FolderGrant



129
130
131
132
133
134
135
136
# File 'lib/zm/client/folder/folder.rb', line 129

def grant!(folder_grant)
  @parent.sacc.folder_action(
      @parent.token,
      'grant',
      @id,
      grant: folder_grant.to_h
  )
end

#import(file_path) ⇒ Object



171
172
173
174
# File 'lib/zm/client/folder/folder.rb', line 171

def import(file_path)
  uploader = Upload.new(@parent, RestAccountConnector.new)
  uploader.send_file(absFolderPath, 'tgz', nil, 'skip', file_path)
end

#init_from_json(json) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/zm/client/folder/folder.rb', line 197

def init_from_json(json)
  INSTANCE_VARIABLE_KEYS.each do |key|
    var_name = "@#{key}"
    instance_variable_set(var_name, json[key])
  end

  if !json[:acl].nil? && json[:acl][:grant].is_a?(Array)
    @grants = json[:acl][:grant].map { |grant| FolderGrant.create_by_json(self, grant) }
  end

  if json[:retentionPolicy].is_a?(Array)
    @retention_policies = json[:retentionPolicy].first.map do |k, v|
      FolderRetentionPolicy.create_by_json(self, k, v.first)
    end
  end
end

#is_immutable?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/zm/client/folder/folder.rb', line 35

def is_immutable?
  @is_immutable ||= Zm::Client::FolderDefault::IDS.include?(@id.to_i)
end

#modify!Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/zm/client/folder/folder.rb', line 64

def modify!
  options = to_h
  options.delete_if { |_, v| v.nil? }

  if is_immutable?
    options.delete(:name)
    options.delete(:l)
  end

  update!(options)
end

#move!(folder_id) ⇒ Object



90
91
92
93
# File 'lib/zm/client/folder/folder.rb', line 90

def move!(folder_id)
  @parent.sacc.folder_action(@parent.token, 'move', @id, l: folder_id)
  @l = folder_id
end

#reload!Object



103
104
105
106
# File 'lib/zm/client/folder/folder.rb', line 103

def reload!
  rep = @parent.sacc.get_folder(@parent.token, @id)
  init_from_json(rep[:Body][:GetFolderResponse][:folder].first)
end

#remove_grant!(zid) ⇒ Object

def grant!(parent, right)

@parent.sacc.folder_action(
  @parent.token,
  'grant',
  @id,
  grant: {
    zid: parent.id,
    gt: parent.grantee_type,
    perm: right
  }
)

end



151
152
153
154
155
156
157
158
# File 'lib/zm/client/folder/folder.rb', line 151

def remove_grant!(zid)
  @parent.sacc.folder_action(
    @parent.token,
    '!grant',
    @id,
    zid: zid
  )
end

#rename!(new_name) ⇒ Object



80
81
82
83
# File 'lib/zm/client/folder/folder.rb', line 80

def rename!(new_name)
  @parent.sacc.folder_action(@parent.token, 'rename', @id, name: new_name)
  @name = new_name
end

#retention_policies_hObject



160
161
162
# File 'lib/zm/client/folder/folder.rb', line 160

def retention_policies_h
  @retention_policies.map(&:to_h).reduce({}, :merge)
end

#to_hObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zm/client/folder/folder.rb', line 43

def to_h
  {
    f: f,
    name: name,
    l: l,
    color: color,
    rgb: rgb,
    url: url,
    fb: fb,
    view: view
  }
end

#to_queryObject



39
40
41
# File 'lib/zm/client/folder/folder.rb', line 39

def to_query
  "inid:#{id}"
end

#update!(options) ⇒ Object



76
77
78
# File 'lib/zm/client/folder/folder.rb', line 76

def update!(options)
  @parent.sacc.folder_action(@parent.token, 'update', @id, options)
end

#upload(file_path, fmt = nil, types = nil, resolve = 'replace') ⇒ Object



164
165
166
167
168
169
# File 'lib/zm/client/folder/folder.rb', line 164

def upload(file_path, fmt = nil, types = nil, resolve = 'replace')
  fmt ||= File.extname(file_path)[1..-1]
  # @parent.uploader.send_file(absFolderPath, fmt, types, resolve, file_path)
  uploader = Upload.new(@parent, RestAccountConnector.new)
  uploader.send_file(absFolderPath, fmt, types, resolve, file_path)
end