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.
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
.run ⇒ void
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') = 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
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) = client..(workspace_gid: workspace.gid) .find { |tag| tag.name == tag_name } end |
#tag_or_raise(workspace_name, tag_name) ⇒ 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>
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>
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: []) = 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 |