module Camper::Client::TodosAPI
Defines methods related to todos. @see github.com/basecamp/bc3-api/blob/master/sections/todos.md
Constants
- PARAMETERS
Public Instance Methods
Complete a todo
@example
client.complete_todo(todo)
@param todo [Resource] the todo to be marked as completed @raise [Error::InvalidParameter] if url field in todo param
is not a valid basecamp url
@see github.com/basecamp/bc3-api/blob/master/sections/todos.md#complete-a-to-do
# File lib/camper/api/todos.rb, line 121 def complete_todo(todo) post("#{todo.url}/completion", override_path: true) end
Create a todo within a todolist
@example
client.create_todo(todolist, 'First Todo')
@example
client.create_todo( todolist, 'Program it', description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01" )
@param todolist [Resource] the todolist where the todo is going to be created @param content [String] what the to-do is for @param options [Hash] extra parameters for the todo such as due_date and description @return [Resource] @raise [Error::InvalidParameter] if todos_url field in todolist param
is not a valid basecamp url
@raise [Error::InvalidParameter] if content parameter is blank @see github.com/basecamp/bc3-api/blob/master/sections/todos.md#create-a-to-do
# File lib/camper/api/todos.rb, line 79 def create_todo(todolist, content, options = {}) raise Error::InvalidParameter, content if content.blank? post(todolist.todos_url, body: { content: content, **options }, override_path: true) end
Reposition a todo
@example
client.uncomplete_todo(todo)
@param todo [Resource] the todo to be repositioned @param position [Integer|String] new position for the todo @raise [Error::InvalidParameter] if url field in todo param
is not a valid basecamp url
@raise [Error::InvalidParameter] if position param is less than 1 @see github.com/basecamp/bc3-api/blob/master/sections/todos.md#reposition-a-to-do
# 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
Get a todo with a given id using a particular parent resource.
@example
client.todo(my_project, '10')
@example
client.todo(new_todolist, 134)
@example
client.todo(67543, '2440')
@param parent [Integer|String|Project|Resource] can be either a project id, a project or a todolist resource @param id [Integer|String] id of the todo @return [Resource] @see github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-a-to-do
# 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
Get the todos in a todolist
@example
client.todos(todolist)
@example
client.todos(todolist, completed: true)
@param todolist [Resource] the parent todolist resource @param options [Hash] options to filter the list of todos @return [Resource] @raise [Error::InvalidParameter] if todos_url field in todolist param
is not a valid basecamp url
@see github.com/basecamp/bc3-api/blob/master/sections/todos.md#get-to-dos
# File lib/camper/api/todos.rb, line 31 def todos(todolist, options = {}) get(todolist.todos_url, query: options, override_path: true) end
Trash a todo
it calls the trash_recording endpoint under the hood
@example
client.trash_todo(todo)
@param todo [Resource] the todo to be trashed @raise [Error::InvalidParameter] if url field in todo param
is not a valid basecamp url
@see github.com/basecamp/bc3-api/blob/master/sections/recordings.md#trash-a-recording
# File lib/camper/api/todos.rb, line 165 def trash_todo(todo) trash_recording(todo) end
Uncomplete a todo
@example
client.uncomplete_todo(todo)
@param todo [Resource] the todo to be marked as uncompleted @raise [Error::InvalidParameter] if url field in todo param
is not a valid basecamp url
@see github.com/basecamp/bc3-api/blob/master/sections/todos.md#uncomplete-a-to-do
# File lib/camper/api/todos.rb, line 134 def uncomplete_todo(todo) delete("#{todo.url}/completion", override_path: true) end
Update a todo.
@example
client.update_todo(todo, 'Todo')
@example
client.update_todo( todo, 'Program it', description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01", starts_on: "2016-04-30" )
@param todo [Resource] the todo to be updated @param options [Hash] parameters to be changed. The ones that are not specified
will be set to the current values of the todo object
@return [Resource] @raise [Error::InvalidParameter] if url field in todo param
is not a valid basecamp url
@see github.com/basecamp/bc3-api/blob/master/sections/todos.md#update-a-to-do
# File lib/camper/api/todos.rb, line 105 def update_todo(todo, options) body = {}.merge(options) PARAMETERS.each { |p| body[p.to_sym] = todo[p] unless key_is_present?(body, p) } put(todo.url, body: body, override_path: true) end
Private Instance Methods
# File lib/camper/api/todos.rb, line 171 def key_is_present?(hash, key) hash.key?(key.to_sym) || hash.key?(key.to_s) end