class Trello::Card
A Card
is a container that can house checklists and comments; it resides inside a List
.
@!attribute [r] id
@return [String]
@!attribute [r] short_id
@return [Fixnum]
@!attribute [rw] name
@return [String]
@!attribute [rw] desc
@return [String]
@!attribute [rw] due
@return [Datetime]
@!attribute [rw] closed
@return [Boolean]
@!attribute [r] url
@return [String]
@!attribute [r] short_url
@return [String]
@!attribute [rw] board_id
@return [String] A 24-character hex string
@!attribute [rw] member_ids
@return [Array<String>] An Array of 24-character hex strings
@!attribute [rw] list_id
@return [String] A 24-character hex string
@!attribute [rw] pos
@return [Float]
@!attribute [r] last_activity_date
@return [Dateime]
@!attribute [rw] card_labels
@return [Array<Hash>]
@!attribute [rw] labels
@return [Array<Trello::Labels>]
@!attribute [rw] cover_image_id
@return [String] A 24-character hex string
@!attribute [r] badges
@return [Hash]
@!attribute [r] card_members
@return [Object]
@!attribute [rw] source_card_id
@return [String] A 24-character hex string
@!attribute [rw] source_card_properties
@return [Array<String>] Array of strings
Public Instance Methods
Add an attachment to this card
# File lib/trello/card.rb, line 272 def add_attachment(attachment, name = '') # Is it a file object or a string (url)? if attachment.respond_to?(:path) && attachment.respond_to?(:read) client.post("/cards/#{id}/attachments", { file: attachment, name: name }) else client.post("/cards/#{id}/attachments", { url: attachment, name: name }) end end
Add a checklist to this card
# File lib/trello/card.rb, line 175 def add_checklist(checklist, name: nil, position: nil) payload = { idChecklistSource: checklist.id } payload[:name] = name if name payload[:pos] = position if position client.post("/cards/#{id}/checklists", payload) end
Add a comment with the supplied text.
# File lib/trello/card.rb, line 170 def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end
Add a label
# File lib/trello/card.rb, line 254 def add_label(label) unless label.valid? errors.add(:label, "is not valid.") return Trello.logger.warn "Label is not valid." unless label.valid? end client.post("/cards/#{id}/idLabels", {value: label.id}) end
Add a member to this card
# File lib/trello/card.rb, line 218 def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end
Retrieve a list of attachments
# File lib/trello/card.rb, line 288 def attachments attachments = Attachment.from_response client.get("/cards/#{id}/attachments") MultiAssociation.new(self, attachments).proxy end
# File lib/trello/card.rb, line 108 def check_item_states states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates") MultiAssociation.new(self, states).proxy end
Close the card.
This only marks your local copy card as closed. Use `close!` if you want to close the card and persist the change to the Trello
API.
@return [Boolean] always returns true
@return [String] The JSON representation of the closed card returned by
the Trello API.
# File lib/trello/card.rb, line 155 def close self.closed = true end
# File lib/trello/card.rb, line 159 def close! close save end
Check if the card is not active anymore.
# File lib/trello/card.rb, line 142 def closed? closed end
Returns a reference to the cover image attachment
# File lib/trello/card.rb, line 90 def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end
create a new checklist and add it to this card
# File lib/trello/card.rb, line 184 def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end
Delete this card
@return [String] the JSON response from the Trello
API
# File lib/trello/card.rb, line 137 def delete client.delete("/cards/#{id}") end
Returns a list of members who are assigned to this card.
@return [Array<Trello::Member>]
# File lib/trello/card.rb, line 119 def members members = Member.from_response client.get("/cards/#{self.id}/members") MultiAssociation.new(self, members).proxy end
Move this card to the given board (and optional list on this board)
# File lib/trello/card.rb, line 209 def move_to_board(new_board, new_list = nil) unless board_id == new_board.id payload = { value: new_board.id } payload[:idList] = new_list.id if new_list client.put("/cards/#{id}/idBoard", payload) end end
Move this card to the given list
# File lib/trello/card.rb, line 189 def move_to_list(list) list_number = list.is_a?(String) ? list : list.id unless list_id == list_number client.put("/cards/#{id}/idList", { value: list_number }) end end
Moves this card to the given list no matter which board it is on
# File lib/trello/card.rb, line 199 def move_to_list_on_any_board(list_id) list = List.find(list_id) if board.id == list.board_id move_to_list(list_id) else move_to_board(Board.find(list.board_id), list) end end
Remove an attachment from this card
# File lib/trello/card.rb, line 294 def remove_attachment(attachment) client.delete("/cards/#{id}/attachments/#{attachment.id}") end
Remove a label
# File lib/trello/card.rb, line 263 def remove_label(label) unless label.valid? errors.add(:label, "is not valid.") return Trello.logger.warn "Label is not valid." unless label.valid? end client.delete("/cards/#{id}/idLabels/#{label.id}") end
Remove a member from this card
# File lib/trello/card.rb, line 225 def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end
Recind upvote. Noop if authenticated user hasn't previously voted
# File lib/trello/card.rb, line 243 def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e.message =~ /has not voted/i end self end
Current authenticated user upvotes a card
# File lib/trello/card.rb, line 230 def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e.message =~ /has already voted/i end self end
Is the record valid?
# File lib/trello/card.rb, line 165 def valid? !(name && list_id).nil? end
Returns a list of members who have upvoted this card NOTE: this fetches a list each time it's called to avoid case where card is voted (or vote is removed) after card is fetched. Optimizing accuracy over network performance
@return [Array<Trello::Member>]
# File lib/trello/card.rb, line 130 def voters Member.from_response client.get("/cards/#{id}/membersVoted") end