class Checkoff::Sections
Query different sections of Asana projects
Constants
- LONG_CACHE_TIME
- MINUTE
- SHORT_CACHE_TIME
Attributes
client[R]
projects[R]
time[R]
workspaces[R]
Public Class Methods
new(config: Checkoff::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), workspaces: Checkoff::Workspaces.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client, time: Time)
click to toggle source
# File lib/checkoff/sections.rb, line 19 def initialize(config: Checkoff::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config), workspaces: Checkoff::Workspaces.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client, time: Time) @projects = projects @workspaces = workspaces @time = time @client = client end
Public Instance Methods
section_or_raise(workspace_name, project_name, section_name)
click to toggle source
# File lib/checkoff/sections.rb, line 67 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)
click to toggle source
Pulls just names of tasks from a given section.
# File lib/checkoff/sections.rb, line 61 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)
click to toggle source
Returns a list of Asana API section objects for a given project
# File lib/checkoff/sections.rb, line 32 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: [])
click to toggle source
XXX: Rename to section_tasks
Pulls task objects from a specified section
# File lib/checkoff/sections.rb, line 48 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)
click to toggle source
Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks
# File lib/checkoff/sections.rb, line 39 def tasks_by_section(workspace_name, project_name) project = project_or_raise(workspace_name, project_name) tasks_by_section_for_project(project) end
Private Instance Methods
by_section(tasks, project_gid)
click to toggle source
Given a list of tasks, pull a Hash of tasks with section name -> task list
# File lib/checkoff/sections.rb, line 92 def by_section(tasks, project_gid) by_section = {} tasks.each do |task| file_task_by_section(by_section, task, project_gid) end by_section end
file_task_by_section(by_section, task, project_gid)
click to toggle source
# File lib/checkoff/sections.rb, line 101 def file_task_by_section(by_section, task, project_gid) membership = task.memberships.find { |m| m['project']['gid'] == project_gid } raise "Could not find task in project_gid #{project_gid}: #{task}" if membership.nil? current_section = membership['section']['name'] current_section = nil if current_section == '(no section)' by_section[current_section] ||= [] by_section[current_section] << task end
project_or_raise(workspace_name, project_name)
click to toggle source
# File lib/checkoff/sections.rb, line 111 def project_or_raise(workspace_name, project_name) project = projects.project(workspace_name, project_name) if project.nil? raise "Could not find project #{project_name} " \ "under workspace #{workspace_name}" end project end
section(workspace_name, project_name, section_name)
click to toggle source
# File lib/checkoff/sections.rb, line 120 def section(workspace_name, project_name, section_name) sections = sections_or_raise(workspace_name, project_name) sections.find { |section| section.name.chomp(':') == section_name.chomp(':') } end
tasks_by_section_for_project(project)
click to toggle source
Given a project object, pull all tasks, then provide a Hash of tasks with section name -> task list of the uncompleted tasks
# File lib/checkoff/sections.rb, line 85 def tasks_by_section_for_project(project) raw_tasks = projects.tasks_from_project(project) active_tasks = projects.active_tasks(raw_tasks) by_section(active_tasks, project.gid) end