Module: Camper::Client::TodosAPI
- Included in:
- Camper::Client
- Defined in:
- lib/camper/api/todos.rb
Overview
Defines methods related to todos.
Constant Summary collapse
- PARAMETERS =
%w[ content description assignee_ids completion_subscriber_ids notify due_on starts_on ].freeze
Instance Method Summary collapse
-
#complete_todo(todo) ⇒ Object
Complete a todo.
-
#create_todo(todolist, content, options = {}) ⇒ Resource
Create a todo within a todolist.
-
#reposition_todo(todo, position) ⇒ Object
Reposition a todo.
-
#todo(parent, id) ⇒ Resource
Get a todo with a given id using a particular parent resource.
-
#todos(todolist, options = {}) ⇒ Resource
Get the todos in a todolist.
-
#trash_todo(todo) ⇒ Object
Trash a todo it calls the trash_recording endpoint under the hood.
-
#uncomplete_todo(todo) ⇒ Object
Uncomplete a todo.
-
#update_todo(todo, options) ⇒ Resource
Update a todo.
Instance Method Details
#complete_todo(todo) ⇒ Object
Complete a todo
121 122 123 |
# File 'lib/camper/api/todos.rb', line 121 def complete_todo(todo) post("#{todo.url}/completion", override_path: true) end |
#create_todo(todolist, content, options = {}) ⇒ Resource
Create a todo within a todolist
79 80 81 82 83 |
# File 'lib/camper/api/todos.rb', line 79 def create_todo(todolist, content, = {}) raise Error::InvalidParameter, content if content.blank? post(todolist.todos_url, body: { content: content, ** }, override_path: true) end |
#reposition_todo(todo, position) ⇒ Object
Reposition a todo
149 150 151 152 153 |
# File 'lib/camper/api/todos.rb', line 149 def reposition_todo(todo, position) raise Error::InvalidParameter, position if position.to_i < 1 put("#{todo.url}/position", position: position, override_path: true) end |
#todo(parent, id) ⇒ Resource
Get a todo with a given id using a particular parent resource.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/camper/api/todos.rb', line 48 def todo(parent, id) bucket_id = parent if parent.is_a? Camper::Project bucket_id = parent.id elsif parent.respond_to?(:type) bucket_id = parent.bucket.id end get("/buckets/#{bucket_id}/todos/#{id}") end |
#todos(todolist, options = {}) ⇒ Resource
Get the todos in a todolist
31 32 33 |
# File 'lib/camper/api/todos.rb', line 31 def todos(todolist, = {}) get(todolist.todos_url, query: , override_path: true) end |
#trash_todo(todo) ⇒ Object
Trash a todo
it calls the trash_recording endpoint under the hood
165 166 167 |
# File 'lib/camper/api/todos.rb', line 165 def trash_todo(todo) trash_recording(todo) end |
#uncomplete_todo(todo) ⇒ Object
Uncomplete a todo
134 135 136 |
# File 'lib/camper/api/todos.rb', line 134 def uncomplete_todo(todo) delete("#{todo.url}/completion", override_path: true) end |
#update_todo(todo, options) ⇒ Resource
Update a todo.
105 106 107 108 109 110 |
# File 'lib/camper/api/todos.rb', line 105 def update_todo(todo, ) body = {}.merge() PARAMETERS.each { |p| body[p.to_sym] = todo[p] unless key_is_present?(body, p) } put(todo.url, body: body, override_path: true) end |