Class: Trello::Checklist

Inherits:
BasicData show all
Defined in:
lib/trello/checklist.rb

Overview

A Checklist holds items which are like a “task” list. Checklists are linked to a card.

Instance Attribute Summary collapse

Attributes inherited from BasicData

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicData

#==, client, #hash, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save

Methods included from JsonUtils

included

Constructor Details

This class inherits a constructor from Trello::BasicData

Instance Attribute Details

#board_idString (readonly)

Returns A 24-character hex string.

Returns:

  • (String)

    A 24-character hex string



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#check_itemsObject (readonly)

Returns:

  • (Object)


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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#closedBoolean (readonly)

Returns:

  • (Boolean)


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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#descriptionString (readonly)

Returns:



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#idString (readonly)

Returns:



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#list_idString (readonly)

Returns A 24-character hex string.

Returns:

  • (String)

    A 24-character hex string



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#member_idsArray<String> (readonly)

Returns An array of 24-character hex strings.

Returns:

  • (Array<String>)

    An array of 24-character hex strings



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#nameString

Returns:



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#positionObject

Returns:

  • (Object)


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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

#urlString (readonly)

Returns:



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/trello/checklist.rb', line 24

class Checklist < BasicData
  register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
                      readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
  validates_presence_of :id, :board_id, :list_id
  validates_length_of :name, in: 1..16384

  class << self
    # Locate a specific checklist by its id.
    def find(id, params = {})
      client.find(:checklist, id, params)
    end

    def create(options)
      client.create(:checklist,
                    'name' => options[:name],
                    'idCard'  => options[:card_id])
    end
  end

  # Update the fields of a checklist.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a checklist.
  def update_fields(fields)
    attributes[:id] = fields['id'] || attributes[:id]
    attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
    attributes[:description] = fields['desc'] || attributes[:description]
    attributes[:closed] = fields['closed'] if fields.has_key?('closed')
    attributes[:url] = fields['url'] || attributes[:url]
    attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
    attributes[:position] = fields['pos'] || attributes[:position]
    attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
    attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
    attributes[:list_id] = fields['idList'] || attributes[:list_id]
    attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
    self
  end

  # Check if the checklist is currently active.
  def closed?
    closed
  end

  # Save a record.
  def save
    return update! if id

    from_response(client.post("/checklists", {
      name: name,
      idCard: card_id
    }))
  end

  def update!
    from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
  end

  # Return a list of items on the checklist.
  def items
    check_items.map do |item_fields|
      Item.new(item_fields)
    end
  end

  # Return a reference to the board the checklist is on.
  one :board, path: :checklists, using: :board_id

  # Return a reference to the card the checklist is on.
  one :card, path: :checklists, using: :card_id

  # Return a reference to the list the checklist is on.
  one :list, path: :lists, using: :list_id

  # Return a list of members active in this checklist.
  def members
    members = member_ids.map do |member_id|
      Member.find(member_id)
    end
    MultiAssociation.new(self, members).proxy
  end

  # Add an item to the checklist
  def add_item(name, checked = false, position = 'bottom')
    client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
  end

  # Update a checklist item's state, e.g.: "complete" or "incomplete"
  def update_item_state(item_id, state)
    state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
    client.put(
        "/cards/#{card_id}/checkItem/#{item_id}",
        state: state
    )
  end

  # Delete a checklist item
  def delete_checklist_item(item_id)
    client.delete("/checklists/#{id}/checkItems/#{item_id}")
  end

  # Delete a checklist
  def delete
    client.delete("/checklists/#{id}")
  end

  # Copy a checklist (i.e., same attributes, items, etc.)
  def copy
    checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
    copy_items_to(checklist_copy)
    return checklist_copy
  end

  private
  def copy_items_to(another_checklist)
    items.each do |item|
      another_checklist.add_item(item.name, item.complete?)
    end
  end
end

Class Method Details

.create(options) ⇒ Object



36
37
38
39
40
# File 'lib/trello/checklist.rb', line 36

def create(options)
  client.create(:checklist,
                'name' => options[:name],
                'idCard'  => options[:card_id])
end

.find(id, params = {}) ⇒ Object

Locate a specific checklist by its id.



32
33
34
# File 'lib/trello/checklist.rb', line 32

def find(id, params = {})
  client.find(:checklist, id, params)
end

Instance Method Details

#add_item(name, checked = false, position = 'bottom') ⇒ Object

Add an item to the checklist



106
107
108
# File 'lib/trello/checklist.rb', line 106

def add_item(name, checked = false, position = 'bottom')
  client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
end

#closed?Boolean

Check if the checklist is currently active.

Returns:

  • (Boolean)


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

def closed?
  closed
end

#copyObject

Copy a checklist (i.e., same attributes, items, etc.)



130
131
132
133
134
# File 'lib/trello/checklist.rb', line 130

def copy
  checklist_copy = self.class.create(name: self.name, board_id: self.board_id, card_id: self.card_id)
  copy_items_to(checklist_copy)
  return checklist_copy
end

#deleteObject

Delete a checklist



125
126
127
# File 'lib/trello/checklist.rb', line 125

def delete
  client.delete("/checklists/#{id}")
end

#delete_checklist_item(item_id) ⇒ Object

Delete a checklist item



120
121
122
# File 'lib/trello/checklist.rb', line 120

def delete_checklist_item(item_id)
  client.delete("/checklists/#{id}/checkItems/#{item_id}")
end

#itemsObject

Return a list of items on the checklist.



82
83
84
85
86
# File 'lib/trello/checklist.rb', line 82

def items
  check_items.map do |item_fields|
    Item.new(item_fields)
  end
end

#membersObject

Return a list of members active in this checklist.



98
99
100
101
102
103
# File 'lib/trello/checklist.rb', line 98

def members
  members = member_ids.map do |member_id|
    Member.find(member_id)
  end
  MultiAssociation.new(self, members).proxy
end

#saveObject

Save a record.



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

def save
  return update! if id

  from_response(client.post("/checklists", {
    name: name,
    idCard: card_id
  }))
end

#update!Object



77
78
79
# File 'lib/trello/checklist.rb', line 77

def update!
  from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
end

#update_fields(fields) ⇒ Object

Update the fields of a checklist.

Supply a hash of string keyed data retrieved from the Trello API representing a checklist.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/trello/checklist.rb', line 47

def update_fields(fields)
  attributes[:id] = fields['id'] || attributes[:id]
  attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
  attributes[:description] = fields['desc'] || attributes[:description]
  attributes[:closed] = fields['closed'] if fields.has_key?('closed')
  attributes[:url] = fields['url'] || attributes[:url]
  attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
  attributes[:position] = fields['pos'] || attributes[:position]
  attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
  attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
  attributes[:list_id] = fields['idList'] || attributes[:list_id]
  attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
  self
end

#update_item_state(item_id, state) ⇒ Object

Update a checklist item’s state, e.g.: “complete” or “incomplete”



111
112
113
114
115
116
117
# File 'lib/trello/checklist.rb', line 111

def update_item_state(item_id, state)
  state = ( state ? 'complete' : 'incomplete' ) unless state.is_a?(String)
  client.put(
      "/cards/#{card_id}/checkItem/#{item_id}",
      state: state
  )
end