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
@sg-ignore.
- #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 @sg-ignore projects.project may be nil but is raised below.
-
#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 @sg-ignore section() is nil-checked below.
-
#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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/checkoff/sections.rb', line 42 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)
35 36 37 |
# File 'lib/checkoff/sections.rb', line 35 def my_tasks @my_tasks end |
#projects ⇒ Checkoff::Projects (readonly)
26 27 28 |
# File 'lib/checkoff/sections.rb', line 26 def projects @projects end |
#time ⇒ Class<Time> (readonly)
32 33 34 |
# File 'lib/checkoff/sections.rb', line 32 def time @time end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
29 30 31 |
# File 'lib/checkoff/sections.rb', line 29 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
1223 |
# File 'sig/checkoff.rbs', line 1223
def debug: (?Object? message) -> void
|
#error ⇒ void
This method returns an undefined value.
@param message
1214 |
# File 'sig/checkoff.rbs', line 1214
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 298 299 300 |
# File 'lib/checkoff/sections.rb', line 284 def file_task_by_section(by_section, task, project_gid) membership = task.memberships.find do |m| membership_hash = T.unsafe(m) T.cast(membership_hash['project'], T::Hash[String, T.untyped])['gid'] == project_gid end raise "Could not find task in project_gid #{project_gid}: #{task}" if membership.nil? membership_data = T.unsafe(membership) section = T.cast(membership_data['section'], T::Hash[String, T.untyped]) section_name = T.cast(section['name'], String) # @type [String, nil] current_section = section_key(section_name) # @sg-ignore by_section.fetch(current_section) << task end |
#finer ⇒ void
This method returns an undefined value.
@param message
1226 |
# File 'sig/checkoff.rbs', line 1226
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
1220 |
# File 'sig/checkoff.rbs', line 1220
def info: (?Object? message) -> void
|
#log_level ⇒ Symbol
@sg-ignore
1229 |
# File 'sig/checkoff.rbs', line 1229
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
1211 |
# File 'sig/checkoff.rbs', line 1211
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
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/checkoff/sections.rb', line 186 def previous_section(section) sections = sections_by_project_gid(section.project.fetch('gid')) # @type [Array<Asana::Resources::Section>] # @sg-ignore sections = sections.to_a index = sections.find_index { |s| s.gid == section.gid } return nil if index.nil? || index.zero? # @sg-ignore sections[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 @sg-ignore projects.project may be nil but is raised below
@param workspace_name
@param project_name
306 307 308 309 310 311 312 313 314 315 |
# File 'lib/checkoff/sections.rb', line 306 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
176 177 178 179 180 181 |
# File 'lib/checkoff/sections.rb', line 176 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 @sg-ignore section() is nil-checked below
@param workspace_name
@param project_name
@param section_name
@param extra_section_fields
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/checkoff/sections.rb', line 160 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. @sg-ignore
@param workspace_name
@param project_name
@param section_name
146 147 148 149 150 |
# File 'lib/checkoff/sections.rb', line 146 def section_task_names(workspace_name, project_name, section_name) task_array = tasks(workspace_name, project_name, section_name) # @type [Array<String>] T.cast(task_array.map(&:name), T::Array[String]) 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
74 75 76 77 78 |
# File 'lib/checkoff/sections.rb', line 74 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
63 64 65 66 |
# File 'lib/checkoff/sections.rb', line 63 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
125 126 127 128 129 130 131 132 133 134 135 136 |
# 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.(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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/checkoff/sections.rb', line 88 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
108 109 110 111 112 113 114 |
# File 'lib/checkoff/sections.rb', line 108 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
1217 |
# File 'sig/checkoff.rbs', line 1217
def warn: (?Object? message) -> void
|