class Checkoff::Projects
Work with projects in 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), workspaces: Checkoff::Workspaces.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client)
click to toggle source
# File lib/checkoff/projects.rb, line 26 def initialize(config: Checkoff::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client) @config = config @workspaces = workspaces @client = client end
Public Instance Methods
active_tasks(tasks)
click to toggle source
find uncompleted tasks in a list
# File lib/checkoff/projects.rb, line 68 def active_tasks(tasks) tasks.select { |task| task.completed_at.nil? } end
project(workspace_name, project_name)
click to toggle source
pulls an Asana API project class given a name
# File lib/checkoff/projects.rb, line 47 def project(workspace_name, project_name) if project_name.is_a?(Symbol) && project_name.to_s.start_with?('my_tasks') my_tasks(workspace_name) else projects = projects_by_workspace_name(workspace_name) projects.find do |project| project.name == project_name end end end
project_or_raise(workspace_name, project_name)
click to toggle source
# File lib/checkoff/projects.rb, line 59 def project_or_raise(workspace_name, project_name) project = project(workspace_name, project_name) raise "Could not find project #{project_name} under workspace #{workspace_name}." if project.nil? project end
task_options()
click to toggle source
Default options used in Asana API to pull taskso
# File lib/checkoff/projects.rb, line 36 def task_options { per_page: 100, options: { fields: %w[name completed_at due_at due_on tags memberships.project.gid memberships.section.name dependencies], }, } end
tasks_from_project(project, only_uncompleted: true, extra_fields: [])
click to toggle source
pull task objects from a named project
# File lib/checkoff/projects.rb, line 73 def tasks_from_project(project, only_uncompleted: true, extra_fields: []) options = task_options options[:completed_since] = '9999-12-01' if only_uncompleted options[:project] = project.gid options[:options][:fields] += extra_fields client.tasks.find_all(**options).to_a end
Private Instance Methods
my_tasks(workspace_name)
click to toggle source
# File lib/checkoff/projects.rb, line 98 def my_tasks(workspace_name) workspace = @workspaces.workspace_or_raise(workspace_name) result = client.user_task_lists.get_user_task_list_for_user(user_gid: 'me', workspace: workspace.gid) gid = result.gid projects.find_by_id(gid) end
projects()
click to toggle source
# File lib/checkoff/projects.rb, line 86 def projects client.projects end
projects_by_workspace_name(workspace_name)
click to toggle source
# File lib/checkoff/projects.rb, line 91 def projects_by_workspace_name(workspace_name) workspace = @workspaces.workspace_or_raise(workspace_name) raise "Could not find workspace named #{workspace_name}" unless workspace projects.find_by_workspace(workspace: workspace.gid) end