Class: Checkoff::Sections

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/checkoff/sections.rb

Overview

Query different sections of Asana projects

Constant Summary collapse

MINUTE =
60
LONG_CACHE_TIME =
MINUTE * 15
SHORT_CACHE_TIME =
MINUTE * 5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, projects: Checkoff::Projects.new(config: config, client: client), workspaces: Checkoff::Workspaces.new(config: config, client: client), time: Time) ⇒ Sections

Returns a new instance of Sections.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/checkoff/sections.rb', line 20

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               client: Checkoff::Clients.new(config: config).client,
               projects: Checkoff::Projects.new(config: config,
                                                client: client),
               workspaces: Checkoff::Workspaces.new(config: config,
                                                    client: client),
               time: Time)
  @projects = projects
  @workspaces = workspaces
  @my_tasks = Checkoff::MyTasks.new(config: config, projects: projects, client: client)
  @client = client
  @time = time
end

Instance Attribute Details

#my_tasksObject (readonly)

Returns the value of attribute my_tasks.



18
19
20
# File 'lib/checkoff/sections.rb', line 18

def my_tasks
  @my_tasks
end

#projectsObject (readonly)

Returns the value of attribute projects.



18
19
20
# File 'lib/checkoff/sections.rb', line 18

def projects
  @projects
end

#timeObject (readonly)

Returns the value of attribute time.



18
19
20
# File 'lib/checkoff/sections.rb', line 18

def time
  @time
end

#workspacesObject (readonly)

Returns the value of attribute workspaces.



18
19
20
# File 'lib/checkoff/sections.rb', line 18

def workspaces
  @workspaces
end

Instance Method Details

#section_or_raise(workspace_name, project_name, section_name) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/checkoff/sections.rb', line 73

def section_or_raise(workspace_name, project_name, section_name)
  section = section(workspace_name, project_name, section_name)
  if section.nil?
    valid_sections = sections_or_raise(workspace_name, project_name).map(&:name)

    raise "Could not find section #{section_name} under project #{project_name} " \
          "under workspace #{workspace_name}.  Valid sections: #{valid_sections}"
  end
  section
end

#section_task_names(workspace_name, project_name, section_name) ⇒ Object

Pulls just names of tasks from a given section.



67
68
69
70
# File 'lib/checkoff/sections.rb', line 67

def section_task_names(workspace_name, project_name, section_name)
  tasks = tasks(workspace_name, project_name, section_name)
  tasks.map(&:name)
end

#sections_or_raise(workspace_name, project_name) ⇒ Object

Returns a list of Asana API section objects for a given project



35
36
37
38
# File 'lib/checkoff/sections.rb', line 35

def sections_or_raise(workspace_name, project_name)
  project = project_or_raise(workspace_name, project_name)
  client.sections.get_sections_for_project(project_gid: project.gid)
end

#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Object

XXX: Rename to section_tasks

Pulls task objects from a specified section



54
55
56
57
58
59
60
61
62
63
# File 'lib/checkoff/sections.rb', line 54

def tasks(workspace_name, project_name, section_name,
          only_uncompleted: true,
          extra_fields: [])
  section = section_or_raise(workspace_name, project_name, section_name)
  options = projects.task_options
  options[:options][:fields] += extra_fields
  options[:completed_since] = '9999-12-01' if only_uncompleted
  client.tasks.get_tasks(section: section.gid,
                         **options)
end

#tasks_by_section(workspace_name, project_name, extra_fields: []) ⇒ Object

Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks



42
43
44
45
46
47
48
49
# File 'lib/checkoff/sections.rb', line 42

def tasks_by_section(workspace_name, project_name, extra_fields: [])
  project = project_or_raise(workspace_name, project_name)
  if project_name == :my_tasks
    my_tasks.tasks_by_section_for_my_tasks(project, extra_fields: extra_fields)
  else
    tasks_by_section_for_project(project, extra_fields: extra_fields)
  end
end