Class: Trello::Checklist
Overview
A Checklist holds items which are like a “task” list. Checklists are linked to a card.
Instance Attribute Summary collapse
-
#board_id ⇒ String
readonly
A 24-character hex string.
- #check_items ⇒ Object readonly
- #closed ⇒ Boolean readonly
- #description ⇒ String readonly
- #id ⇒ String readonly
-
#list_id ⇒ String
readonly
A 24-character hex string.
-
#member_ids ⇒ Array<String>
readonly
An array of 24-character hex strings.
- #name ⇒ String
- #position ⇒ Object
- #url ⇒ String readonly
Attributes inherited from BasicData
Class Method Summary collapse
- .create(options) ⇒ Object
-
.find(id, params = {}) ⇒ Object
Locate a specific checklist by its id.
Instance Method Summary collapse
-
#add_item(name, checked = false, position = 'bottom') ⇒ Object
Add an item to the checklist.
-
#closed? ⇒ Boolean
Check if the checklist is currently active.
-
#copy ⇒ Object
Copy a checklist (i.e., same attributes, items, etc.).
-
#delete ⇒ Object
Delete a checklist.
-
#delete_checklist_item(item_id) ⇒ Object
Delete a checklist item.
-
#items ⇒ Object
Return a list of items on the checklist.
-
#members ⇒ Object
Return a list of members active in this checklist.
-
#save ⇒ Object
Save a record.
- #update! ⇒ Object
-
#update_fields(fields) ⇒ Object
Update the fields of a checklist.
-
#update_item_state(item_id, state) ⇒ Object
Update a checklist item’s state, e.g.: “complete” or “incomplete”.
Methods inherited from BasicData
#==, client, #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 Attribute Details
#board_id ⇒ String (readonly)
Returns 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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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_items ⇒ Object (readonly)
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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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 |
#closed ⇒ Boolean (readonly)
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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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 |
#description ⇒ String (readonly)
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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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 |
#id ⇒ String (readonly)
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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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_id ⇒ String (readonly)
Returns 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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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_ids ⇒ Array<String> (readonly)
Returns 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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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 |
#name ⇒ 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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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 |
#position ⇒ 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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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 |
#url ⇒ String (readonly)
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 |
# 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: 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() client.create(:checklist, 'name' => [:name], 'idCard' => [: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.
63 64 65 |
# File 'lib/trello/checklist.rb', line 63 def closed? closed end |
#copy ⇒ Object
Copy a checklist (i.e., same attributes, items, etc.)
129 130 131 132 133 |
# File 'lib/trello/checklist.rb', line 129 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 |
#delete ⇒ Object
Delete a checklist
124 125 126 |
# File 'lib/trello/checklist.rb', line 124 def delete client.delete("/checklists/#{id}") end |
#delete_checklist_item(item_id) ⇒ Object
Delete a checklist item
119 120 121 |
# File 'lib/trello/checklist.rb', line 119 def delete_checklist_item(item_id) client.delete("/checklists/#{id}/checkItems/#{item_id}") end |
#items ⇒ Object
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 |
#members ⇒ Object
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 |
#save ⇒ Object
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[:name] = fields['name'] || fields[:name] attributes[:description] = fields['desc'] attributes[:closed] = fields['closed'] attributes[:url] = fields['url'] attributes[:check_items] = fields['checkItems'] attributes[:position] = fields['pos'] attributes[:board_id] = fields['idBoard'] attributes[:card_id] = fields['idCard'] || fields[:card_id] attributes[:list_id] = fields['idList'] attributes[:member_ids] = fields['idMembers'] 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 |
# File 'lib/trello/checklist.rb', line 111 def update_item_state(item_id, state) client.put( "/cards/#{card_id}/checklist/#{id}/checkItem/#{item_id}/state", value: state, ) end |