Class: Checkoff::Sections
- Inherits:
-
Object
- Object
- Checkoff::Sections
- Extended by:
- CacheMethod::ClassMethods, Forwardable
- Includes:
- Logging
- Defined in:
- lib/checkoff/sections.rb,
sig/checkoff.rbs
Overview
Query different sections of Asana projects
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- REALLY_LONG_CACHE_TIME =
MINUTE * 30
- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE * 5
Instance Attribute Summary collapse
-
#client ⇒ Asana::Client
readonly
sord warn - Asana::Client wasn't able to be resolved to a constant in this project.
- #my_tasks ⇒ Checkoff::MyTasks readonly
- #projects ⇒ Checkoff::Projects readonly
- #time ⇒ Class<Time> readonly
- #workspaces ⇒ Checkoff::Workspaces readonly
Instance Method Summary collapse
- #as_cache_key ⇒ Hash
-
#by_section(tasks, project_gid) ⇒ ::Hash[String?, ::Enumerable[Asana::Resources::Task]]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Given a list of tasks, pull a Hash of tasks with section name -> task list.
-
#debug ⇒ void
@param
message. -
#error ⇒ void
@param
message. -
#file_task_by_section(by_section, task, project_gid) ⇒ void
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
by_section. -
#finer ⇒ void
@param
message. -
#info ⇒ void
@param
message. -
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config:).client, projects: Checkoff::Projects.new(config:, client:), workspaces: Checkoff::Workspaces.new(config:, client:), time: Time) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param
config. - #log_level ⇒ Symbol
- #logger ⇒ ::Logger
-
#parse(response) ⇒ ::Array[::Hash[untyped, untyped]]
sord warn - Asana::HttpClient::Response wasn't able to be resolved to a constant in this project https://github.com/Asana/ruby-asana/blob/master/lib/asana/resource_includes/response_helper.rb#L7.
-
#previous_section(section) ⇒ Asana::Resources::Section?
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param
section. -
#project_or_raise(workspace_name, project_name) ⇒ Asana::Resources::Project
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
workspace_name. -
#section(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Object
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param
workspace_name. -
#section_by_gid(gid) ⇒ Asana::Resources::Section?
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param
gid. -
#section_key(name) ⇒ String?
@param
name. -
#section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Object
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project @param
workspace_name. -
#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]
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project 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]
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project Returns a list of Asana API section objects for a given project.
-
#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Object
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Pulls task objects from a specified section.
-
#tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) ⇒ Object
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project 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_for_project(project, only_uncompleted: true, extra_fields: []) ⇒ ::Hash[String?, ::Enumerable[Asana::Resources::Task]]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Given a project object, pull all tasks, 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]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
section_gid. -
#warn ⇒ void
@param
message.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config:).client, projects: Checkoff::Projects.new(config:, client:), workspaces: Checkoff::Workspaces.new(config:, client:), time: Time) ⇒ Object
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
@param config
@param client
@param projects
@param workspaces
@param time
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/checkoff/sections.rb', line 47 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config:).client, projects: Checkoff::Projects.new(config:, client:), workspaces: Checkoff::Workspaces.new(config:, client:), time: Time) @projects = projects @workspaces = workspaces @my_tasks = Checkoff::MyTasks .new(config:, projects:, client:) @client = client @time = time end |
Instance Attribute Details
#client ⇒ Asana::Client (readonly)
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
248 249 250 |
# File 'lib/checkoff/sections.rb', line 248 def client @client end |
#my_tasks ⇒ Checkoff::MyTasks (readonly)
40 41 42 |
# File 'lib/checkoff/sections.rb', line 40 def my_tasks @my_tasks end |
#projects ⇒ Checkoff::Projects (readonly)
31 32 33 |
# File 'lib/checkoff/sections.rb', line 31 def projects @projects end |
#time ⇒ Class<Time> (readonly)
37 38 39 |
# File 'lib/checkoff/sections.rb', line 37 def time @time end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
34 35 36 |
# File 'lib/checkoff/sections.rb', line 34 def workspaces @workspaces end |
Instance Method Details
#as_cache_key ⇒ Hash
215 216 217 |
# File 'lib/checkoff/sections.rb', line 215 def as_cache_key {} end |
#by_section(tasks, project_gid) ⇒ ::Hash[String?, ::Enumerable[Asana::Resources::Task]]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Given a list of tasks, pull a Hash of tasks with section name -> task list
@param tasks
@param project_gid
270 271 272 273 274 275 276 277 |
# File 'lib/checkoff/sections.rb', line 270 def by_section(tasks, project_gid) by_section = {} sections = client.sections.get_sections_for_project(project_gid:, options: { fields: ['name'] }) sections.each_entry { |section| by_section[section_key(section.name)] = [] } tasks.each { |task| file_task_by_section(by_section, task, project_gid) } by_section end |
#debug ⇒ void
This method returns an undefined value.
@param message
1208 |
# File 'sig/checkoff.rbs', line 1208
def debug: (?Object? message) -> void
|
#error ⇒ void
This method returns an undefined value.
@param message
1199 |
# File 'sig/checkoff.rbs', line 1199
def error: (?Object? message) -> void
|
#file_task_by_section(by_section, task, project_gid) ⇒ void
This method returns an undefined value.
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param by_section
@param task
@param project_gid
284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/checkoff/sections.rb', line 284 def file_task_by_section(by_section, task, project_gid) membership = task.memberships.find do |m| m.fetch('project')['gid'] == project_gid end raise "Could not find task in project_gid #{project_gid}: #{task}" if membership.nil? section = membership.fetch('section') section_name = section.fetch('name') # @type [String, nil] current_section = section_key(section_name) by_section.fetch(current_section) << task end |
#finer ⇒ void
This method returns an undefined value.
@param message
1211 |
# File 'sig/checkoff.rbs', line 1211
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
1205 |
# File 'sig/checkoff.rbs', line 1205
def info: (?Object? message) -> void
|
#log_level ⇒ Symbol
1213 |
# File 'sig/checkoff.rbs', line 1213
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
1196 |
# File 'sig/checkoff.rbs', line 1196
def logger: () -> ::Logger
|
#parse(response) ⇒ ::Array[::Hash[untyped, untyped]]
sord warn - Asana::HttpClient::Response wasn't able to be resolved to a constant in this project https://github.com/Asana/ruby-asana/blob/master/lib/asana/resource_includes/response_helper.rb#L7
@param response
239 240 241 242 243 244 245 |
# File 'lib/checkoff/sections.rb', line 239 def parse(response) data = response.body.fetch('data') do raise("Unexpected response body: #{response.body}") end extra = response.body.except('data') [data, extra] end |
#previous_section(section) ⇒ Asana::Resources::Section?
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
@param section
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/checkoff/sections.rb', line 188 def previous_section(section) project_sections = sections_by_project_gid(section.project.fetch('gid')) # @type [Array<Asana::Resources::Section>] project_sections_arr = project_sections.to_a index = project_sections_arr.find_index { |s| s.gid == section.gid } return nil if index.nil? || index.zero? project_sections_arr[index - 1] end |
#project_or_raise(workspace_name, project_name) ⇒ Asana::Resources::Project
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param workspace_name
@param project_name
302 303 304 305 306 307 308 309 310 311 |
# File 'lib/checkoff/sections.rb', line 302 def project_or_raise(workspace_name, project_name) raise ArgumentError, 'Provide nil project_name' if T.unsafe(project_name).nil? project = projects.project(workspace_name, project_name) if project.nil? raise "Could not find project #{project_name.inspect} " \ "under workspace #{workspace_name}" end project end |
#section(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Object
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
@param workspace_name
@param project_name
@param section_name
@param extra_section_fields
225 226 227 228 229 |
# File 'lib/checkoff/sections.rb', line 225 def section(workspace_name, project_name, section_name, extra_section_fields: []) sections = sections_or_raise(workspace_name, project_name, extra_fields: extra_section_fields) sections.find { |section| section_key(T.cast(section.name, String))&.chomp(':') == section_name&.chomp(':') } end |
#section_by_gid(gid) ⇒ Asana::Resources::Section?
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
@param gid
204 205 206 207 208 209 210 211 |
# File 'lib/checkoff/sections.rb', line 204 def section_by_gid(gid) = {} Asana::Resources::Section.new(parse(client.get("/sections/#{gid}", options:)).first, client:) rescue Asana::Errors::NotFound => e debug e nil end |
#section_key(name) ⇒ String?
@param name
178 179 180 181 182 183 |
# File 'lib/checkoff/sections.rb', line 178 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: []) ⇒ Object
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project
@param workspace_name
@param project_name
@param section_name
@param extra_section_fields
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/checkoff/sections.rb', line 162 def section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) s = section(workspace_name, project_name, section_name, 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.
@param workspace_name
@param project_name
@param section_name
150 151 152 153 |
# File 'lib/checkoff/sections.rb', line 150 def section_task_names(workspace_name, project_name, section_name) task_array = tasks(workspace_name, project_name, section_name) task_array.filter_map(&:name) end |
#sections_by_project_gid(project_gid, extra_fields: []) ⇒ ::Enumerable[Asana::Resources::Section]
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project Returns a list of Asana API section objects for a given project GID
@param project_gid
@param extra_fields
79 80 81 82 83 |
# File 'lib/checkoff/sections.rb', line 79 def sections_by_project_gid(project_gid, extra_fields: []) fields = (%w[name] + extra_fields).sort.uniq client.sections.get_sections_for_project(project_gid:, options: { fields: }) end |
#sections_or_raise(workspace_name, project_name, extra_fields: []) ⇒ ::Enumerable[Asana::Resources::Section]
sord warn - Asana::Resources::Section wasn't able to be resolved to a constant in this project Returns a list of Asana API section objects for a given project
@param workspace_name
@param project_name
@param extra_fields
68 69 70 71 |
# File 'lib/checkoff/sections.rb', line 68 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:) end |
#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Object
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Pulls task objects from a specified section
@param workspace_name
@param project_name
@param section_name
@param only_uncompleted
@param extra_fields
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/checkoff/sections.rb', line 130 def tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) section = section_or_raise(workspace_name, project_name, section_name) = projects.(extra_fields:, only_uncompleted:) # Note: 30 minute cache time on a raw Enumerable from SDK gives # 'Your pagination token has expired' errors. So we go ahead # and eagerly evaluate here so we can enjoy the cache. client.tasks.get_tasks(section: section.gid, **).to_a end |
#tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) ⇒ Object
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks
@param workspace_name
@param project_name
@param only_uncompleted
@param extra_fields
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/checkoff/sections.rb', line 93 def tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) raise ArgumentError, 'Provided nil workspace name' if T.unsafe(workspace_name).nil? raise ArgumentError, 'Provided nil project name' if T.unsafe(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:, extra_fields:) else tasks_by_section_for_project(project, only_uncompleted:, extra_fields:) end end |
#tasks_by_section_for_project(project, only_uncompleted: true, extra_fields: []) ⇒ ::Hash[String?, ::Enumerable[Asana::Resources::Task]]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Given a project object, pull all tasks, then provide a Hash of tasks with section name -> task list of the uncompleted tasks
@param project
@param only_uncompleted
@param extra_fields
256 257 258 259 260 261 262 263 264 |
# File 'lib/checkoff/sections.rb', line 256 def tasks_by_section_for_project(project, only_uncompleted: true, extra_fields: []) raw_tasks = projects.tasks_from_project(project, only_uncompleted:, extra_fields:) active_tasks = projects.active_tasks(raw_tasks) by_section(active_tasks, project.gid) end |
#tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param section_gid
@param only_uncompleted
@param extra_fields
113 114 115 116 117 118 119 |
# File 'lib/checkoff/sections.rb', line 113 def tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) = projects.(extra_fields:, only_uncompleted:) client.tasks.get_tasks(section: section_gid, **) end |
#warn ⇒ void
This method returns an undefined value.
@param message
1202 |
# File 'sig/checkoff.rbs', line 1202
def warn: (?Object? message) -> void
|