Module: Tacokit::Client::Cards

Included in:
Tacokit::Client
Defined in:
lib/tacokit/client/cards.rb

Overview

Methods for the Cards API

Instance Method Summary collapse

Instance Method Details

#add_checklist(card_id, name) ⇒ Object Also known as: start_checklist

Start a new checklist on card



207
208
209
# File 'lib/tacokit/client/cards.rb', line 207

def add_checklist(card_id, name)
  create_card_resource(card_id, "checklists", name: name)
end

#add_comment(card_id, text, options = {}) ⇒ Object Also known as: create_card_comment

Add a comment to a card



172
173
174
175
# File 'lib/tacokit/client/cards.rb', line 172

def add_comment(card_id, text, options = {})
  options.update text: text
  create_card_resource card_id, "actions", "comments", options
end

#add_label(card_id, color, options = {}) ⇒ Object

Add label to card



229
230
231
# File 'lib/tacokit/client/cards.rb', line 229

def add_label(card_id, color, options = {})
  create_card_resource(card_id, "labels", options.merge(color: color))
end

#add_member_to_card(card_id, member_id) ⇒ Object

Add a member to a card



222
223
224
# File 'lib/tacokit/client/cards.rb', line 222

def add_member_to_card(card_id, member_id)
  create_card_resource(card_id, "idMembers", value: member_id)
end

#add_sticker(card_id, image_name, options = {}) ⇒ Object Also known as: create_sticker

Add sticker to card



244
245
246
247
# File 'lib/tacokit/client/cards.rb', line 244

def add_sticker(card_id, image_name, options = {})
  defaults = { top: 0, left: 0, z_index: 1 }
  create_card_resource(card_id, "stickers", defaults.merge(options.merge(image: image_name)))
end

#archive_card(card_id) ⇒ Object

Archive a card



113
114
115
# File 'lib/tacokit/client/cards.rb', line 113

def archive_card(card_id)
  update_card(card_id, closed: true)
end

#attach_file(card_id, url, mime_type = nil, options = {}) ⇒ Object Also known as: create_card_attachment

Attach a file to a card



181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/tacokit/client/cards.rb', line 181

def attach_file(card_id, url, mime_type = nil, options = {})
  options = mime_type if mime_type.is_a?(Hash)

  uri = URI.parse(url)

  if uri.scheme =~ %r{https?}
    options.update url: uri.to_s, mime_type: mime_type
  else
    file = Faraday::UploadIO.new(uri.to_s, mime_type)
    options.update file: file, mime_type: file.content_type
  end

  create_card_resource card_id, "attachments", options
end

#attachment(card_id, attachment_id, options = {}) ⇒ Object

Retrieve a card attachment



34
35
36
# File 'lib/tacokit/client/cards.rb', line 34

def attachment(card_id, attachment_id, options = {})
  card_resource(card_id, "attachments/#{attachment_id}", options)
end

#attachments(card_id, options = {}) ⇒ Object Also known as: card_attachments

Retrieve card attachments



26
27
28
# File 'lib/tacokit/client/cards.rb', line 26

def attachments(card_id, options = {})
  card_resource(card_id, "attachments", options)
end

#card(card_id, options = nil) ⇒ Object

Retrieve a card by id or shortlink



12
13
14
# File 'lib/tacokit/client/cards.rb', line 12

def card(card_id, options = nil)
  get card_path(card_id), options
end

#card_actions(card_id, options = {}) ⇒ Object

Retrieve card actions



19
20
21
# File 'lib/tacokit/client/cards.rb', line 19

def card_actions(card_id, options = {})
  paginated_card_resource(card_id, "actions", options)
end

#card_board(card_id, options = {}) ⇒ Object

Retrieve a card board



41
42
43
# File 'lib/tacokit/client/cards.rb', line 41

def card_board(card_id, options = {})
  card_resource(card_id, "board", options)
end

#card_list(card_id, options = {}) ⇒ Object

