Class: Trello::Card
- Includes:
- HasActions
- Defined in:
- lib/trello/card.rb
Overview
A Card is a container that can house checklists and comments; it resides inside a List.
Instance Attribute Summary collapse
- #badges ⇒ Hash readonly
-
#board_id ⇒ String
A 24-character hex string.
- #card_labels ⇒ Array<Hash>
- #card_members ⇒ Object readonly
- #closed ⇒ Boolean
-
#cover_image_id ⇒ String
A 24-character hex string.
- #desc ⇒ String
- #due ⇒ Datetime
- #id ⇒ String readonly
- #labels ⇒ Array<Trello::Labels>
- #last_activity_date ⇒ Dateime readonly
-
#list_id ⇒ String
A 24-character hex string.
-
#member_ids ⇒ Array<String>
An Array of 24-character hex strings.
- #name ⇒ String
- #pos ⇒ Float
- #short_id ⇒ Fixnum readonly
- #short_url ⇒ String readonly
-
#source_card_id ⇒ String
A 24-character hex string.
-
#source_card_properties ⇒ Array<String>
Array of strings.
- #url ⇒ String readonly
Attributes inherited from BasicData
Instance Method Summary collapse
-
#add_attachment(attachment, name = '') ⇒ Object
Add an attachment to this card.
-
#add_checklist(checklist, name: nil, position: nil) ⇒ Object
Add a checklist to this card.
-
#add_comment(text) ⇒ Object
Add a comment with the supplied text.
-
#add_label(label) ⇒ Object
Add a label.
-
#add_member(member) ⇒ Object
Add a member to this card.
-
#attachments(params = {}) ⇒ Object
Retrieve a list of attachments.
- #check_item_states(params = {}) ⇒ Object
-
#close ⇒ Boolean, String
Close the card.
- #close! ⇒ Object
-
#closed? ⇒ Boolean
Check if the card is not active anymore.
-
#comments(params = {}) ⇒ Object
Retrieve a list of comments.
-
#cover_image(params = {}) ⇒ Object
Returns a reference to the cover image attachment.
-
#create_new_checklist(name) ⇒ Object
create a new checklist and add it to this card.
-
#created_at ⇒ Object
Find the creation date.
-
#delete ⇒ String
Delete this card.
-
#members(params = {}) ⇒ Array<Trello::Member>
Returns a list of members who are assigned to this card.
-
#move_to_board(new_board, new_list = nil) ⇒ Object
Move this card to the given board (and optional list on this board).
-
#move_to_list(list) ⇒ Object
Move this card to the given list.
-
#move_to_list_on_any_board(list_id) ⇒ Object
Moves this card to the given list no matter which board it is on.
-
#remove_attachment(attachment) ⇒ Object
Remove an attachment from this card.
-
#remove_label(label) ⇒ Object
Remove a label.
-
#remove_member(member) ⇒ Object
Remove a member from this card.
-
#remove_upvote ⇒ Object
Recind upvote.
-
#request_prefix ⇒ Object
:nodoc:.
-
#upvote ⇒ Object
Current authenticated user upvotes a card.
-
#valid? ⇒ Boolean
Is the record valid?.
-
#voters(params = {}) ⇒ Array<Trello::Member>
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.
Methods included from HasActions
Methods inherited from BasicData
#==, #attributes, client, #collection_name, #collection_path, create, #element_name, #element_path, find, #hash, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attrs, #save, save, schema, #schema, #update!, #update_fields
Methods included from JsonUtils
Constructor Details
This class inherits a constructor from Trello::BasicData
Instance Attribute Details
#badges ⇒ Hash (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#board_id ⇒ String
Returns A 24-character hex string.
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#card_labels ⇒ Array<Hash>
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#card_members ⇒ Object (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#closed ⇒ Boolean
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#cover_image_id ⇒ String
Returns A 24-character hex string.
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#desc ⇒ String
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#due ⇒ Datetime
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#id ⇒ String (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#labels ⇒ Array<Trello::Labels>
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#last_activity_date ⇒ Dateime (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#list_id ⇒ String
Returns A 24-character hex string.
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#member_ids ⇒ Array<String>
Returns An Array of 24-character hex strings.
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#name ⇒ String
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#pos ⇒ Float
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#short_id ⇒ Fixnum (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#short_url ⇒ String (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#source_card_id ⇒ String
Returns A 24-character hex string.
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#source_card_properties ⇒ Array<String>
Returns Array of strings.
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
#url ⇒ String (readonly)
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trello/card.rb', line 45 class Card < BasicData schema do # readonly attribute :id, readonly: true, primary_key: true attribute :short_id, readonly: true, remote_key: 'idShort' attribute :url, readonly: true attribute :short_url, readonly: true, remote_key: 'shortUrl' attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time' attribute :labels, readonly: true, default: [], serializer: 'Labels' attribute :badges, readonly: true attribute :card_members, readonly: true, remote_key: 'members' # Writable attribute :name attribute :desc attribute :due, serializer: 'Time' attribute :due_complete, remote_key: 'dueComplete' attribute :member_ids, remote_key: 'idMembers' attribute :list_id, remote_key: 'idList' attribute :pos attribute :card_labels, remote_key: 'idLabels' # Writable but for create only attribute :source_card_id, create_only: true, remote_key: 'idCardSource' attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource' # Writable but for update only attribute :closed, update_only: true attribute :board_id, update_only: true, remote_key: 'idBoard' attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover' # Deprecated attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource' end validates_presence_of :id, :name, :list_id validates_length_of :name, in: 1..16384 validates_length_of :desc, in: 0..16384 include HasActions # Returns a reference to the board this card is part of. one :board, path: :boards, using: :board_id # Returns a reference to the cover image attachment def cover_image(params = {}) response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params) CoverImage.from_response(response) end # Returns a list of checklists associated with the card. # # The options hash may have a filter key which can have its value set as any # of the following values: # :filter => [ :none, :all ] # default :all many :checklists, filter: :all # Returns a list of plugins associated with the card many :plugin_data, path: "pluginData" # List of custom field values on the card, only the ones that have been set many :custom_field_items, path: 'customFieldItems' def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end # Returns a reference to the list this card is currently in. one :list, path: :lists, using: :list_id # Returns a list of members who are assigned to this card. # # @return [Array<Trello::Member>] def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy 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>] def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end # Delete this card # # @return [String] the JSON response from the Trello API def delete client.delete("/cards/#{id}") end # Check if the card is not active anymore. def closed? closed 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. def close self.closed = true end def close! close save end # Is the record valid? def valid? !(name && list_id).nil? end # Add a comment with the supplied text. def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end # Add a checklist to this card 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 # create a new checklist and add it to this card def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end # Move this card to the given list 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 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 # Move this card to the given board (and optional list on this board) 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 # Add a member to this card def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end # Remove a member from this card def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end # Current authenticated user upvotes a card def upvote begin client.post("/cards/#{id}/membersVoted", { value: me.id }) rescue Trello::Error => e fail e unless e. =~ /has already voted/i end self end # Recind upvote. Noop if authenticated user hasn't previously voted def remove_upvote begin client.delete("/cards/#{id}/membersVoted/#{me.id}") rescue Trello::Error => e fail e unless e. =~ /has not voted/i end self end # Add a label 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 # Remove a label 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 # Add an attachment to this card def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end # Retrieve a list of attachments def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end # Remove an attachment from this card def () client.delete("/cards/#{id}/attachments/#{.id}") end # :nodoc: def request_prefix "/cards/#{id}" end # Retrieve a list of comments def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end # Find the creation date def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end private def me @me ||= Member.find(:me) end end |
Instance Method Details
#add_attachment(attachment, name = '') ⇒ Object
Add an attachment to this card
272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/trello/card.rb', line 272 def (, name = '') # Is it a file object or a string (url)? if .respond_to?(:path) && .respond_to?(:read) client.post("/cards/#{id}/attachments", { file: Trello::TInternet.multipart_file(), name: name }) else client.post("/cards/#{id}/attachments", { url: , name: name }) end end |
#add_checklist(checklist, name: nil, position: nil) ⇒ Object
Add a checklist to this card
175 176 177 178 179 180 181 |
# 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) ⇒ Object
Add a comment with the supplied text.
170 171 172 |
# File 'lib/trello/card.rb', line 170 def add_comment(text) client.post("/cards/#{id}/actions/comments", text: text) end |
#add_label(label) ⇒ Object
Add a label
254 255 256 257 258 259 260 |
# 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) ⇒ Object
Add a member to this card
218 219 220 221 222 |
# File 'lib/trello/card.rb', line 218 def add_member(member) client.post("/cards/#{id}/idMembers", { value: member.id }) end |
#attachments(params = {}) ⇒ Object
Retrieve a list of attachments
288 289 290 291 |
# File 'lib/trello/card.rb', line 288 def (params = {}) = Attachment.from_response client.get("/cards/#{id}/attachments", params) MultiAssociation.new(self, ).proxy end |
#check_item_states(params = {}) ⇒ Object
108 109 110 111 |
# File 'lib/trello/card.rb', line 108 def check_item_states(params = {}) states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates", params) MultiAssociation.new(self, states).proxy end |
#close ⇒ Boolean, String
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.
155 156 157 |
# File 'lib/trello/card.rb', line 155 def close self.closed = true end |
#close! ⇒ Object
159 160 161 162 |
# File 'lib/trello/card.rb', line 159 def close! close save end |
#closed? ⇒ Boolean
Check if the card is not active anymore.
142 143 144 |
# File 'lib/trello/card.rb', line 142 def closed? closed end |
#comments(params = {}) ⇒ Object
Retrieve a list of comments
304 305 306 307 |
# File 'lib/trello/card.rb', line 304 def comments(params = {}) params[:filter] ||= "commentCard" comments = Comment.from_response client.get("/cards/#{id}/actions", params) end |
#cover_image(params = {}) ⇒ Object
Returns a reference to the cover image attachment
90 91 92 93 |
# 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) ⇒ Object
create a new checklist and add it to this card
184 185 186 |
# File 'lib/trello/card.rb', line 184 def create_new_checklist(name) client.post("/cards/#{id}/checklists", { name: name }) end |
#created_at ⇒ Object
Find the creation date
310 311 312 |
# File 'lib/trello/card.rb', line 310 def created_at @created_at ||= Time.at(id[0..7].to_i(16)) rescue nil end |
#delete ⇒ String
Delete this card
137 138 139 |
# File 'lib/trello/card.rb', line 137 def delete client.delete("/cards/#{id}") end |
#members(params = {}) ⇒ Array<Trello::Member>
Returns a list of members who are assigned to this card.
119 120 121 122 |
# File 'lib/trello/card.rb', line 119 def members(params = {}) members = Member.from_response client.get("/cards/#{self.id}/members", params) MultiAssociation.new(self, members).proxy end |
#move_to_board(new_board, new_list = nil) ⇒ Object
Move this card to the given board (and optional list on this board)
209 210 211 212 213 214 215 |
# 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) ⇒ Object
Move this card to the given list
189 190 191 192 193 194 195 196 |
# 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) ⇒ Object
Moves this card to the given list no matter which board it is on
199 200 201 202 203 204 205 206 |
# 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) ⇒ Object
Remove an attachment from this card
294 295 296 |
# File 'lib/trello/card.rb', line 294 def () client.delete("/cards/#{id}/attachments/#{.id}") end |
#remove_label(label) ⇒ Object
Remove a label
263 264 265 266 267 268 269 |
# 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) ⇒ Object
Remove a member from this card
225 226 227 |
# File 'lib/trello/card.rb', line 225 def remove_member(member) client.delete("/cards/#{id}/idMembers/#{member.id}") end |
#remove_upvote ⇒ Object
Recind upvote. Noop if authenticated user hasn’t previously voted
243 244 245 246 247 248 249 250 251 |
# 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. =~ /has not voted/i end self end |
#request_prefix ⇒ Object
:nodoc:
299 300 301 |
# File 'lib/trello/card.rb', line 299 def request_prefix "/cards/#{id}" end |
#upvote ⇒ Object
Current authenticated user upvotes a card
230 231 232 233 234 235 236 237 238 239 240 |
# 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. =~ /has already voted/i end self end |
#valid? ⇒ Boolean
Is the record valid?
165 166 167 |
# File 'lib/trello/card.rb', line 165 def valid? !(name && list_id).nil? end |
#voters(params = {}) ⇒ Array<Trello::Member>
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
130 131 132 |
# File 'lib/trello/card.rb', line 130 def voters(params = {}) Member.from_response client.get("/cards/#{id}/membersVoted", params) end |