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

Returns a new instance of Tags.



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

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

Class Method Details

.runObject



53
54
55
56
57
58
59
# File 'lib/checkoff/tags.rb', line 53

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



39
40
41
42
43
# File 'lib/checkoff/tags.rb', line 39

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



31
32
33
34
35
36
# File 'lib/checkoff/tags.rb', line 31

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