Class: Asana::Resources::CustomField
- Defined in:
- lib/asana/resources/custom_fields.rb
Overview
Custom Fields store the metadata that is used in order to add user-specified information to tasks in Asana. Be sure to reference the [Custom Fields](/developers/documentation/getting-started/custom-fields) developer documentation for more information about how custom fields relate to various resources in Asana.
Users in Asana can [lock custom fields](/guide/help/premium/custom-fields#gl-lock-fields), which will make them read-only when accessed by other users. Attempting to edit a locked custom field will return HTTP error code ‘403 Forbidden`.
Instance Attribute Summary collapse
- #description ⇒ Object readonly
- #enum_options ⇒ Object readonly
- #gid ⇒ Object readonly
- #id ⇒ Object readonly
- #name ⇒ Object readonly
- #precision ⇒ Object readonly
- #resource_subtype ⇒ Object readonly
- #resource_type ⇒ Object readonly
- #type ⇒ Object readonly
Class Method Summary collapse
-
.create(client, workspace: required("workspace"), resource_subtype: nil, type: nil, name: required("name"), description: nil, precision: nil, enum_options: nil, options: {}, **data) ⇒ Object
Creates a new custom field in a workspace.
-
.create_enum_option(client, custom_field: required("custom_field"), name: required("name"), color: nil, insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object
(also: add_enum_option)
Creates an enum option and adds it to this custom field’s list of enum options.
-
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete definition of a custom field’s metadata.
-
.find_by_workspace(client, workspace: required("workspace"), per_page: 20, options: {}) ⇒ Object
Returns a list of the compact representation of all of the custom fields in a workspace.
-
.insert_enum_option(client, custom_field: required("custom_field"), enum_option: required("enum_option"), name: required("name"), color: nil, before_enum_option: nil, after_enum_option: nil, options: {}, **data) ⇒ Object
(also: reorder_enum_option)
Moves a particular enum option to be either before or after another specified enum option in the custom field.
-
.plural_name ⇒ Object
Returns the plural name of the resource.
Instance Method Summary collapse
-
#delete ⇒ Object
A specific, existing custom field can be deleted by making a DELETE request on the URL for that custom field.
-
#update(options: {}, **data) ⇒ Object
A specific, existing custom field can be updated by making a PUT request on the URL for that custom field.
-
#update_enum_option(enum_option: required("enum_option"), name: required("name"), color: nil, enabled: nil, options: {}, **data) ⇒ Object
Updates an existing enum option.
Methods inherited from Resource
inherited, #initialize, #method_missing, #refresh, #respond_to_missing?, #to_h, #to_s
Methods included from ResponseHelper
Constructor Details
This class inherits a constructor from Asana::Resources::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Asana::Resources::Resource
Instance Attribute Details
#description ⇒ Object (readonly)
29 30 31 |
# File 'lib/asana/resources/custom_fields.rb', line 29 def description @description end |
#enum_options ⇒ Object (readonly)
33 34 35 |
# File 'lib/asana/resources/custom_fields.rb', line 33 def @enum_options end |
#gid ⇒ Object (readonly)
21 22 23 |
# File 'lib/asana/resources/custom_fields.rb', line 21 def gid @gid end |
#id ⇒ Object (readonly)
19 20 21 |
# File 'lib/asana/resources/custom_fields.rb', line 19 def id @id end |
#name ⇒ Object (readonly)
27 28 29 |
# File 'lib/asana/resources/custom_fields.rb', line 27 def name @name end |
#precision ⇒ Object (readonly)
35 36 37 |
# File 'lib/asana/resources/custom_fields.rb', line 35 def precision @precision end |
#resource_subtype ⇒ Object (readonly)
25 26 27 |
# File 'lib/asana/resources/custom_fields.rb', line 25 def resource_subtype @resource_subtype end |
#resource_type ⇒ Object (readonly)
23 24 25 |
# File 'lib/asana/resources/custom_fields.rb', line 23 def resource_type @resource_type end |
#type ⇒ Object (readonly)
31 32 33 |
# File 'lib/asana/resources/custom_fields.rb', line 31 def type @type end |
Class Method Details
.create(client, workspace: required("workspace"), resource_subtype: nil, type: nil, name: required("name"), description: nil, precision: nil, enum_options: nil, options: {}, **data) ⇒ Object
Creates a new custom field in a workspace. Every custom field is required to be created in a specific workspace, and this workspace cannot be changed once set.
A custom field’s ‘name` must be unique within a workspace and not conflict with names of existing task properties such as ’Due Date’ or ‘Assignee’. A custom field’s ‘type` must be one of ’text’, ‘enum’, or ‘number’.
58 59 60 61 |
# File 'lib/asana/resources/custom_fields.rb', line 58 def create(client, workspace: required("workspace"), resource_subtype: nil, type: nil, name: required("name"), description: nil, precision: nil, enum_options: nil, options: {}, **data) with_params = data.merge(workspace: workspace, resource_subtype: resource_subtype || type, name: name, description: description, precision: precision, enum_options: ).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/custom_fields", body: with_params, options: )).first, client: client) end |
.create_enum_option(client, custom_field: required("custom_field"), name: required("name"), color: nil, insert_before: nil, insert_after: nil, options: {}, **data) ⇒ Object Also known as: add_enum_option
Creates an enum option and adds it to this custom field’s list of enum options. A custom field can have at most 50 enum options (including disabled options). By default new enum options are inserted at the end of a custom field’s list.
Locked custom fields can only have enum options added by the user who locked the field.
97 98 99 100 |
# File 'lib/asana/resources/custom_fields.rb', line 97 def create_enum_option(client, custom_field: required("custom_field"), name: required("name"), color: nil, insert_before: nil, insert_after: nil, options: {}, **data) with_params = data.merge(name: name, color: color, insert_before: insert_before, insert_after: insert_after).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/custom_fields/#{custom_field}/enum_options", body: with_params, options: )).first, client: client) end |
.find_by_id(client, id, options: {}) ⇒ Object
Returns the complete definition of a custom field’s metadata.
68 69 70 71 |
# File 'lib/asana/resources/custom_fields.rb', line 68 def find_by_id(client, id, options: {}) self.new(parse(client.get("/custom_fields/#{id}", options: )).first, client: client) end |
.find_by_workspace(client, workspace: required("workspace"), per_page: 20, options: {}) ⇒ Object
Returns a list of the compact representation of all of the custom fields in a workspace.
78 79 80 81 |
# File 'lib/asana/resources/custom_fields.rb', line 78 def find_by_workspace(client, workspace: required("workspace"), per_page: 20, options: {}) params = { limit: per_page }.reject { |_,v| v.nil? || Array(v).empty? } Collection.new(parse(client.get("/workspaces/#{workspace}/custom_fields", params: params, options: )), type: Resource, client: client) end |
.insert_enum_option(client, custom_field: required("custom_field"), enum_option: required("enum_option"), name: required("name"), color: nil, before_enum_option: nil, after_enum_option: nil, options: {}, **data) ⇒ Object Also known as: reorder_enum_option
Moves a particular enum option to be either before or after another specified enum option in the custom field.
Locked custom fields can only be reordered by the user who locked the field.
116 117 118 119 |
# File 'lib/asana/resources/custom_fields.rb', line 116 def insert_enum_option(client, custom_field: required("custom_field"), enum_option: required("enum_option"), name: required("name"), color: nil, before_enum_option: nil, after_enum_option: nil, options: {}, **data) with_params = data.merge(enum_option: enum_option, name: name, color: color, before_enum_option: before_enum_option, after_enum_option: after_enum_option).reject { |_,v| v.nil? || Array(v).empty? } Resource.new(parse(client.post("/custom_fields/#{custom_field}/enum_options/insert", body: with_params, options: )).first, client: client) end |
.plural_name ⇒ Object
Returns the plural name of the resource.
39 40 41 |
# File 'lib/asana/resources/custom_fields.rb', line 39 def plural_name 'custom_fields' end |
Instance Method Details
#delete ⇒ Object
A specific, existing custom field can be deleted by making a DELETE request on the URL for that custom field.
Locked custom fields can only be deleted by the user who locked the field.
145 146 147 148 |
# File 'lib/asana/resources/custom_fields.rb', line 145 def delete() client.delete("/custom_fields/#{gid}") && true end |
#update(options: {}, **data) ⇒ Object
A specific, existing custom field can be updated by making a PUT request on the URL for that custom field. Only the fields provided in the ‘data` block will be updated; any unspecified fields will remain unchanged
When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the custom field.
An enum custom field’s ‘enum_options` cannot be updated with this endpoint. Instead see “Work With Enum Options” for information on how to update `enum_options`.
Locked custom fields can only be updated by the user who locked the field.
135 136 137 138 |
# File 'lib/asana/resources/custom_fields.rb', line 135 def update(options: {}, **data) refresh_with(parse(client.put("/custom_fields/#{gid}", body: data, options: )).first) end |
#update_enum_option(enum_option: required("enum_option"), name: required("name"), color: nil, enabled: nil, options: {}, **data) ⇒ Object
Updates an existing enum option. Enum custom fields require at least one enabled enum option.
Locked custom fields can only be updated by the user who locked the field.
163 164 165 166 |
# File 'lib/asana/resources/custom_fields.rb', line 163 def update_enum_option(enum_option: required("enum_option"), name: required("name"), color: nil, enabled: nil, options: {}, **data) with_params = data.merge(name: name, color: color, enabled: enabled).reject { |_,v| v.nil? || Array(v).empty? } refresh_with(parse(client.put("/enum_options/#{enum_option}", body: with_params, options: )).first) end |