Class: Checkoff::Tasks

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/tasks.rb

Overview

Pull tasks from Asana

Constant Summary collapse

MINUTE =
60
HOUR =
MINUTE * 60
DAY =
24 * HOUR
REALLY_LONG_CACHE_TIME =
HOUR
LONG_CACHE_TIME =
MINUTE * 15
SHORT_CACHE_TIME =
MINUTE * 5

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, sections: Checkoff::Sections.new(config: config, client: client), time_class: Time, asana_task: Asana::Resources::Task) ⇒ Tasks



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/checkoff/tasks.rb', line 17

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               client: Checkoff::Clients.new(config: config).client,
               sections: Checkoff::Sections.new(config: config,
                                                client: client),
               time_class: Time,
               asana_task: Asana::Resources::Task)
  @config = config
  @sections = sections
  @time_class = time_class
  @asana_task = asana_task
  @client = client
end

Instance Method Details

#add_task(name, workspace_gid: default_workspace_gid, assignee_gid: default_assignee_gid) ⇒ Object



55
56
57
58
59
60
61
# 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) ⇒ Object

Pull a specific task by name



41
42
43
44
45
46
47
48
49
50
51
52
53
# 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) ⇒ Boolean



30
31
32
33
34
35
36
37
38
# 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) ⇒ Object

Return an end-user URL to the task in question



64
65
66
# File 'lib/checkoff/tasks.rb', line 64

def url_of_task(task)
  "https://app.asana.com/0/0/#{task.gid}/f"
end