Class: Checkoff::TaskSearches

Inherits:
Object
  • Object
show all
Includes:
Asana::Resources::ResponseHelper
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

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.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/checkoff/task_searches.rb', line 30

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

.runObject



72
73
74
75
76
77
78
# File 'lib/checkoff/task_searches.rb', line 72

def run
  workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  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

#task_search(workspace_name, url, extra_fields: []) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/checkoff/task_searches.rb', line 46

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)
  path = "/workspaces/#{workspace.gid}/tasks/search"
  options = calculate_api_options(extra_fields)
  tasks = @asana_resources_collection_class.new(parse(client.get(path,
                                                                 params: api_params,
                                                                 options: options)),
                                                type: Asana::Resources::Task,
                                                client: client)
  tasks.select { |task| task_selectors.filter_via_task_selector(task, task_selector) }
end