Class: Trello::CustomFieldItem

Inherits:
BasicData show all
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 collapse

Attributes inherited from BasicData

#client

Instance Method Summary collapse

Methods inherited from BasicData

#==, #attributes, client, #collection_name, create, #element_name, find, #hash, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attrs, save, #schema, schema, #update!, #update_fields

Methods included from JsonUtils

included

Constructor Details

This class inherits a constructor from Trello::BasicData

Instance Attribute Details

#custom_field_idString (readonly)

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trello/custom_field_item.rb', line 16

class CustomFieldItem < BasicData

  schema do
    attribute :id, readonly: true, primary_key: true
    attribute :model_id, readonly: true, remote_key: 'idModel'
    attribute :model_type, readonly: true, remote_key: 'modelType'
    attribute :custom_field_id, readonly: true, remote_key: 'idCustomField'
    attribute :option_id, readonly: true, remote_key: 'idValue'

    attribute :value
  end

  validates_presence_of :id, :model_id, :custom_field_id

  # References the card with this custom field value
  one :card, path: :cards, using: :model_id

  # References the parent custom field that this item is an instance of
  one :custom_field, path: 'customFields', using: :custom_field_id

  def save
    return update! if id

    payload = {}

    schema.attrs.each do |_, attribute|
      payload = attribute.build_payload_for_create(attributes, payload)
    end

    put(element_path, payload)
  end

  def collection_path
    "/cards/#{model_id}/#{collection_name}"
  end

  def element_path
    "/cards/#{model_id}/customField/#{custom_field_id}/item"
  end

  # You can't "delete" a custom field item, you can only clear the value
  def remove
    params = { value: {} }
    client.put(element_path, params)
  end

  # Type is saved at the CustomField level
  def type
    custom_field.type
  end

  # Need to make another call to get the actual value if the custom field type == 'list'
  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
end

#idString (readonly)

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trello/custom_field_item.rb', line 16

class CustomFieldItem < BasicData

  schema do
    attribute :id, readonly: true, primary_key: true
    attribute :model_id, readonly: true, remote_key: 'idModel'
    attribute :model_type, readonly: true, remote_key: 'modelType'
    attribute :custom_field_id, readonly: true, remote_key: 'idCustomField'
    attribute :option_id, readonly: true, remote_key: 'idValue'

    attribute :value
  end

  validates_presence_of :id, :model_id, :custom_field_id

  # References the card with this custom field value
  one :card, path: :cards, using: :model_id

  # References the parent custom field that this item is an instance of
  one :custom_field, path: 'customFields', using: :custom_field_id

  def save
    return update! if id

    payload = {}

    schema.attrs.each do |_, attribute|
      payload = attribute.build_payload_for_create(attributes, payload)
    end

    put(element_path, payload)
  end

  def collection_path
    "/cards/#{model_id}/#{collection_name}"
  end

  def element_path
    "/cards/#{model_id}/customField/#{custom_field_id}/item"
  end

  # You can't "delete" a custom field item, you can only clear the value
  def remove
    params = { value: {} }
    client.put(element_path, params)
  end

  # Type is saved at the CustomField level
  def type
    custom_field.type
  end

  # Need to make another call to get the actual value if the custom field type == 'list'
  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
end

#model_idString (readonly)

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trello/custom_field_item.rb', line 16

class CustomFieldItem < BasicData

  schema do
    attribute :id, readonly: true, primary_key: true
    attribute :model_id, readonly: true, remote_key: 'idModel'
    attribute :model_type, readonly: true, remote_key: 'modelType'
    attribute :custom_field_id, readonly: true, remote_key: 'idCustomField'
    attribute :option_id, readonly: true, remote_key: 'idValue'

    attribute :value
  end

  validates_presence_of :id, :model_id, :custom_field_id

  # References the card with this custom field value
  one :card, path: :cards, using: :model_id

  # References the parent custom field that this item is an instance of
  one :custom_field, path: 'customFields', using: :custom_field_id

  def save
    return update! if id

    payload = {}

    schema.attrs.each do |_, attribute|
      payload = attribute.build_payload_for_create(attributes, payload)
    end

    put(element_path, payload)
  end

  def collection_path
    "/cards/#{model_id}/#{collection_name}"
  end

  def element_path
    "/cards/#{model_id}/customField/#{custom_field_id}/item"
  end

  # You can't "delete" a custom field item, you can only clear the value
  def remove
    params = { value: {} }
    client.put(element_path, params)
  end

  # Type is saved at the CustomField level
  def type
    custom_field.type
  end

  # Need to make another call to get the actual value if the custom field type == 'list'
  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
end

#model_typeString (readonly)

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trello/custom_field_item.rb', line 16

