Class: Checkoff::Tags
- Inherits:
-
Object
- Object
- Checkoff::Tags
- 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
-
#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
constructor
A new instance of Tags.
-
#tag(workspace_name, tag_name) ⇒ Asana::Resources::Tag?
@sg-ignore.
- #tag_or_raise(workspace_name, tag_name) ⇒ Asana::Resources::Tag
- #tasks(workspace_name, tag_name, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
- #tasks_by_tag_gid(workspace_name, tag_gid, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/checkoff/tags.rb', line 32 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
.run ⇒ void
This method returns an undefined value.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/checkoff/tags.rb', line 133 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') = Checkoff::Tags.new tag = .tag_or_raise(workspace_name, tag_name) puts "Results: #{tag}" end |
Instance Method Details
#tag(workspace_name, tag_name) ⇒ Asana::Resources::Tag?
@sg-ignore
92 93 94 95 96 |
# File 'lib/checkoff/tags.rb', line 92 def tag(workspace_name, tag_name) workspace = workspaces.workspace_or_raise(workspace_name) = client..(workspace_gid: workspace.gid) .find { |tag| tag.name == tag_name } end |
#tag_or_raise(workspace_name, tag_name) ⇒ Asana::Resources::Tag
78 79 80 81 82 83 84 |
# File 'lib/checkoff/tags.rb', line 78 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>
48 49 50 51 52 53 54 55 56 |
# File 'lib/checkoff/tags.rb', line 48 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>
64 65 66 67 68 69 70 71 72 |
# File 'lib/checkoff/tags.rb', line 64 def tasks_by_tag_gid(workspace_name, tag_gid, only_uncompleted: true, extra_fields: []) = projects.(extra_fields:, only_uncompleted:) params = build_params() Asana::Resources::Collection.new(parse(client.get("/tags/#{tag_gid}/tasks", params:, options: [:options])), type: Asana::Resources::Task, client:) end |