Retrive a card list



63
64
65
# File 'lib/tacokit/client/cards.rb', line 63

def card_list(card_id, options = {})
  card_resource(card_id, "list", options)
end

#card_members(card_id, options = {}) ⇒ Object

Retrieve card members



70
71
72
# File 'lib/tacokit/client/cards.rb', line 70

def card_members(card_id, options = {})
  card_resource(card_id, "members", options)
end

#card_members_voted(card_id, options = {}) ⇒ Object

Retrieve members who voted on a card



77
78
79
# File 'lib/tacokit/client/cards.rb', line 77

def card_members_voted(card_id, options = {})
  card_resource(card_id, "members_voted", options)
end

#check_item_states(card_id, options = {}) ⇒ Object

Retrieve card checklist item states



48
49
50
# File 'lib/tacokit/client/cards.rb', line 48

def check_item_states(card_id, options = {})
  card_resource(card_id, "check_item_states", options)
end

#checklists(card_id, options = {}) ⇒ Object

Retrieve card checklists



55
56
57
# File 'lib/tacokit/client/cards.rb', line 55

def checklists(card_id, options = {})
  card_resource(card_id, "checklists", options)
end

#convert_to_card(card_id, checklist_id, check_item_id) ⇒ Object

Convert a checklist item to a card



200
201
202
# File 'lib/tacokit/client/cards.rb', line 200

def convert_to_card(card_id, checklist_id, check_item_id)
  create_card_resource(card_id, "checklist", checklist_id, "checkItem", check_item_id, "convertToCard")
end

#copy_checklist(card_id, checklist_id) ⇒ Object

Copy another checklist to card



215
216
217
# File 'lib/tacokit/client/cards.rb', line 215

def copy_checklist(card_id, checklist_id)
  create_card_resource(card_id, "checklists", checklist_source_id: checklist_id)
end

#create_card(list_id, name = nil, options = {}) ⇒ Object

Create a card



165
166
167
# File 'lib/tacokit/client/cards.rb', line 165

def create_card(list_id, name = nil, options = {})
  post "cards", options.merge(name: name, list_id: list_id)
end

#create_card_resource(card_id, resource, *paths) ⇒ Object

Create a card resource



252
253
254
255
# File 'lib/tacokit/client/cards.rb', line 252

def create_card_resource(card_id, resource, *paths)
  paths, options = extract_options(camp(resource), *paths)
  post card_path(card_id, *paths), options
end

#delete_card(card_id) ⇒ Object

DELETE cards/[card id or shortlink]



260
261
262
# File 'lib/tacokit/client/cards.rb', line 260

def delete_card(card_id)
  delete card_path(card_id)
end

#move_card(card_id, options) ⇒ Object

Move card to another position, board and/or list



128
129
130
131
132
133
# File 'lib/tacokit/client/cards.rb', line 128

def move_card(card_id, options)
  unless options.is_a?(Hash) && ([:board_id, :list_id, :pos].any? { |key| options.key? key })
    raise ArgumentError, "Required option: :pos, :board_id and/or :list_id"
  end
  update_card(card_id, options)
end

#remove_attachment(card_id, attachment_id) ⇒ Object Also known as: delete_attachement

Remove an attachment



275
276
277
# File 'lib/tacokit/client/cards.rb', line 275

def remove_attachment(card_id, attachment_id)
  delete_card_resource card_id, "attachments", attachment_id
end

#remove_card_member(card_id, member_id) ⇒ Object Also known as: delete_card_member

Remove a member from a card



291
292
293
# File 'lib/tacokit/client/cards.rb', line 291

def remove_card_member(card_id, member_id)
  delete_card_resource card_id, "idMembers", member_id
end

#remove_checklist(card_id, checklist_id) ⇒ Object Also known as: delete_checklist

Remove checklist



283
284
285
# File 'lib/tacokit/client/cards.rb', line 283

