Class: Checkoff::Sections
- Inherits:
-
Object
- Object
- Checkoff::Sections
- Extended by:
- CacheMethod::ClassMethods, Forwardable
- Defined in:
- lib/checkoff/sections.rb
Overview
Query different sections of Asana projects
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- REALLY_LONG_CACHE_TIME =
HOUR * 1
- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE * 5
Instance Attribute Summary collapse
- #my_tasks ⇒ Checkoff::MyTasks readonly
- #projects ⇒ Checkoff::Projects readonly
- #time ⇒ Class<Time> readonly
- #workspaces ⇒ Checkoff::Workspaces readonly
Instance Method Summary collapse
-
#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
constructor
A new instance of Sections.
- #previous_section(section) ⇒ Asana::Resources::Section?
- #section_by_gid(gid) ⇒ Asana::Resources::Section
- #section_key(name) ⇒ String?
-
#section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Asana::Resources::Section
@sg-ignore.
-
#section_task_names(workspace_name, project_name, section_name) ⇒ Array<String>
Pulls just names of tasks from a given section.
-
#sections_by_project_gid(project_gid, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project GID.
-
#sections_or_raise(workspace_name, project_name, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project.
-
#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
XXX: Rename to section_tasks.
-
#tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) ⇒ Hash{[String, nil] => Enumerable<Asana::Resources::Task>}
Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks.
- #tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/checkoff/sections.rb', line 40 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_tasks ⇒ Checkoff::MyTasks (readonly)
33 34 35 |
# File 'lib/checkoff/sections.rb', line 33 def my_tasks @my_tasks end |
#projects ⇒ Checkoff::Projects (readonly)
24 25 26 |
# File 'lib/checkoff/sections.rb', line 24 def projects @projects end |
#time ⇒ Class<Time> (readonly)
30 31 32 |
# File 'lib/checkoff/sections.rb', line 30 def time @time end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
27 28 29 |
# File 'lib/checkoff/sections.rb', line 27 def workspaces @workspaces end |
Instance Method Details
#previous_section(section) ⇒ Asana::Resources::Section?
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/checkoff/sections.rb', line 182 def previous_section(section) sections = sections_by_project_gid(section.project.fetch('gid')) # @type [Array<Asana::Resources::Section>] sections = sections.to_a index = sections.find_index { |s| s.gid == section.gid } return nil if index.nil? || index.zero? sections[index - 1] end |
#section_by_gid(gid) ⇒ Asana::Resources::Section
198 199 200 201 202 |
# File 'lib/checkoff/sections.rb', line 198 def section_by_gid(gid) = {} Asana::Resources::Section.new(parse(client.get("/sections/#{gid}", options: )).first, client: client) end |
#section_key(name) ⇒ String?
172 173 174 175 176 177 |
# File 'lib/checkoff/sections.rb', line 172 def section_key(name) inbox_section_names = ['(no section)', 'Untitled section', 'Inbox', 'Recently assigned'] return nil if inbox_section_names.include?(name) name end |
#section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Asana::Resources::Section
@sg-ignore
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/checkoff/sections.rb', line 156 def section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) s = section(workspace_name, project_name, section_name, extra_section_fields: extra_section_fields) if s.nil? valid_sections = sections_or_raise(workspace_name, project_name, extra_fields: extra_section_fields).map(&:name) raise "Could not find section #{section_name.inspect} under project #{project_name.inspect} " \ "under workspace #{workspace_name.inspect}. Valid sections: #{valid_sections.inspect}" end s end |
#section_task_names(workspace_name, project_name, section_name) ⇒ Array<String>
Pulls just names of tasks from a given section.
143 144 145 146 |
# File 'lib/checkoff/sections.rb', line 143 def section_task_names(workspace_name, project_name, section_name) task_array = tasks(workspace_name, project_name, section_name) task_array.map(&:name) end |
#sections_by_project_gid(project_gid, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project GID
71 72 73 74 75 |
# File 'lib/checkoff/sections.rb', line 71 def sections_by_project_gid(project_gid, extra_fields: []) fields = %w[name] + extra_fields client.sections.get_sections_for_project(project_gid: project_gid, options: { fields: fields }) end |
#sections_or_raise(workspace_name, project_name, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project
60 61 62 63 |
# File 'lib/checkoff/sections.rb', line 60 def sections_or_raise(workspace_name, project_name, extra_fields: []) project = project_or_raise(workspace_name, project_name) sections_by_project_gid(project.gid, extra_fields: extra_fields) end |
#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
XXX: Rename to section_tasks
Pulls task objects from a specified section
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/checkoff/sections.rb', line 125 def tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) section = section_or_raise(workspace_name, project_name, section_name) = projects. [:options][:fields] += extra_fields [:completed_since] = '9999-12-01' if only_uncompleted client.tasks.get_tasks(section: section.gid, **) end |
#tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) ⇒ Hash{[String, nil] => Enumerable<Asana::Resources::Task>}
Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/checkoff/sections.rb', line 85 def tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) raise ArgumentError, 'Provided nil workspace name' if workspace_name.nil? raise ArgumentError, 'Provided nil project name' if project_name.nil? project = project_or_raise(workspace_name, project_name) if project_name == :my_tasks my_tasks.tasks_by_section_for_my_tasks(project, only_uncompleted: only_uncompleted, extra_fields: extra_fields) else tasks_by_section_for_project(project, only_uncompleted: only_uncompleted, extra_fields: extra_fields) end end |
#tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
105 106 107 108 109 110 111 112 |
# File 'lib/checkoff/sections.rb', line 105 def tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) = projects. [:options][:fields] += extra_fields [:completed_since] = '9999-12-01' if only_uncompleted client.tasks.get_tasks(section: section_gid, **) end |