Class: Checkoff::CustomFields
- Inherits:
-
Object
- Object
- Checkoff::CustomFields
- Extended by:
- CacheMethod::ClassMethods
- Defined in:
- lib/checkoff/custom_fields.rb,
sig/checkoff.rbs
Overview
Work with custom fields in Asana
Constant Summary collapse
- MINUTE =
60- HOUR =
MINUTE * 60
- DAY =
24 * HOUR
- REALLY_LONG_CACHE_TIME =
HOUR- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE
Instance Attribute Summary collapse
-
#client ⇒ Asana::Client
readonly
sord warn - Asana::Client wasn't able to be resolved to a constant in this project.
- #workspaces ⇒ Checkoff::Workspaces readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#custom_field(workspace_name, custom_field_name) ⇒ Asana::Resources::CustomField?
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project @param
workspace_name. -
#custom_field_or_raise(workspace_name, custom_field_name) ⇒ Asana::Resources::CustomField
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project @param
workspace_name. -
#find_gids(custom_field, enum_value) ⇒ ::Array[String]
@param
custom_field. -
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.client, workspaces: Checkoff::Workspaces.new(config:, client:)) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param
config. -
#resource_custom_field_by_gid_or_raise(resource, custom_field_gid) ⇒ ::Hash[String, Object]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
resource. -
#resource_custom_field_by_name(resource, custom_field_name) ⇒ ::Hash[String, Object]?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
resource. -
#resource_custom_field_by_name_or_raise(resource, custom_field_name) ⇒ ::Hash[String, Object]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project @param
resource. -
#resource_custom_field_enum_values(custom_field) ⇒ ::Array[::Hash[untyped, (untyped | String)]]
sord warn - ""resource_subtype"" does not appear to be a type sord warn - "String} & Hashdoes not appear to be a type sord warn - "Hash & Hashdoes not appear to be a type sord warn - "\"gid\"" does not appear to be a type sord warn - "String & Hash{"name"" does not appear to be a type rubocop:disable Layout/LineLength, YARD/TagTypeSyntax rubocop:enable Layout/LineLength, YARD/TagTypeSyntax.
-
#resource_custom_field_values_gids_or_raise(resource, custom_field_gid) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
resource. -
#resource_custom_field_values_names_by_name(resource, custom_field_name) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project @param
resource.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.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 workspaces
@param clients
@param client
31 32 33 34 35 36 37 38 |
# File 'lib/checkoff/custom_fields.rb', line 31 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), clients: Checkoff::Clients.new(config:), client: clients.client, workspaces: Checkoff::Workspaces.new(config:, client:)) @workspaces = workspaces @client = client end |
Instance Attribute Details
#client ⇒ Asana::Client (readonly)
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
170 171 172 |
# File 'lib/checkoff/custom_fields.rb', line 170 def client @client end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
167 168 169 |
# File 'lib/checkoff/custom_fields.rb', line 167 def workspaces @workspaces end |
Class Method Details
.run ⇒ void
This method returns an undefined value.
176 177 178 179 180 181 182 183 184 |
# File 'lib/checkoff/custom_fields.rb', line 176 def run # @type [String] workspace_name = ARGV[0] || raise('Please pass workspace name as first argument') # @type [String] 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) ⇒ Asana::Resources::CustomField?
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project
@param workspace_name
@param custom_field_name
56 57 58 59 60 |
# File 'lib/checkoff/custom_fields.rb', line 56 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) ⇒ Asana::Resources::CustomField
sord warn - Asana::Resources::CustomField wasn't able to be resolved to a constant in this project
@param workspace_name
@param custom_field_name
44 45 46 47 48 49 |
# File 'lib/checkoff/custom_fields.rb', line 44 def custom_field_or_raise(workspace_name, custom_field_name) cf = custom_field(workspace_name, custom_field_name) raise "Could not find custom_field #{custom_field_name} under workspace #{workspace_name}." if cf.nil? cf end |
#find_gids(custom_field, enum_value) ⇒ ::Array[String]
@param custom_field
@param enum_value
158 159 160 161 162 163 164 |
# File 'lib/checkoff/custom_fields.rb', line 158 def find_gids(custom_field, enum_value) if enum_value.nil? [] else [enum_value.fetch('gid')] end end |
#resource_custom_field_by_gid_or_raise(resource, custom_field_gid) ⇒ ::Hash[String, Object]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_gid
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/checkoff/custom_fields.rb', line 119 def resource_custom_field_by_gid_or_raise(resource, custom_field_gid) # @type [Array<Hash{String => Object}>] custom_fields = resource.custom_fields if custom_fields.nil? raise "Could not find custom_fields under project (was 'custom_fields' included in 'extra_fields'?)" end # @type [Hash{String => Object}, nil] matched_custom_field = custom_fields.find { |data| data.fetch('gid') == custom_field_gid } if matched_custom_field.nil? raise "Could not find custom field with gid #{custom_field_gid} " \ "in gid #{resource.gid} with custom fields #{custom_fields}" end matched_custom_field end |
#resource_custom_field_by_name(resource, custom_field_name) ⇒ ::Hash[String, Object]?
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_name
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/checkoff/custom_fields.rb', line 93 def resource_custom_field_by_name(resource, custom_field_name) # @type [Array<Hash{String => Object}>] custom_fields = resource.custom_fields if custom_fields.nil? raise "custom fields not found on resource - did you add 'custom_fields' in your extra_fields argument?" end # @type [Hash{String => Object}, nil] custom_fields.find { |field| field.fetch('name') == custom_field_name } end |
#resource_custom_field_by_name_or_raise(resource, custom_field_name) ⇒ ::Hash[String, Object]
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_name
107 108 109 110 111 112 113 114 |
# File 'lib/checkoff/custom_fields.rb', line 107 def resource_custom_field_by_name_or_raise(resource, custom_field_name) custom_field = resource_custom_field_by_name(resource, custom_field_name) if custom_field.nil? raise "Could not find custom field with name #{custom_field_name} " \ "in gid #{resource.gid} with custom fields #{resource.custom_fields}" end custom_field end |
#resource_custom_field_enum_values(custom_field) ⇒ ::Array[::Hash[untyped, (untyped | String)]]
sord warn - ""resource_subtype"" does not appear to be a type sord warn - "String} & Hashdoes not appear to be a type sord warn - "Hash & Hashdoes not appear to be a type sord warn - "\"gid\"" does not appear to be a type sord warn - "String & Hash{"name"" does not appear to be a type rubocop:disable Layout/LineLength, YARD/TagTypeSyntax rubocop:enable Layout/LineLength, YARD/TagTypeSyntax
@param custom_field
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/checkoff/custom_fields.rb', line 143 def resource_custom_field_enum_values(custom_field) resource_subtype = custom_field.fetch('resource_subtype') case resource_subtype when 'enum' [custom_field.fetch('enum_value')] when 'multi_enum' custom_field.fetch('multi_enum_values') else raise "Teach me how to handle resource_subtype #{resource_subtype}" end end |
#resource_custom_field_values_gids_or_raise(resource, custom_field_gid) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_gid
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/checkoff/custom_fields.rb', line 67 def resource_custom_field_values_gids_or_raise(resource, custom_field_gid) custom_field = resource_custom_field_by_gid_or_raise(resource, custom_field_gid) resource_custom_field_enum_values(custom_field).flat_map do |enum_value| find_gids(custom_field, enum_value) end rescue StandardError => e raise "Could not process custom field with gid #{custom_field_gid} " \ "in gid #{resource.gid} with custom fields #{resource.custom_fields.inspect}: #{e}" end |
#resource_custom_field_values_names_by_name(resource, custom_field_name) ⇒ ::Array[String]
sord warn - Asana::Resources::Project wasn't able to be resolved to a constant in this project
sord warn - Asana::Resources::Task wasn't able to be resolved to a constant in this project
@param resource
@param custom_field_name
81 82 83 84 85 86 87 88 |
# File 'lib/checkoff/custom_fields.rb', line 81 def resource_custom_field_values_names_by_name(resource, custom_field_name) custom_field = resource_custom_field_by_name(resource, custom_field_name) return [] if custom_field.nil? resource_custom_field_enum_values(custom_field).flat_map do |enum_value| [enum_value.fetch('name')] end end |