def remove_checklist(card_id, checklist_id)
  delete_card_resource card_id, "checklists", checklist_id
end

#remove_comment(card_id, comment_id) ⇒ Object Also known as: delete_comment

Remove a comment



267
268
269
# File 'lib/tacokit/client/cards.rb', line 267

def remove_comment(card_id, comment_id)
  delete_card_resource card_id, "actions", comment_id, "comments"
end

#remove_label(card_id, color) ⇒ Object Also known as: delete_label

Remove label from card



299
300
301
# File 'lib/tacokit/client/cards.rb', line 299

def remove_label(card_id, color)
  delete_card_resource card_id, "labels", color
end

#remove_sticker(card_id, sticker_id) ⇒ Object Also known as: delete_sticker

Remove a sticker from a card



315
316
317
# File 'lib/tacokit/client/cards.rb', line 315

def remove_sticker(card_id, sticker_id)
  delete_card_resource card_id, "stickers", sticker_id
end

#remove_vote(card_id, member_id) ⇒ Object Also known as: delete_vote

Remove a vote from a card



307
308
309
# File 'lib/tacokit/client/cards.rb', line 307

def remove_vote(card_id, member_id)
  delete_card_resource card_id, "membersVoted", member_id
end

#restore_card(card_id) ⇒ Object

Restore an archived card



120
121
122
# File 'lib/tacokit/client/cards.rb', line 120

def restore_card(card_id)
  update_card(card_id, closed: false)
end

#stickers(card_id, options = {}) ⇒ Object

Retrieve card stickers



84
85
86
# File 'lib/tacokit/client/cards.rb', line 84

def stickers(card_id, options = {})
  card_resource(card_id, "stickers", options)
end

#subscribe_to_card(card_id) ⇒ Object

Subscribe to card



145
146
147
# File 'lib/tacokit/client/cards.rb', line 145

def subscribe_to_card(card_id)
  put card_path(card_id, "subscribed"), value: true
end

#unsubscribe_from_card(card_id) ⇒ Object

Unubscribe from card



152
153
154
# File 'lib/tacokit/client/cards.rb', line 152

def unsubscribe_from_card(card_id)
  put card_path(card_id, "subscribed"), value: false
end

#update_card(card_id, options = {}) ⇒ Object

Update card attributes



91
92
93
# File 'lib/tacokit/client/cards.rb', line 91

def update_card(card_id, options = {})
  put card_path(card_id), options
end

#update_card_name(card_id, name) ⇒ Object

Update card name



138
139
140
# File 'lib/tacokit/client/cards.rb', line 138

def update_card_name(card_id, name)
  put card_path(card_id, "name"), value: name
end

#update_card_resource(card_id, resource, *paths) ⇒ Object

Update any card resource



157
158
159
160
# File 'lib/tacokit/client/cards.rb', line 157

def update_card_resource(card_id, resource, *paths)
  paths, options = extract_options(camp(resource), *paths)
  put card_path(card_id, *paths), options
end

#update_check_item(card_id, checklist_id, check_item_id, options = {}) ⇒ Object

Update checklist item text, position or state



106
107
108
# File 'lib/tacokit/client/cards.rb', line 106

def update_check_item(card_id, checklist_id, check_item_id, options = {})
  update_card_resource(card_id, "checklist", checklist_id, "checkItem", check_item_id, options)
end

#update_comment(card_id, comment_id, text, options = {}) ⇒ Object Also known as: edit_comment

Update comment text



98
99
100
# File 'lib/tacokit/client/cards.rb', line 98

def update_comment(card_id, comment_id, text, options = {})
  update_card_resource(card_id, "actions", comment_id, "comments", options.merge(text: text))
end

#vote(card_id, member_id) ⇒ Object Also known as: create_vote

Cast vote for card



236
237
238
# File 'lib/tacokit/client/cards.rb', line 236

def vote(card_id, member_id)
  create_card_resource(card_id, "membersVoted", value: member_id)
end