Class: Todoist::Task

Inherits:
Struct
  • Object
show all
Includes:
StructCleanup
Defined in:
lib/todoist/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StructCleanup

#fields_to_date_time, #ignore_undefined_keys, #properties_to_desc, #replace_keys

Constructor Details

#initialize(*arg_hashes) ⇒ Task

Returns a new instance of Task.



34
35
36
37
38
39
40
41
# File 'lib/todoist/task.rb', line 34

def initialize(*arg_hashes)
  args = arg_hashes.first
  get_properties(args)
  fields_to_date_time(args, %w[added_at updated_at])
  ignore_undefined_keys(args)
  due_to_struct(args)
  super
end

Instance Attribute Details

#added_atObject

Returns the value of attribute added_at

Returns:

  • (Object)

    the current value of added_at



2
3
4
# File 'lib/todoist/task.rb', line 2

def added_at
  @added_at
end

#added_by_uidObject

Returns the value of attribute added_by_uid

Returns:

  • (Object)

    the current value of added_by_uid



2
3
4
# File 'lib/todoist/task.rb', line 2

def added_by_uid
  @added_by_uid
end

#assigned_by_uidObject

Returns the value of attribute assigned_by_uid

Returns:

  • (Object)

    the current value of assigned_by_uid



2
3
4
# File 'lib/todoist/task.rb', line 2

def assigned_by_uid
  @assigned_by_uid
end

#checkedObject

Returns the value of attribute checked

Returns:

  • (Object)

    the current value of checked



2
3
4
# File 'lib/todoist/task.rb', line 2

def checked
  @checked
end

#child_orderObject

Returns the value of attribute child_order

Returns:

  • (Object)

    the current value of child_order



2
3
4
# File 'lib/todoist/task.rb', line 2

def child_order
  @child_order
end

#completed_atObject

Returns the value of attribute completed_at

Returns:

  • (Object)

    the current value of completed_at



2
3
4
# File 'lib/todoist/task.rb', line 2

def completed_at
  @completed_at
end

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



2
3
4
# File 'lib/todoist/task.rb', line 2

def content
  @content
end

#day_orderObject

Returns the value of attribute day_order

Returns:

  • (Object)

    the current value of day_order



2
3
4
# File 'lib/todoist/task.rb', line 2

def day_order
  @day_order
end

#deadlineObject

Returns the value of attribute deadline

Returns:

  • (Object)

    the current value of deadline



2
3
4
# File 'lib/todoist/task.rb', line 2

def deadline
  @deadline
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



2
3
4
# File 'lib/todoist/task.rb', line 2

def description
  @description
end

#dueObject

Returns the value of attribute due

Returns:

  • (Object)

    the current value of due



2
3
4
# File 'lib/todoist/task.rb', line 2

def due
  @due
end

#durationObject

Returns the value of attribute duration

Returns:

  • (Object)

    the current value of duration



2
3
4
# File 'lib/todoist/task.rb', line 2

def duration
  @duration
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/todoist/task.rb', line 2

def id
  @id
end

#is_collapsedObject

Returns the value of attribute is_collapsed

Returns:

  • (Object)

    the current value of is_collapsed



2
3
4
# File 'lib/todoist/task.rb', line 2

def is_collapsed
  @is_collapsed
end

#is_deletedObject

Returns the value of attribute is_deleted

Returns:

  • (Object)

    the current value of is_deleted



2
3
4
# File 'lib/todoist/task.rb', line 2

def is_deleted
  @is_deleted
end

#jsw_ignored_keysObject

Returns the value of attribute jsw_ignored_keys

Returns:

  • (Object)

    the current value of jsw_ignored_keys



2
3
4
# File 'lib/todoist/task.rb', line 2

def jsw_ignored_keys
  @jsw_ignored_keys
end

#jsw_propertiesObject

Returns the value of attribute jsw_properties

Returns:

  • (Object)

    the current value of jsw_properties



2
3
4
# File 'lib/todoist/task.rb', line 2

def jsw_properties
  @jsw_properties
end

#labelsObject

Returns the value of attribute labels

Returns:

  • (Object)

    the current value of labels



2
3
4
# File 'lib/todoist/task.rb', line 2

def labels
  @labels
end

#note_countObject

Returns the value of attribute note_count

Returns:

  • (Object)

    the current value of note_count



2
3
4
# File 'lib/todoist/task.rb', line 2

def note_count
  @note_count
end

#parent_idObject

Returns the value of attribute parent_id

Returns:

  • (Object)

    the current value of parent_id



2
3
4
# File 'lib/todoist/task.rb', line 2

def parent_id
  @parent_id
end

#priorityObject

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



2
3
4
# File 'lib/todoist/task.rb', line 2

def priority
  @priority
end

#project_idObject

Returns the value of attribute project_id

Returns:

  • (Object)

    the current value of project_id



2
3
4
# File 'lib/todoist/task.rb', line 2

def project_id
  @project_id
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



2
3
4
# File 'lib/todoist/task.rb', line 2

def project_name
  @project_name
end

#responsible_uidObject

Returns the value of attribute responsible_uid

Returns:

  • (Object)

    the current value of responsible_uid



2
3
4
# File 'lib/todoist/task.rb', line 2

def responsible_uid
  @responsible_uid
end

#section_idObject

Returns the value of attribute section_id

Returns:

  • (Object)

    the current value of section_id



2
3
4
# File 'lib/todoist/task.rb', line 2

def section_id
  @section_id
end

#updated_atObject

Returns the value of attribute updated_at

Returns:

  • (Object)

    the current value of updated_at



2
3
4
# File 'lib/todoist/task.rb', line 2

def updated_at
  @updated_at
end

#user_idObject

Returns the value of attribute user_id

Returns:

  • (Object)

    the current value of user_id



2
3
4
# File 'lib/todoist/task.rb', line 2

def user_id
  @user_id
end

Instance Method Details

#due_to_struct(args) ⇒ Object



43
44
45
# File 'lib/todoist/task.rb', line 43

def due_to_struct(args)
  args["due"] = Due[args["due"]]
end

#get_properties(args) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/todoist/task.rb', line 56

def get_properties(args)
  args[:jsw_properties] = {}
  if (jsw_properties_match = args["description"].match(/(.*)```\s*~~~begin_yaml~~~\s*(.*)\s*~~~end_yaml~~~\s*```(.*)/m))
    @desc = [jsw_properties_match[1], jsw_properties_match[3]]
    args[:jsw_properties] = YAML.safe_load(jsw_properties_match[2])
    if args[:jsw_properties].is_a?(Hash)
      args[:jsw_properties].deep_symbolize_keys!
    end
  end
end

#properties_string(properties = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/todoist/task.rb', line 67

def properties_string(properties = nil)
  properties ||= jsw_properties
  <<~HEREDOC
    #{@desc&.dig(0)}
    ```
    ~~~begin_yaml~~~
    #{properties.to_yaml}~~~end_yaml~~~
    ```
    #{@desc&.dig(1)}
  HEREDOC
end

#to_hObject



47
48
49
50
# File 'lib/todoist/task.rb', line 47

def to_h
  self.due = due.to_h
  super
end

#urlObject



52
53
54
# File 'lib/todoist/task.rb', line 52

def url
  "https://todoist.com/showTask?id=#{id}"
end