Class: Trello::CustomFieldItem
- Defined in:
- lib/trello/custom_field_item.rb
Overview
A custom field item contains the value for a custom field on a particular card.
Instance Attribute Summary
Attributes inherited from BasicData
Instance Method Summary collapse
-
#option_value ⇒ Object
Need to make another call to get the actual value if the custom field type == ‘list’.
-
#remove ⇒ Object
You can’t “delete” a custom field item, you can only clear the value.
-
#save ⇒ String
Saves a record.
-
#type ⇒ Object
Type is saved at the CustomField level Can equally be derived from :value, with a little parsing work: 42.
- #update! ⇒ Object
-
#update_fields(fields) ⇒ Object
Update the fields of a custom field item.
Methods inherited from BasicData
#==, client, create, find, #hash, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save
Methods included from JsonUtils
Constructor Details
This class inherits a constructor from Trello::BasicData
Instance Method Details
#option_value ⇒ Object
Need to make another call to get the actual value if the custom field type == ‘list’
69 70 71 72 73 74 75 |
# File 'lib/trello/custom_field_item.rb', line 69 def option_value if option_id option_endpoint = "/customFields/#{custom_field_id}/options/#{option_id}" option = CustomFieldOption.from_response client.get(option_endpoint) option.value end end |
#remove ⇒ Object
You can’t “delete” a custom field item, you can only clear the value
57 58 59 60 |
# File 'lib/trello/custom_field_item.rb', line 57 def remove params = { value: {} } client.put("/card/#{model_id}/customField/#{custom_field_id}/item", params) end |
#save ⇒ String
Saves a record.
the Trello API.
47 48 49 50 51 52 53 54 |
# File 'lib/trello/custom_field_item.rb', line 47 def save # If we have an id, just update our fields. return update! if id from_response client.post("/card/#{model_id}/customField/#{custom_field_id}/item", { value: value }) end |
#type ⇒ Object
Type is saved at the CustomField level Can equally be derived from :value, with a little parsing work: 42
64 65 66 |
# File 'lib/trello/custom_field_item.rb', line 64 def type custom_field.type end |
#update! ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/trello/custom_field_item.rb', line 32 def update! @previously_changed = changes # extract only new values to build payload payload = Hash[changes.map { |key, values| [key.to_sym, values[1]] }] @changed_attributes.clear client.put("/card/#{model_id}/customField/#{custom_field_id}/item", payload) end |
#update_fields(fields) ⇒ Object
Update the fields of a custom field item.
Supply a hash of string keyed data retrieved from the Trello API representing an item state.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trello/custom_field_item.rb', line 19 def update_fields(fields) attributes[:id] = fields['id'] || fields[:id] || attributes[:id] attributes[:model_id] = fields['idModel'] || fields[:model_id] || attributes[:model_id] attributes[:custom_field_id] = fields['idCustomField'] || fields[:custom_field_id] || attributes[:custom_field_id] attributes[:model_type] = fields['modelType'] || fields[:model_type] || attributes[:model_type] # Dropdown custom field items do not have a value, they have an ID that maps to # a different endpoint to get the value attributes[:option_id] = fields['idValue'] if fields.has_key?('idValue') # value format: { "text": "hello world" } attributes[:value] = fields['value'] if fields.has_key?('value') self end |