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 * 1
- 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, untyped]
@sg-ignore.
-
#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.
- #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
220 221 222 |
# File 'lib/checkoff/task_searches.rb', line 220 def client @client end |
#projects ⇒ Checkoff::Projects (readonly)
216 217 218 |
# File 'lib/checkoff/task_searches.rb', line 216 def projects @projects end |
#task_selectors ⇒ Checkoff::TaskSelectors (readonly)
214 215 216 |
# File 'lib/checkoff/task_searches.rb', line 214 def task_selectors @task_selectors end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
218 219 220 |
# File 'lib/checkoff/task_searches.rb', line 218 def workspaces @workspaces end |
Class Method Details
.run ⇒ void
This method returns an undefined value.
201 202 203 204 205 206 207 208 209 |
# File 'lib/checkoff/task_searches.rb', line 201 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
125 126 127 128 129 130 131 132 133 |
# File 'lib/checkoff/task_searches.rb', line 125 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
110 111 112 |
# File 'lib/checkoff/task_searches.rb', line 110 def as_cache_key {} end |
#calculate_api_options(extra_fields) ⇒ ::Hash[Symbol, untyped]
@sg-ignore
@param extra_fields
191 192 193 194 195 |
# File 'lib/checkoff/task_searches.rb', line 191 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
1920 |
# File 'sig/checkoff.rbs', line 1920
def debug: (?Object? message) -> void
|
#error ⇒ void
This method returns an undefined value.
@param message
1911 |
# File 'sig/checkoff.rbs', line 1911
def error: (?Object? message) -> void
|
#finer ⇒ void
This method returns an undefined value.
@param message
1923 |
# File 'sig/checkoff.rbs', line 1923
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
1917 |
# File 'sig/checkoff.rbs', line 1917
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
152 153 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 |
# File 'lib/checkoff/task_searches.rb', line 152 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
1926 |
# File 'sig/checkoff.rbs', line 1926
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
1908 |
# File 'sig/checkoff.rbs', line 1908
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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/checkoff/task_searches.rb', line 93 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 |
# 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 raw_task_search(api_params, workspace_gid: workspace.gid, task_selector:, extra_fields:) end |
#warn ⇒ void
This method returns an undefined value.
@param message
1914 |
# File 'sig/checkoff.rbs', line 1914
def warn: (?Object? message) -> void
|