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

Instance Method Details

#complete_todo(todo) ⇒ Object

Complete a todo

Examples:

client.complete_todo(todo)

Parameters:

  • todo (Resource)

    the todo to be marked as completed

Raises:

See Also:



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

Examples:

client.create_todo(todolist, 'First Todo')
client.create_todo(
  todolist,
  'Program it',
  description: "<div><em>Try that new language!</em></div>, due_on: "2016-05-01"
)

Parameters:

  • todolist (Resource)

    the todolist where the todo is going to be created

  • content (String)

    what the to-do is for

  • options (Hash) (defaults to: {})

    extra parameters for the todo such as due_date and description

Returns:

Raises:

See Also:



79
80
81
82
83
# 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_todo(todo, position) ⇒ Object

Reposition a todo

Examples:

client.uncomplete_todo(todo)

Parameters:

  • todo (Resource)

    the todo to be repositioned

  • position (Integer|String)

    new position for the todo

Raises:

See Also:



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.

Examples:

client.todo(my_project, '10')
client.todo(new_todolist, 134)
client.todo(67543, '2440')

Parameters:

  • parent (Integer|String|Project|Resource)

    can be either a project id, a project or a todolist resource

  • id (Integer|String)

    id of the todo

Returns:

See Also:



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

Examples:

client.todos(todolist)
client.todos(todolist, completed: true)

Parameters:

  • todolist (Resource)

    the parent todolist resource

  • options (Hash) (defaults to: {})

    options to filter the list of todos

Returns:

Raises:

See Also:



31
32
33
# File 'lib/camper/api/todos.rb', line 31

def todos(todolist, options = {})
  get(todolist.todos_url, query: options, override_path: true)
end

#trash_todo(todo) ⇒ Object

Trash a todo

it calls the trash_recording endpoint under the hood

Examples:

client.trash_todo(todo)

Parameters:

  • todo (Resource)

    the todo to be trashed

Raises:

See Also:



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

Examples:

client.uncomplete_todo(todo)

Parameters:

  • todo (Resource)

    the todo to be marked as uncompleted

Raises:

See Also:



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.

Examples:

client.update_todo(todo, 'Todo')
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"
)

Parameters:

  • todo (Resource)

    the todo to be updated

  • options (Hash)

    parameters to be changed. The ones that are not specified will be set to the current values of the todo object

Returns:

Raises:

See Also:



105
106
107
108
109
110
# 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