class Checkoff::Tasks

Pull tasks from Asana

Constants

DAY
HOUR
LONG_CACHE_TIME
MINUTE
REALLY_LONG_CACHE_TIME
SHORT_CACHE_TIME

Attributes

client[R]

Public Class Methods

new(config: Checkoff::ConfigLoader.load(:asana), sections: Checkoff::Sections.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client, time_class: Time, asana_task: Asana::Resources::Task) click to toggle source
# File lib/checkoff/tasks.rb, line 17
def initialize(config: Checkoff::ConfigLoader.load(:asana),
               sections: Checkoff::Sections.new(config: config),
               clients: Checkoff::Clients.new(config: config),
               client: clients.client,
               time_class: Time,
               asana_task: Asana::Resources::Task)
  @config = config
  @sections = sections
  @time_class = time_class
  @asana_task = asana_task
  @client = client
end

Public Instance Methods

add_task(name, workspace_gid: default_workspace_gid, assignee_gid: default_assignee_gid) click to toggle source
# File lib/checkoff/tasks.rb, line 55
def add_task(name,
             workspace_gid: default_workspace_gid,
             assignee_gid: default_assignee_gid)
  @asana_task.create(client,
                     assignee: assignee_gid,
                     workspace: workspace_gid, name: name)
end
task(workspace_name, project_name, task_name, section_name: :unspecified, only_uncompleted: true) click to toggle source

Pull a specific task by name

# File lib/checkoff/tasks.rb, line 41
def task(workspace_name, project_name, task_name,
         section_name: :unspecified,
         only_uncompleted: true)
  project = projects.project(workspace_name, project_name)
  tasks = if section_name == :unspecified
            projects.tasks_from_project(project,
                                        only_uncompleted: only_uncompleted)
          else
            @sections.tasks(workspace_name, project_name, section_name,
                            only_uncompleted: only_uncompleted)
          end
  tasks.find { |task| task.name == task_name }
end
task_ready?(task) click to toggle source
# File lib/checkoff/tasks.rb, line 30
def task_ready?(task)
  return false if incomplete_dependencies?(task)

  due = due_time(task)

  return true if due.nil?

  due < @time_class.now
end
url_of_task(task) click to toggle source

Return an end-user URL to the task in question

# File lib/checkoff/tasks.rb, line 64
def url_of_task(task)
  "https://app.asana.com/0/0/#{task.gid}/f"
end

Private Instance Methods

default_assignee_gid() click to toggle source
# File lib/checkoff/tasks.rb, line 76
def default_assignee_gid
  @config.fetch(:default_assignee_gid)
end
due_time(task) click to toggle source
# File lib/checkoff/tasks.rb, line 80
def due_time(task)
  return @time_class.parse(task.due_at) if task.due_at
  return @time_class.parse(task.due_on) if task.due_on

  nil
end
incomplete_dependencies?(task) click to toggle source
# File lib/checkoff/tasks.rb, line 87
def incomplete_dependencies?(task)
  task.dependencies.any? do |parent_task_info|
    parent_task_gid = parent_task_info.gid
    parent_task = @asana_task.find_by_id(client, parent_task_gid,
                                         options: { fields: ['completed'] })
    !parent_task.completed
  end
end
projects() click to toggle source
# File lib/checkoff/tasks.rb, line 72
def projects
  @projects ||= @sections.projects
end