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_attachment(attachment, name = '') click to toggle source

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_checklist(checklist, name: nil, position: nil) click to toggle source

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_comment(text) click to toggle source

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_label(label) click to toggle source

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_member(member) click to toggle source

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
attachments() click to toggle source

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
check_item_states() click to toggle source
# 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() click to toggle source

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
close!() click to toggle source
# File lib/trello/card.rb, line 159
def close!
  close
  save
end
closed?() click to toggle source

Check if the card is not active anymore.

# File lib/trello/card.rb, line 142
def closed?
  closed
end
cover_image(params = {}) click to toggle source

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_new_checklist(name) click to toggle source

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() click to toggle source

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
members() click to toggle source

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_to_board(new_board, new_list = nil) click to toggle source

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_to_list(list) click to toggle source

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
move_to_list_on_any_board(list_id) click to toggle source

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_attachment(attachment) click to toggle source

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_label(label) click to toggle source

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_member(member) click to toggle source

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
remove_upvote() click to toggle source

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
upvote() click to toggle source

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
valid?() click to toggle source

Is the record valid?

# File lib/trello/card.rb, line 165
def valid?
  !(name && list_id).nil?
end
voters() click to toggle source

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