Class: Checkoff::TaskSearches
- Inherits:
-
Object
- Object
- Checkoff::TaskSearches
- Extended by:
- CacheMethod::ClassMethods
- Includes:
- Asana::Resources::ResponseHelper, Logging
- Defined in:
- lib/checkoff/task_searches.rb
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
Class Method Summary collapse
Instance Method Summary collapse
- #as_cache_key ⇒ Hash
-
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config: config), task_selectors: Checkoff::TaskSelectors.new(config: config), projects: Checkoff::Projects.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client, search_url_parser: Checkoff::Internal::SearchUrl::Parser.new, asana_resources_collection_class: Asana::Resources::Collection) ⇒ TaskSearches
constructor
A new instance of TaskSearches.
-
#raw_task_search(api_params, workspace_gid:, extra_fields: [], task_selector: [], fetch_all: true) ⇒ Enumerable<Asana::Resources::Task>
Perform a search using the Asana Task Search API:.
-
#task_search(workspace_name, url, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
Perform an equivalent search API to an Asana search URL in the web UI.
Methods included from Logging
#debug, #error, #finer, #info, #logger, #warn
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config: config), task_selectors: Checkoff::TaskSelectors.new(config: config), projects: Checkoff::Projects.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client, search_url_parser: Checkoff::Internal::SearchUrl::Parser.new, asana_resources_collection_class: Asana::Resources::Collection) ⇒ TaskSearches
Returns a new instance of TaskSearches.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/checkoff/task_searches.rb', line 43 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config: config), task_selectors: Checkoff::TaskSelectors.new(config: config), projects: Checkoff::Projects.new(config: config), clients: Checkoff::Clients.new(config: 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 |
Class Method Details
.run ⇒ void
This method returns an undefined value.
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/checkoff/task_searches.rb', line 206 def run # @sg-ignore # @type [String] workspace_name = ARGV[0] || raise('Please pass workspace name as first argument') # @sg-ignore # @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
#as_cache_key ⇒ Hash
113 114 115 |
# File 'lib/checkoff/task_searches.rb', line 113 def as_cache_key {} end |
#raw_task_search(api_params, workspace_gid:, extra_fields: [], task_selector: [], fetch_all: true) ⇒ Enumerable<Asana::Resources::Task>
Perform a search using the Asana Task Search API:
https://developers.asana.com/reference/searchtasksforworkspace
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/checkoff/task_searches.rb', line 92 def raw_task_search(api_params, workspace_gid:, extra_fields: [], task_selector: [], fetch_all: true) # @sg-ignore tasks = api_task_search_request(api_params, workspace_gid: workspace_gid, extra_fields: extra_fields) if fetch_all && tasks.count == 100 # @sg-ignore tasks = iterated_raw_task_search(api_params, workspace_gid: workspace_gid, extra_fields: extra_fields) end 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>
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.
71 72 73 74 75 76 77 78 |
# File 'lib/checkoff/task_searches.rb', line 71 def task_search(workspace_name, url, extra_fields: []) workspace = workspaces.workspace_or_raise(workspace_name) # @sg-ignore 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: task_selector, extra_fields: extra_fields) end |