class Nin::Integration::Service::Todoist::Item

Public Instance Methods

add(item) click to toggle source
# File lib/nin/integration/service/todoist.rb, line 54
def add(item)
  commands = [
    {
      "type": "item_add",
      "temp_id": SecureRandom.uuid,
      "uuid": SecureRandom.uuid,
      "args": item
    }
  ].to_json

  @client.sync.write_resources(commands).fetch('temp_id_mapping').values.first
end
all() click to toggle source
# File lib/nin/integration/service/todoist.rb, line 36
def all
  data = @client.sync.read_resources(['projects', 'items'])

  projects = data.fetch('projects').reduce({}) do |projects, p|
    projects.update(p["id"] => p["name"])
  end

  data.fetch('items').reduce([]) do |tasks, t|
    tasks << [
      t["content"],
      (t["due"] || {}).fetch('date', nil),
      projects.fetch(t["project_id"]),
      t["id"],
      (t["checked"].to_i == 1)
    ]
  end
end
delete(ids) click to toggle source
# File lib/nin/integration/service/todoist.rb, line 79
def delete(ids)
  commands = ids.ensure_array.map do |id|
    {
      "type": "item_delete",
      "uuid": SecureRandom.uuid,
      "args": { 'id': id }
    }
  end.to_json

  @client.sync.write_resources(commands)
end
update(items) click to toggle source
# File lib/nin/integration/service/todoist.rb, line 67
def update(items)
  commands = items.ensure_array.map do |item|
    {
      "type": "item_update",
      "uuid": SecureRandom.uuid,
      "args": item
    }
  end.to_json

  @client.sync.write_resources(commands)
end