Class: Checkoff::TaskSearches
- Inherits:
-
Object
- Object
- Checkoff::TaskSearches
- Extended by:
- CacheMethod::ClassMethods
- Includes:
- Asana::Resources::ResponseHelper, Logging
- Defined in:
- lib/checkoff/task_searches.rb,
sig/checkoff.rbs
Overview
Run task searches against the Asana API
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- DAY =
24 * HOUR
- REALLY_LONG_CACHE_TIME =
HOUR- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE
Instance Attribute Summary collapse
-
#client ⇒ Asana::Client
readonly
sord warn - Asana::Client wasn't able to be resolved to a constant in this project.
- #projects ⇒ Checkoff::Projects readonly
- #task_selectors ⇒ Checkoff::TaskSelectors readonly
- #workspaces ⇒ Checkoff::Workspaces readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#api_task_search_request(api_params, workspace_gid:, extra_fields:) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform a search using the Asana Task Search API:.
- #as_cache_key ⇒ Hash
-
#calculate_api_options(extra_fields) ⇒ ::Hash[Symbol, ::Array[String]]
@sg-ignore return type could not be inferred — bracket access on a HashSymbol=>undefined local doesn't narrow even with a T.cast on the return expression.
-
#debug ⇒ void
@param
message. -
#error ⇒ void
@param
message. -
#finer ⇒ void
@param
message. -
#info ⇒ void
@param
message. -
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), task_selectors: Checkoff::TaskSelectors.new(config:), projects: Checkoff::Projects.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client, search_url_parser: Checkoff::Internal::SearchUrl::Parser.new, asana_resources_collection_class: Asana::Resources::Collection) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Collection wasn't able to be resolved to a constant in this project @param
config. -
#iterated_raw_task_search(api_params, workspace_gid:, extra_fields:) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform a search using the Asana Task Search API and use manual pagination to ensure all results are returned:.
-
#log_level ⇒ Symbol
@sg-ignore return type could not be inferred — cascades from the ENV.fetch RBS gap below.
- #logger ⇒ ::Logger
-
#raw_task_search(api_params, workspace_gid:, extra_fields: [], task_selector: [], fetch_all: true) ⇒ Object
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform a search using the Asana Task Search API:.
-
#task_search(workspace_name, url, extra_fields: []) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform an equivalent search API to an Asana search URL in the web UI.
-
#warn ⇒ void
@param
message.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), task_selectors: Checkoff::TaskSelectors.new(config:), projects: Checkoff::Projects.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client, search_url_parser: Checkoff::Internal::SearchUrl::Parser.new, asana_resources_collection_class: Asana::Resources::Collection) ⇒ Object
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Collection wasn't able to be resolved to a constant in this project
@param config
@param workspaces
@param task_selectors
@param projects
@param clients
@param client
@param search_url_parser
@param asana_resources_collection_class
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/checkoff/task_searches.rb', line 44 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), task_selectors: Checkoff::TaskSelectors.new(config:), projects: Checkoff::Projects.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client, search_url_parser: Checkoff::Internal::SearchUrl::Parser.new, asana_resources_collection_class: Asana::Resources::Collection) @workspaces = workspaces @task_selectors = task_selectors @projects = projects @client = client @search_url_parser = search_url_parser @asana_resources_collection_class = asana_resources_collection_class end |
Instance Attribute Details
#client ⇒ Asana::Client (readonly)
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
223 224 225 |
# File 'lib/checkoff/task_searches.rb', line 223 def client @client end |
#projects ⇒ Checkoff::Projects (readonly)
219 220 221 |
# File 'lib/checkoff/task_searches.rb', line 219 def projects @projects end |
#task_selectors ⇒ Checkoff::TaskSelectors (readonly)
217 218 219 |
# File 'lib/checkoff/task_searches.rb', line 217 def task_selectors @task_selectors end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
221 222 223 |
# File 'lib/checkoff/task_searches.rb', line 221 def workspaces @workspaces end |
Class Method Details
.run ⇒ void
This method returns an undefined value.
204 205 206 207 208 209 210 211 212 |
# File 'lib/checkoff/task_searches.rb', line 204 def run # @type [String] workspace_name = ARGV[0] || raise('Please pass workspace name as first argument') # @type [String] url = ARGV[1] || raise('Please pass task search URL as second argument') task_searches = Checkoff::TaskSearches.new task_search = task_searches.task_search(workspace_name, url) puts "Results: #{task_search}" end |
Instance Method Details
#api_task_search_request(api_params, workspace_gid:, extra_fields:) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform a search using the Asana Task Search API:
https://developers.asana.com/reference/searchtasksforworkspace
@param api_params
@param workspace_gid
@param extra_fields
127 128 129 130 131 132 133 134 135 |
# File 'lib/checkoff/task_searches.rb', line 127 def api_task_search_request(api_params, workspace_gid:, extra_fields:) path = "/workspaces/#{workspace_gid}/tasks/search" = (extra_fields) @asana_resources_collection_class.new(parse(client.get(path, params: api_params, options:)), type: Asana::Resources::Task, client:) end |
#as_cache_key ⇒ Hash
112 113 114 |
# File 'lib/checkoff/task_searches.rb', line 112 def as_cache_key {} end |
#calculate_api_options(extra_fields) ⇒ ::Hash[Symbol, ::Array[String]]
@sg-ignore return type could not be inferred — bracket access on a HashSymbol=>undefined local doesn't narrow even with a T.cast on the return expression
@param extra_fields
194 195 196 197 198 |
# File 'lib/checkoff/task_searches.rb', line 194 def (extra_fields) # @type [Hash{Symbol => undefined}] = projects.(extra_fields: ['custom_fields'] + extra_fields) [:options] end |
#debug ⇒ void
This method returns an undefined value.
@param message
1932 |
# File 'sig/checkoff.rbs', line 1932
def debug: (?Object? message) -> void
|
#error ⇒ void
This method returns an undefined value.
@param message
1923 |
# File 'sig/checkoff.rbs', line 1923
def error: (?Object? message) -> void
|
#finer ⇒ void
This method returns an undefined value.
@param message
1935 |
# File 'sig/checkoff.rbs', line 1935
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
1929 |
# File 'sig/checkoff.rbs', line 1929
def info: (?Object? message) -> void
|
#iterated_raw_task_search(api_params, workspace_gid:, extra_fields:) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform a search using the Asana Task Search API and use manual pagination to ensure all results are returned:
https://developers.asana.com/reference/searchtasksforworkspace
"However, you can paginate manually by sorting the search
results by their creation time and then modifying each
subsequent query to exclude data you have already seen." -
see sort_by field at
https://developers.asana.com/reference/searchtasksforworkspace
@param api_params
@param workspace_gid
@param url
@param extra_fields
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/checkoff/task_searches.rb', line 154 def iterated_raw_task_search(api_params, workspace_gid:, extra_fields:) # https://developers.asana.com/reference/searchtasksforworkspace tasks = [] new_api_params = api_params.dup original_sort_by = new_api_params.delete('sort_by') # defaults to false original_sort_ascending = new_api_params.delete('sort_ascending') original_created_at_before = new_api_params.delete('created_at.before') raise 'Teach me how to handle original_created_at_before' unless original_created_at_before.nil? new_api_params['sort_by'] = 'created_at' Kernel.loop do # Get the most recently created results, then iterate on until we're out of results # @type [Array<Asana::Resources::Task>] task_batch = raw_task_search(new_api_params, workspace_gid:, extra_fields: extra_fields + ['created_at'], fetch_all: false).to_a oldest = task_batch.to_a.last break if oldest.nil? new_api_params['created_at.before'] = oldest.created_at tasks.concat(task_batch.to_a) end unless original_sort_by.nil? || original_sort_by == 'created_at' raise "Teach me how to handle original_sort_by: #{original_sort_by.inspect}" end raise 'Teach me how to handle original_sort_ascending' unless original_sort_ascending.nil? tasks end |
#log_level ⇒ Symbol
@sg-ignore return type could not be inferred — cascades from the ENV.fetch RBS gap below
1938 |
# File 'sig/checkoff.rbs', line 1938
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
1920 |
# File 'sig/checkoff.rbs', line 1920
def logger: () -> ::Logger
|
#raw_task_search(api_params, workspace_gid:, extra_fields: [], task_selector: [], fetch_all: true) ⇒ Object
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform a search using the Asana Task Search API:
https://developers.asana.com/reference/searchtasksforworkspace
@param api_params
@param workspace_gid
@param extra_fields
@param task_selector
@param fetch_all — Ensure all results are provided by manually paginating
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/checkoff/task_searches.rb', line 95 def raw_task_search(api_params, workspace_gid:, extra_fields: [], task_selector: [], fetch_all: true) tasks = api_task_search_request(api_params, workspace_gid:, extra_fields:) tasks = iterated_raw_task_search(api_params, workspace_gid:, extra_fields:) if fetch_all && tasks.count == 100 debug { "#{tasks.count} raw tasks returned" } return tasks if task_selector.empty? tasks.select do |task| task_selectors.filter_via_task_selector(task, task_selector) end end |
#task_search(workspace_name, url, extra_fields: []) ⇒ ::Enumerable[Asana::Resources::Task]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project Perform an equivalent search API to an Asana search URL in the web UI. Not all URL parameters are supported; each one must be added here manually. In addition, not all are supported in the Asana API in a compatible way, so they may result in more tasks being fetched than actually returned as filtering is done manually.
@param workspace_name
@param url
@param extra_fields
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/checkoff/task_searches.rb', line 72 def task_search(workspace_name, url, extra_fields: []) workspace = workspaces.workspace_or_raise(workspace_name) api_params, task_selector = @search_url_parser.convert_params(url) debug { "Task search params: api_params=#{api_params}, task_selector=#{task_selector}" } # @sg-ignore task_selector expected Symbol,Array<Symbol,Integer,Array> received # Hash{String=>String} — Solargraph mis-assigns tuple-destructured types from # `api_params, task_selector = @search_url_parser.convert_params(url)` above raw_task_search(api_params, workspace_gid: workspace.gid, task_selector:, extra_fields:) end |
#warn ⇒ void
This method returns an undefined value.
@param message
1926 |
# File 'sig/checkoff.rbs', line 1926
def warn: (?Object? message) -> void
|