Class: Checkoff::Tags

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/tags.rb

Overview

Work with tags in Asana

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), clients: Checkoff::Clients.new(config: config), client: clients.client, projects: Checkoff::Projects.new(config: config, client: client), workspaces: Checkoff::Workspaces.new(config: config, client: client)) ⇒ Tags

Returns a new instance of Tags.



23
24
25
26
27
28
29
30
31
# File 'lib/checkoff/tags.rb', line 23

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               clients: Checkoff::Clients.new(config: config),
               client: clients.client,
               projects: Checkoff::Projects.new(config: config, client: client),
               workspaces: Checkoff::Workspaces.new(config: config, client: client))
  @workspaces = workspaces
  @projects = projects
  @client = client
end

Class Method Details

.runObject



90
91
92
93
94
95
96
# File 'lib/checkoff/tags.rb', line 90

def run
  workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  tag_name = ARGV[1] || raise('Please pass tag name as second argument')
  tags = Checkoff::Tags.new
  tag = tags.tag_or_raise(workspace_name, tag_name)
  puts "Results: #{tag}"
end

Instance Method Details

#tag(workspace_name, tag_name) ⇒ Object



57
58
59
60
61
# File 'lib/checkoff/tags.rb', line 57

def tag(workspace_name, tag_name)
  workspace = workspaces.workspace_or_raise(workspace_name)
  tags = client.tags.get_tags_for_workspace(workspace_gid: workspace.gid)
  tags.find { |tag| tag.name == tag_name }
end

#tag_or_raise(workspace_name, tag_name) ⇒ Object



49
50
51
52
53
54
# File 'lib/checkoff/tags.rb', line 49

def tag_or_raise(workspace_name, tag_name)
  tag = tag(workspace_name, tag_name)
  raise "Could not find tag #{tag_name} under workspace #{workspace_name}." if tag.nil?

  tag
end

#tasks(workspace_name, tag_name, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>

Returns:

  • (Enumerable<Asana::Resources::Task>)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/checkoff/tags.rb', line 34

def tasks(workspace_name, tag_name,
          only_uncompleted: true,
          extra_fields: [])
  tag = tag_or_raise(workspace_name, tag_name)

  options = build_task_options(projects.task_options, extra_fields, only_uncompleted)

  params = build_params(options)

  Asana::Collection.new(parse(client.get("/tags/#{tag.gid}/tasks",
                                         params: params, options: options[:options])),
                        type: Asana::Resources::Task,
                        client: client)
end