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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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

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

Retrieve card members



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

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



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

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



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

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



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

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



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

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

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

Create a card resource



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

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]



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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

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

Retrieve card stickers



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

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

#subscribe_to_card(card_id) ⇒ Object

Subscribe to card



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

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

#unsubscribe_from_card(card_id) ⇒ Object

Unubscribe from card



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

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

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

Update card attributes



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

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

#update_card_name(card_id, name) ⇒ Object

Update card name



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

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



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

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



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

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



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

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



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

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