Class: TodoistClient::Project
- Inherits:
-
Object
- Object
- TodoistClient::Project
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#archive ⇒ Object
only premium user.
-
#completed_items ⇒ Object
only premium user.
- #delete ⇒ Object
-
#initialize(params = nil) ⇒ Project
constructor
A new instance of Project.
- #save ⇒ Object
-
#unarchive ⇒ Object
only premium user.
- #uncompleted_items ⇒ Object
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
.all ⇒ Object
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 |
Instance Method Details
#archive ⇒ Object
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_items ⇒ Object
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 |
#delete ⇒ Object
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 |
#save ⇒ Object
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 |
#unarchive ⇒ Object
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_items ⇒ Object
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 |