class CustomFieldItem < BasicData

  schema do
    attribute :id, readonly: true, primary_key: true
    attribute :model_id, readonly: true, remote_key: 'idModel'
    attribute :model_type, readonly: true, remote_key: 'modelType'
    attribute :custom_field_id, readonly: true, remote_key: 'idCustomField'
    attribute :option_id, readonly: true, remote_key: 'idValue'

    attribute :value
  end

  validates_presence_of :id, :model_id, :custom_field_id

  # References the card with this custom field value
  one :card, path: :cards, using: :model_id

  # References the parent custom field that this item is an instance of
  one :custom_field, path: 'customFields', using: :custom_field_id

  def save
    return update! if id

    payload = {}

    schema.attrs.each do |_, attribute|
      payload = attribute.build_payload_for_create(attributes, payload)
    end

    put(element_path, payload)
  end

  def collection_path
    "/cards/#{model_id}/#{collection_name}"
  end

  def element_path
    "/cards/#{model_id}/customField/#{custom_field_id}/item"
  end

  # You can't "delete" a custom field item, you can only clear the value
  def remove
    params = { value: {} }
    client.put(element_path, params)
  end

  # Type is saved at the CustomField level
  def type
    custom_field.type
  end

  # Need to make another call to get the actual value if the custom field type == 'list'
  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
end

#option_idString (readonly)

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trello/custom_field_item.rb', line 16

class CustomFieldItem < BasicData

  schema do
    attribute :id, readonly: true, primary_key: true
    attribute :model_id, readonly: true, remote_key: 'idModel'
    attribute :model_type, readonly: true, remote_key: 'modelType'
    attribute :custom_field_id, readonly: true, remote_key: 'idCustomField'
    attribute :option_id, readonly: true, remote_key: 'idValue'

    attribute :value
  end

  validates_presence_of :id, :model_id, :custom_field_id

  # References the card with this custom field value
  one :card, path: :cards, using: :model_id

  # References the parent custom field that this item is an instance of
  one :custom_field, path: 'customFields', using: :custom_field_id

  def save
    return update! if id

    payload = {}

    schema.attrs.each do |_, attribute|
      payload = attribute.build_payload_for_create(attributes, payload)
    end

    put(element_path, payload)
  end

  def collection_path
    "/cards/#{model_id}/#{collection_name}"
  end

  def element_path
    "/cards/#{model_id}/customField/#{custom_field_id}/item"
  end

  # You can't "delete" a custom field item, you can only clear the value
  def remove
    params = { value: {} }
    client.put(element_path, params)
  end

  # Type is saved at the CustomField level
  def type
    custom_field.type
  end

  # Need to make another call to get the actual value if the custom field type == 'list'
  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
end

#valueHash

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/trello/custom_field_item.rb', line 16

class CustomFieldItem < BasicData

  schema do
    attribute :id, readonly: true, primary_key: true
    attribute :model_id, readonly: true, remote_key: 'idModel'
    attribute :model_type, readonly: true, remote_key: 'modelType'
    attribute :custom_field_id, readonly: true, remote_key: 'idCustomField'
    attribute :option_id, readonly: true, remote_key: 'idValue'

    attribute :value
  end

  validates_presence_of :id, :model_id, :custom_field_id

  # References the card with this custom field value
  one :card, path: :cards, using: :model_id

  # References the parent custom field that this item is an instance of
  one :custom_field, path: 'customFields', using: :custom_field_id

  def save
    return update! if id

    payload = {}

    schema.attrs.each do |_, attribute|
      payload = attribute.build_payload_for_create(attributes, payload)
    end

    put(element_path, payload)
  end

  def collection_path
    "/cards/#{model_id}/#{collection_name}"
  end

  def element_path
    "/cards/#{model_id}/customField/#{custom_field_id}/item"
  end

  # You can't "delete" a custom field item, you can only clear the value
  def remove
    params = { value: {} }
    client.put(element_path, params)
  end

  # Type is saved at the CustomField level
  def type
    custom_field.type
  end

  # Need to make another call to get the actual value if the custom field type == 'list'
  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
end

Instance Method Details

#collection_pathObject



48
49
50
# File 'lib/trello/custom_field_item.rb', line 48

def collection_path
  "/cards/#{model_id}/#{collection_name}"
end

#element_pathObject



52
53
54
# File 'lib/trello/custom_field_item.rb', line 52

def element_path
  "/cards/#{model_id}/customField/#{custom_field_id}/item"
end

#option_valueObject

Need to make another call to get the actual value if the custom field type == ‘list’



68
69
70
71
72
73
74
# File 'lib/trello/custom_field_item.rb', line 68

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

#removeObject

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(element_path, params)
end

#saveObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/trello/custom_field_item.rb', line 36

def save
  return update! if id

  payload = {}

  schema.attrs.each do |_, attribute|
    payload = attribute.build_payload_for_create(attributes, payload)
  end

  put(element_path, payload)
end

#typeObject

Type is saved at the CustomField level



63
64
65
# File 'lib/trello/custom_field_item.rb', line 63

def type
  custom_field.type
end