Class: Checkoff::Tags

Inherits:
Object
  • Object
show all
Extended by:
CacheMethod::ClassMethods
Defined in:
lib/checkoff/tags.rb

Overview

Work with tags in Asana

Constant Summary collapse

MINUTE =
60
HOUR =
T.let(MINUTE * 60, Numeric)
DAY =
T.let(24 * HOUR, Numeric)
REALLY_LONG_CACHE_TIME =
T.let(HOUR * 1, Numeric)
LONG_CACHE_TIME =
T.let(MINUTE * 15, Numeric)
SHORT_CACHE_TIME =
T.let(MINUTE, Numeric)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.client, projects: Checkoff::Projects.new(config:, client:), workspaces: Checkoff::Workspaces.new(config:, client:)) ⇒ Tags

Returns a new instance of Tags.

Parameters:



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

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

Class Method Details

.runvoid

This method returns an undefined value.



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/checkoff/tags.rb', line 137

def run
  # @sg-ignore
  # @type [String]
  workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  # @sg-ignore
  # @type [String]
  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) ⇒ Asana::Resources::Tag?

@sg-ignore

Parameters:

  • workspace_name (String)
  • tag_name (String)

Returns:

  • (Asana::Resources::Tag, nil)


96
97
98
99
100
# File 'lib/checkoff/tags.rb', line 96

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) ⇒ Asana::Resources::Tag

Parameters:

  • workspace_name (String)
  • tag_name (String)

Returns:

  • (Asana::Resources::Tag)


82
83
84
85
86
87
88
# File 'lib/checkoff/tags.rb', line 82

def tag_or_raise(workspace_name, tag_name)
  t = tag(workspace_name, tag_name)

  raise "Could not find tag #{tag_name} under workspace #{workspace_name}." if t.nil?

  t
end

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

Parameters:

  • workspace_name (String)
  • tag_name (String)
  • only_uncompleted (Boolean) (defaults to: true)
  • extra_fields (Array<String>) (defaults to: [])

Returns:

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


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

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

  tasks_by_tag_gid(workspace_name, tag_gid,
                   only_uncompleted:, extra_fields:)
end

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

Parameters:

  • workspace_name (String)
  • tag_gid (String)
  • only_uncompleted (Boolean) (defaults to: true)
  • extra_fields (Array<String>) (defaults to: [])

Returns:

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


68
69
70
71
72
73
74
75
76
# File 'lib/checkoff/tags.rb', line 68

def tasks_by_tag_gid(workspace_name, tag_gid, only_uncompleted: true, extra_fields: [])
  options = projects.task_options(extra_fields:,
                                  only_uncompleted:)
  params = build_params(options)
  Asana::Resources::Collection.new(parse(client.get("/tags/#{tag_gid}/tasks",
                                                    params:, options: options[:options])),
                                   type: Asana::Resources::Task,
                                   client:)
end