Class: Zm::Client::Task

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

Overview

class for account task

Constant Summary collapse

INSTANCE_VARIABLE_KEYS =
i[id uid name l desc start_at dur end_at tn]

Instance Attribute Summary collapse

Attributes inherited from Base::Object

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

Instance Method Summary collapse

Methods inherited from Base::AccountObject

#modify!, #rename!, #soap_account_connector, #to_h

Methods inherited from Base::Object

#arrow_name, #clone, #convert_json_string_value, #disable_builder, #enable_builder, #instance_variables_array, #instance_variables_hash, #logger, #recorded?, #save!, #to_s, #use_builder?

Constructor Details

#initialize(parent, json = nil) {|_self| ... } ⇒ Task

Returns a new instance of Task.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(parent, json = nil)
  @parent = parent
  init_from_json(json) if json.is_a?(Hash)
  yield(self) if block_given?
end

Instance Attribute Details

#folderObject



27
28
29
# File 'lib/zm/client/task/task.rb', line 27

def folder
  @folder ||= @parent.folders.all.find { |folder| folder.id == l }
end

#jsonObject (readonly)

Returns the value of attribute json.



12
13
14
# File 'lib/zm/client/task/task.rb', line 12

def json
  @json
end

Instance Method Details

#concatObject



23
24
25
# File 'lib/zm/client/task/task.rb', line 23

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

#create!Object



37
38
39
40
# File 'lib/zm/client/task/task.rb', line 37

def create!
  # rep = @parent.sacc.create_task(@parent.token, @l, @name, @view)
  # init_from_json(rep[:Body][:CreateTaskResponse][:task].first)
end

#delete!Object



47
48
49
# File 'lib/zm/client/task/task.rb', line 47

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

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



31
32
33
34
35
# File 'lib/zm/client/task/task.rb', line 31

def download(dest_file_path, fmt = 'ics')
  # @parent.uploader.download_file(folder.absFolderPath, 'ics', ['task'], [id], dest_file_path)
  uploader = Upload.new(@parent, RestAccountConnector.new)
  uploader.download_file(folder.absFolderPath, fmt, ['task'], [id], dest_file_path)
end

#init_from_json(json) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/zm/client/task/task.rb', line 51

def init_from_json(json)
  @json = json
  @id = json[:id].to_i
  @uid = json[:uid]
  @tn = json[:tn]
  @name = json[:name]
  @l = json[:l]
  @desc = json[:fr]
  make_date(json)
end

#make_date(json) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/zm/client/task/task.rb', line 62

def make_date(json)
  return if json[:inst].nil? || json[:inst].first.empty? || json[:dur].nil?

  @start_at = Time.at(json[:inst].first[:s] / 1000)
  @end_at = Time.at((json[:inst].first[:s] + json[:dur]) / 1000)

  return if json[:dur].nil?

  @dur = json[:dur] / 1000
end

#reload!Object



42
43
44
45
# File 'lib/zm/client/task/task.rb', line 42

def reload!
  # rep = @parent.sacc.get_task(@parent.token, @id)
  # init_from_json(rep[:Body][:GetTaskResponse][:task].first)
end