Sha256: 54b0f4eae40bf1fd7a3c6f8cd1a7af1170fec1d9639a3227bf1f8562f989ef2a

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

#!/usr/bin/env ruby

# frozen_string_literal: true

require_relative 'sections'

module Checkoff
  # Pull things from 'my tasks' in Asana
  class Tasks
    MINUTE = 60
    HOUR = MINUTE * 60
    DAY = 24 * HOUR
    REALLY_LONG_CACHE_TIME = HOUR
    LONG_CACHE_TIME = MINUTE * 15
    SHORT_CACHE_TIME = MINUTE * 5

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

    def client
      @sections.client
    end

    def projects
      @projects ||= @sections.projects
    end

    def task(workspace_name, project_name, task_name, only_uncompleted: true)
      project = projects.project(workspace_name, project_name)
      tasks = projects.tasks_from_project(project,
                                          only_uncompleted: only_uncompleted)
      tasks.find { |task| task.name == task_name }
    end

    def tasks_minus_sections(tasks)
      @sections.by_section(tasks).values.flatten
    end

    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

    def default_assignee_gid
      @config[:default_assignee_gid]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
checkoff-0.5.2 lib/checkoff/tasks.rb
checkoff-0.5.1 lib/checkoff/tasks.rb
checkoff-0.5.0 lib/checkoff/tasks.rb
checkoff-0.4.0 lib/checkoff/tasks.rb
checkoff-0.3.2 lib/checkoff/tasks.rb
checkoff-0.3.1 lib/checkoff/tasks.rb
checkoff-0.3.0 lib/checkoff/tasks.rb