Class: Checkoff::CustomFields

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/custom_fields.rb

Overview

Work with custom fields 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) ⇒ CustomFields

Returns a new instance of CustomFields.



23
24
25
26
27
28
29
# File 'lib/checkoff/custom_fields.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/custom_fields.rb', line 53

def run
  workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  custom_field_name = ARGV[1] || raise('Please pass custom_field name as second argument')
  custom_fields = Checkoff::CustomFields.new
  custom_field = custom_fields.custom_field_or_raise(workspace_name, custom_field_name)
  puts "Results: #{custom_field}"
end

Instance Method Details

#custom_field(workspace_name, custom_field_name) ⇒ Object



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

def custom_field(workspace_name, custom_field_name)
  workspace = workspaces.workspace_or_raise(workspace_name)
  custom_fields = client.custom_fields.get_custom_fields_for_workspace(workspace_gid: workspace.gid)
  custom_fields.find { |custom_field| custom_field.name == custom_field_name }
end

#custom_field_or_raise(workspace_name, custom_field_name) ⇒ Object



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

def custom_field_or_raise(workspace_name, custom_field_name)
  custom_field = custom_field(workspace_name, custom_field_name)
  raise "Could not find custom_field #{custom_field_name} under workspace #{workspace_name}." if custom_field.nil?

  custom_field
end