class Abt::Providers::Asana::Commands::Add

Public Class Methods

description() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 12
def self.description
  "Create a new task for the current/specified Asana project"
end
usage() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 8
def self.usage
  "abt add asana[:<project-gid>]"
end

Public Instance Methods

perform() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 16
def perform
  require_project!

  task
  warn("Task created")

  if section
    move_task
    warn("Moved to section: #{section['name']}")
  end

  print_task(project, task)
end

Private Instance Methods

move_task() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 45
def move_task
  body = { data: { task: task["gid"] } }
  body_json = Oj.dump(body, mode: :json)
  api.post("sections/#{section['gid']}/addTask", body_json)
end
name() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 51
def name
  @name ||= cli.prompt.text("Enter task description")
end
notes() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 55
def notes
  @notes ||= cli.prompt.text("Enter task notes")
end
section() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 59
def section
  @section ||= cli.prompt.choice("Add to section?", sections,
                                 nil_option: ["q", "Don't add to section"])
end
sections() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 64
def sections
  @sections ||= begin
    warn("Fetching sections...")
    api.get_paged("projects/#{project_gid}/sections", opt_fields: "name")
  end
end
task() click to toggle source
# File lib/abt/providers/asana/commands/add.rb, line 32
def task
  @task ||= begin
    body = {
      data: {
        name: name,
        notes: notes,
        projects: [project_gid]
      }
    }
    api.post("tasks", Oj.dump(body, mode: :json))
  end
end