Class: TodoistClient::Project

Inherits:
Object
  • Object
show all
Includes:
ApiClient
Defined in:
lib/todoist_client/project.rb

Defined Under Namespace

Modules: Paths

Constant Summary collapse

VALID_PARAMS =
[
  :user_id,
  :name,
  :color,
  :collapsed,
  :item_order,
  :cache_count,
  :indent,
  :id,
  :last_updated
].freeze

Constants included from ApiClient

ApiClient::BASE_URI

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiClient

included, #set_params, #with_remote_object

Constructor Details

#initialize(params = nil) ⇒ Project

Returns a new instance of Project.



29
30
31
32
33
34
35
36
# File 'lib/todoist_client/project.rb', line 29

def initialize(params = nil)
  case
  when params.is_a?(String)
    @name = params
  when params.is_a?(Hash)
    set_params(params)
  end
end

Class Method Details

.allObject



93
94
95
# File 'lib/todoist_client/project.rb', line 93

def all
  request(*Paths::ALL).map {|project| self.new(project)}
end

.create(params) ⇒ Object



101
102
103
# File 'lib/todoist_client/project.rb', line 101

def create(params)
  self.new(params).save
end

.find(id) ⇒ Object



97
98
99
# File 'lib/todoist_client/project.rb', line 97

def find(id)
  self.new(request(*Paths::FIND, {project_id: id}))
end

Instance Method Details

#archiveObject

only premium user



66
67
68
69
70
# File 'lib/todoist_client/project.rb', line 66

def archive
  with_remote_object do
    self.class.request *Paths::ARCHIVE, {project_id: id}
  end
end

#completed_itemsObject

only premium user



86
87
88
89
90
# File 'lib/todoist_client/project.rb', line 86

def completed_items
  with_remote_object do
    Item.completed_items(id)
  end
end

#deleteObject



59
60
61
62
63
# File 'lib/todoist_client/project.rb', line 59

def delete
  with_remote_object do
    self.class.request *Paths::DELETE, {project_id: id}
  end
end

#saveObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/todoist_client/project.rb', line 38

def save
  if id
    json = self.class.request *Paths::UPDATE, {
      project_id: @id, # required
      name: @name,
      color: @color,
      indent: @indent,
      order: @item_order
    }.select {|k,v| !v.nil?}
  else
    json = self.class.request *Paths::ADD, {
      name: @name, # required
      color: @color,
      indent: @indent,
      order: @item_order
    }.select {|k,v| !v.nil?}
  end
  set_params(json)
  self
end

#unarchiveObject

only premium user



73
74
75
76
77
# File 'lib/todoist_client/project.rb', line 73

def unarchive
  with_remote_object do
    self.class.request *Paths::UNARCHIVE, {project_id: id}
  end
end

#uncompleted_itemsObject



79
80
81
82
83
# File 'lib/todoist_client/project.rb', line 79

def uncompleted_items
  with_remote_object do
    Item.uncompleted(id)
  end
end