Class: Checkoff::Tags

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

Overview

Work with tags in Asana

Constant Summary collapse

MINUTE =

Returns:

  • (Object)
60
HOUR =

Returns:

  • (Object)
T.let(MINUTE * 60, Numeric)
DAY =

Returns:

  • (Object)
T.let(24 * HOUR, Numeric)
REALLY_LONG_CACHE_TIME =

Returns:

  • (Object)
T.let(HOUR * 1, Numeric)
LONG_CACHE_TIME =

Returns:

  • (Object)
T.let(MINUTE * 15, Numeric)
SHORT_CACHE_TIME =

Returns:

  • (Object)
T.let(MINUTE, Numeric)

Instance Attribute Summary collapse

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:)) ⇒ Object

sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param config

@param clients

@param client

@param projects

@param workspaces



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

Instance Attribute Details

#clientAsana::Client (readonly)

sord warn - Asana::Client wasn't able to be resolved to a constant in this project

Returns:

  • (Asana::Client)


110
111
112
# File 'lib/checkoff/tags.rb', line 110

def client
  @client
end

#projectsCheckoff::Projects (readonly)

Returns:



108
109
110
# File 'lib/checkoff/tags.rb', line 108

def projects
  @projects
end

#workspacesCheckoff::Workspaces (readonly)



106
107
108
# File 'lib/checkoff/tags.rb', line 106

def workspaces
  @workspaces
end

Class Method Details

.runvoid

This method returns an undefined value.



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

def run
  # @type [String]
  workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  # @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

#build_params(options) ⇒ ::Hash[Symbol, Object]

@param options

Parameters:

  • options (::Hash[Symbol, Object])

Returns:

  • (::Hash[Symbol, Object])


115
116
117
118
119
120
# File 'lib/checkoff/tags.rb', line 115

def build_params(options)
  { limit: options[:per_page], completed_since: options[:completed_since] }.reject do |_, v|
    # @sg-ignore
    v.nil? || Array(v).empty?
  end
end

#parse(response) ⇒ ::Array[::Hash[untyped, untyped]]

sord warn - Asana::HttpClient::Response wasn't able to be resolved to a constant in this project https://github.com/Asana/ruby-asana/blob/master/lib/asana/resource_includes/response_helper.rb#L7

@param response

Parameters:

  • response (Asana::HttpClient::Response)

Returns:

  • (::Array[::Hash[untyped, untyped]])


127
128
129
130
131
# File 'lib/checkoff/tags.rb', line 127

def parse(response)
  data = response.body.fetch('data')
  extra = response.body.except('data')
  [data, extra]
end

#tag(workspace_name, tag_name) ⇒ Asana::Resources::Tag?

sord warn - Asana::Resources::Tag wasn't able to be resolved to a constant in this project @param workspace_name

@param tag_name

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

sord warn - Asana::Resources::Tag wasn't able to be resolved to a constant in this project @sg-ignore

@param workspace_name

@param tag_name

Parameters:

  • workspace_name (String)
  • tag_name (String)

Returns:

  • (Asana::Resources::Tag)


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

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: []) ⇒ Object

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param workspace_name

@param tag_name

@param only_uncompleted

@param extra_fields



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: []) ⇒ Object

sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param workspace_name

@param tag_gid

@param only_uncompleted

@param extra_fields



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