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]]
@param
extra_fields. -
#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
- #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
216 217 218 |
# File 'lib/checkoff/task_searches.rb', line 216 def client @client end |
#projects ⇒ Checkoff::Projects (readonly)
212 213 214 |
# File 'lib/checkoff/task_searches.rb', line 212 def projects @projects end |
#task_selectors ⇒ Checkoff::TaskSelectors (readonly)
210 211 212 |
# File 'lib/checkoff/task_searches.rb', line 210 def task_selectors @task_selectors end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
214 215 216 |
# File 'lib/checkoff/task_searches.rb', line 214 def workspaces @workspaces end |
Class Method Details
.run ⇒ void
This method returns an undefined value.
197 198 199 200 201 202 203 204 205 |
# File 'lib/checkoff/task_searches.rb', line 197 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
124 125 126 127 128 129 130 131 132 |
# File 'lib/checkoff/task_searches.rb', line 124 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
109 110 111 |
# File 'lib/checkoff/task_searches.rb', line 109 def as_cache_key {} end |
#calculate_api_options(extra_fields) ⇒ ::Hash[Symbol, ::Array[String]]
@param extra_fields
189 190 191 |
# File 'lib/checkoff/task_searches.rb', line 189 def (extra_fields) { fields: projects.task_fields(extra_fields: ['custom_fields'] + extra_fields) } end |
#debug ⇒ void
This method returns an undefined value.
@param message
1898 |
# File 'sig/checkoff.rbs', line 1898
def debug: (?Object? message) -> void
|
#error ⇒ void
This method returns an undefined value.
@param message
1889 |
# File 'sig/checkoff.rbs', line 1889
def error: (?Object? message) -> void
|
#finer ⇒ void
This method returns an undefined value.
@param message
1901 |
# File 'sig/checkoff.rbs', line 1901
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
1895 |
# File 'sig/checkoff.rbs', line 1895
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
151 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 |
# File 'lib/checkoff/task_searches.rb', line 151 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
1903 |
# File 'sig/checkoff.rbs', line 1903
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
1886 |
# File 'sig/checkoff.rbs', line 1886
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
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/checkoff/task_searches.rb', line 92 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 |
# 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}" } raw_task_search(api_params, workspace_gid: workspace.gid, task_selector:, extra_fields:) end |
#warn ⇒ void
This method returns an undefined value.
@param message
1892 |
# File 'sig/checkoff.rbs', line 1892
def warn: (?Object? message) -> void
|