ruby-trello 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -10
  3. data/lib/trello.rb +57 -36
  4. data/lib/trello/action.rb +31 -23
  5. data/lib/trello/association_builder/has_many.rb +17 -0
  6. data/lib/trello/association_builder/has_one.rb +16 -0
  7. data/lib/trello/association_fetcher/has_many.rb +26 -0
  8. data/lib/trello/association_fetcher/has_many/fetch.rb +47 -0
  9. data/lib/trello/association_fetcher/has_many/params.rb +56 -0
  10. data/lib/trello/association_fetcher/has_one.rb +25 -0
  11. data/lib/trello/association_fetcher/has_one/fetch.rb +49 -0
  12. data/lib/trello/association_fetcher/has_one/params.rb +36 -0
  13. data/lib/trello/association_infer_tool.rb +13 -0
  14. data/lib/trello/association_proxy.rb +1 -1
  15. data/lib/trello/attachment.rb +40 -27
  16. data/lib/trello/basic_data.rb +112 -50
  17. data/lib/trello/board.rb +91 -101
  18. data/lib/trello/card.rb +53 -200
  19. data/lib/trello/checklist.rb +17 -71
  20. data/lib/trello/comment.rb +32 -22
  21. data/lib/trello/cover_image.rb +20 -0
  22. data/lib/trello/custom_field.rb +78 -0
  23. data/lib/trello/custom_field_item.rb +76 -0
  24. data/lib/trello/custom_field_option.rb +49 -0
  25. data/lib/trello/item.rb +27 -16
  26. data/lib/trello/item_state.rb +7 -15
  27. data/lib/trello/json_utils.rb +1 -1
  28. data/lib/trello/label.rb +15 -84
  29. data/lib/trello/label_name.rb +22 -25
  30. data/lib/trello/list.rb +31 -44
  31. data/lib/trello/member.rb +77 -31
  32. data/lib/trello/notification.rb +27 -20
  33. data/lib/trello/organization.rb +53 -25
  34. data/lib/trello/plugin_datum.rb +11 -16
  35. data/lib/trello/schema.rb +31 -0
  36. data/lib/trello/schema/attribute/base.rb +79 -0
  37. data/lib/trello/schema/attribute/board_pref.rb +45 -0
  38. data/lib/trello/schema/attribute/custom_field_display.rb +45 -0
  39. data/lib/trello/schema/attribute/default.rb +45 -0
  40. data/lib/trello/schema/attribute_builder.rb +42 -0
  41. data/lib/trello/schema/attribute_registration.rb +47 -0
  42. data/lib/trello/schema/serializer/default.rb +17 -0
  43. data/lib/trello/schema/serializer/labels.rb +23 -0
  44. data/lib/trello/schema/serializer/time.rb +25 -0
  45. data/lib/trello/schema/serializer/webhooks.rb +25 -0
  46. data/lib/trello/token.rb +15 -12
  47. data/lib/trello/webhook.rb +18 -71
  48. data/spec/action_spec.rb +2 -3
  49. data/spec/basic_data_spec.rb +58 -0
  50. data/spec/board_spec.rb +53 -100
  51. data/spec/card_spec.rb +177 -66
  52. data/spec/cassettes/action_find_with_id_and_get_all_fields.yml +104 -0
  53. data/spec/cassettes/board_find_with_id_and_get_all_fields.yml +96 -0
  54. data/spec/cassettes/board_find_with_id_and_get_specific_fields.yml +96 -0
  55. data/spec/cassettes/can_add_a_file_from_url_on_a_card.yml +189 -0
  56. data/spec/cassettes/can_add_a_file_on_a_card.yml +200 -0
  57. data/spec/cassettes/can_add_a_member_to_a_board.yml +191 -0
  58. data/spec/cassettes/can_add_a_member_to_a_card.yml +190 -0
  59. data/spec/cassettes/can_add_label_on_a_card.yml +281 -0
  60. data/spec/cassettes/can_arvhice_all_cards_of_list.yml +397 -0
  61. data/spec/cassettes/can_close_bong_a_card.yml +189 -0
  62. data/spec/cassettes/can_get_actions.yml +196 -0
  63. data/spec/cassettes/can_get_actions_of_board.yml +188 -0
  64. data/spec/cassettes/can_get_actions_of_list.yml +202 -0
  65. data/spec/cassettes/can_get_actions_of_members.yml +199 -0
  66. data/spec/cassettes/can_get_actions_of_organization.yml +201 -0
  67. data/spec/cassettes/can_get_attachments.yml +187 -0
  68. data/spec/cassettes/can_get_boards_of_custom_field.yml +198 -0
  69. data/spec/cassettes/can_get_boards_of_label.yml +197 -0
  70. data/spec/cassettes/can_get_boards_of_organization.yml +207 -0
  71. data/spec/cassettes/can_get_cards_of_board.yml +193 -0
  72. data/spec/cassettes/can_get_cards_of_list.yml +201 -0
  73. data/spec/cassettes/can_get_cards_of_member.yml +204 -0
  74. data/spec/cassettes/can_get_checklists_of_board.yml +187 -0
  75. data/spec/cassettes/can_get_comments.yml +193 -0
  76. data/spec/cassettes/can_get_custom_field_options_of_custom_field.yml +197 -0
  77. data/spec/cassettes/can_get_custom_fields_of_board.yml +187 -0
  78. data/spec/cassettes/can_get_label_names_of_board.yml +187 -0
  79. data/spec/cassettes/can_get_labels_of_board.yml +187 -0
  80. data/spec/cassettes/can_get_lists_of_board.yml +187 -0
  81. data/spec/cassettes/can_get_members_of_board.yml +188 -0
  82. data/spec/cassettes/can_get_members_of_organization.yml +200 -0
  83. data/spec/cassettes/can_get_notifications_of_member.yml +199 -0
  84. data/spec/cassettes/can_get_organization_of_board.yml +189 -0
  85. data/spec/cassettes/can_get_organizations_of_member.yml +203 -0
  86. data/spec/cassettes/can_get_plugin_data_of_board.yml +187 -0
  87. data/spec/cassettes/can_move_a_card_to_another_board_with_specific_list.yml +373 -0
  88. data/spec/cassettes/can_move_a_card_to_another_board_without_specific_list.yml +281 -0
  89. data/spec/cassettes/can_move_a_card_to_another_list.yml +281 -0
  90. data/spec/cassettes/can_move_all_cards_to_another_list.yml +886 -0
  91. data/spec/cassettes/can_remove_a_member_from_a_card.yml +185 -0
  92. data/spec/cassettes/can_remove_an_attachment_on_a_card.yml +277 -0
  93. data/spec/cassettes/can_remove_an_upvote_on_a_card.yml +465 -0
  94. data/spec/cassettes/can_remove_label_on_a_card.yml +279 -0
  95. data/spec/cassettes/can_success_add_comment_to_a_card.yml +196 -0
  96. data/spec/cassettes/can_success_copy_checklist_to_a_card.yml +281 -0
  97. data/spec/cassettes/can_success_copy_checklist_to_a_card_without_name_pos.yml +281 -0
  98. data/spec/cassettes/can_success_create_a_board.yml +98 -0
  99. data/spec/cassettes/can_success_create_a_board_with_full_parameters.yml +97 -0
  100. data/spec/cassettes/can_success_create_a_board_without_clone_from_other.yml +98 -0
  101. data/spec/cassettes/can_success_create_a_card.yml +99 -0
  102. data/spec/cassettes/can_success_create_a_card_when_due_is_datetime.yml +98 -0
  103. data/spec/cassettes/can_success_create_a_card_when_due_is_time.yml +98 -0
  104. data/spec/cassettes/can_success_create_a_checklist.yml +102 -0
  105. data/spec/cassettes/can_success_create_a_custom_field.yml +102 -0
  106. data/spec/cassettes/can_success_create_a_custom_field_option.yml +102 -0
  107. data/spec/cassettes/can_success_create_a_label.yml +102 -0
  108. data/spec/cassettes/can_success_create_a_list.yml +102 -0
  109. data/spec/cassettes/can_success_create_a_list_with_full_parameters.yml +102 -0
  110. data/spec/cassettes/can_success_create_a_organization.yml +104 -0
  111. data/spec/cassettes/can_success_create_a_webhook.yml +102 -0
  112. data/spec/cassettes/can_success_create_new_checklist_to_a_card.yml +189 -0
  113. data/spec/cassettes/can_success_delete_a_custom_field_option.yml +389 -0
  114. data/spec/cassettes/can_success_delete_card.yml +185 -0
  115. data/spec/cassettes/can_success_delete_checklist.yml +284 -0
  116. data/spec/cassettes/can_success_get_card_of_board_by_card_id.yml +188 -0
  117. data/spec/cassettes/can_success_remove_member_from_board.yml +186 -0
  118. data/spec/cassettes/can_success_return_all_boards_of_current_user.yml +195 -0
  119. data/spec/cassettes/can_success_upate_a_board.yml +191 -0
  120. data/spec/cassettes/can_success_upate_a_card.yml +189 -0
  121. data/spec/cassettes/can_success_upate_a_list.yml +296 -0
  122. data/spec/cassettes/can_success_update_bong_a_board.yml +283 -0
  123. data/spec/cassettes/can_success_update_bong_a_board_with_specific_fields.yml +284 -0
  124. data/spec/cassettes/can_success_update_bong_a_card.yml +191 -0
  125. data/spec/cassettes/can_success_update_bong_a_checklist_with_specific_fields.yml +296 -0
  126. data/spec/cassettes/can_success_update_bong_a_custom_field.yml +200 -0
  127. data/spec/cassettes/can_success_update_bong_a_label.yml +200 -0
  128. data/spec/cassettes/can_success_update_bong_a_list.yml +199 -0
  129. data/spec/cassettes/can_success_update_bong_a_list_with_specific_fields.yml +296 -0
  130. data/spec/cassettes/can_success_update_bong_a_organization.yml +203 -0
  131. data/spec/cassettes/can_success_update_bong_a_webhook.yml +296 -0
  132. data/spec/cassettes/can_upvote_on_a_card.yml +469 -0
  133. data/spec/cassettes/card_find_with_id_and_get_all_fields.yml +95 -0
  134. data/spec/cassettes/card_find_with_id_and_get_specific_fields.yml +96 -0
  135. data/spec/cassettes/checklist_can_add_an_item.yml +296 -0
  136. data/spec/cassettes/checklist_can_update_the_item_state.yml +296 -0
  137. data/spec/cassettes/checklist_find_with_id_and_get_all_fields.yml +100 -0
  138. data/spec/cassettes/custom_field_find_with_id_and_get_all_fields.yml +100 -0
  139. data/spec/cassettes/custom_field_find_with_id_and_get_specific_fields.yml +100 -0
  140. data/spec/cassettes/custom_field_item_save_1.yml +97 -0
  141. data/spec/cassettes/custom_field_item_save_2.yml +281 -0
  142. data/spec/cassettes/custom_field_option_find_with_id.yml +100 -0
  143. data/spec/cassettes/get_board_of_card.yml +187 -0
  144. data/spec/cassettes/get_board_of_list.yml +197 -0
  145. data/spec/cassettes/get_boards_of_member.yml +207 -0
  146. data/spec/cassettes/get_check_item_states_of_card.yml +188 -0
  147. data/spec/cassettes/get_checklists_of_card.yml +187 -0
  148. data/spec/cassettes/get_cover_image_of_card.yml +187 -0
  149. data/spec/cassettes/get_custom_field_items_of_card.yml +187 -0
  150. data/spec/cassettes/get_list_of_card.yml +188 -0
  151. data/spec/cassettes/get_lists.yml +187 -0
  152. data/spec/cassettes/get_members_of_card.yml +189 -0
  153. data/spec/cassettes/get_plugin_data_of_card.yml +187 -0
  154. data/spec/cassettes/get_voters_of_card.yml +188 -0
  155. data/spec/cassettes/label_delete.yml +285 -0
  156. data/spec/cassettes/label_find_with_id.yml +100 -0
  157. data/spec/cassettes/list_find_with_id_and_get_all_fields.yml +100 -0
  158. data/spec/cassettes/list_find_with_id_and_get_specific_fields.yml +100 -0
  159. data/spec/cassettes/member_find_with_id_and_get_all_fields.yml +101 -0
  160. data/spec/cassettes/member_find_with_id_and_get_specific_fields.yml +100 -0
  161. data/spec/cassettes/notification_find_with_id.yml +103 -0
  162. data/spec/cassettes/organization_find_with_id_and_get_all_fields.yml +102 -0
  163. data/spec/cassettes/organization_find_with_id_and_get_specific_fields.yml +100 -0
  164. data/spec/cassettes/remove_upvote_on_a_card_when_have_not_voted.yml +366 -0
  165. data/spec/cassettes/revote_on_a_card.yml +464 -0
  166. data/spec/cassettes/token_find_with_token_string.yml +100 -0
  167. data/spec/cassettes/webhook_delete.yml +286 -0
  168. data/spec/cassettes/webhook_find_with_id.yml +100 -0
  169. data/spec/checklist_spec.rb +27 -43
  170. data/spec/custom_field_item_spec.rb +192 -0
  171. data/spec/custom_field_option_spec.rb +49 -0
  172. data/spec/custom_field_spec.rb +273 -0
  173. data/spec/integration/action/find_spec.rb +23 -0
  174. data/spec/integration/basic_data/many_spec.rb +127 -0
  175. data/spec/integration/basic_data/one_spec.rb +84 -0
  176. data/spec/integration/basic_data/schema_spec.rb +156 -0
  177. data/spec/integration/board/add_member_spec.rb +21 -0
  178. data/spec/integration/board/all_spec.rb +20 -0
  179. data/spec/integration/board/associations/actions_spec.rb +18 -0
  180. data/spec/integration/board/associations/cards_spec.rb +18 -0
  181. data/spec/integration/board/associations/checklists_spec.rb +18 -0
  182. data/spec/integration/board/associations/custom_fields_spec.rb +18 -0
  183. data/spec/integration/board/associations/label_names_spec.rb +17 -0
  184. data/spec/integration/board/associations/labels_spec.rb +18 -0
  185. data/spec/integration/board/associations/lists_spec.rb +18 -0
  186. data/spec/integration/board/associations/members_spec.rb +18 -0
  187. data/spec/integration/board/associations/organization_spec.rb +19 -0
  188. data/spec/integration/board/associations/plugin_data_spec.rb +18 -0
  189. data/spec/integration/board/create_spec.rb +95 -0
  190. data/spec/integration/board/find_card_spec.rb +18 -0
  191. data/spec/integration/board/find_spec.rb +42 -0
  192. data/spec/integration/board/remove_member_spec.rb +21 -0
  193. data/spec/integration/board/save_spec.rb +37 -0
  194. data/spec/integration/board/update!_spec.rb +62 -0
  195. data/spec/integration/board_lists_spec.rb +21 -0
  196. data/spec/integration/card/add_and_remove_attachment_spec.rb +45 -0
  197. data/spec/integration/card/add_and_remove_label_spec.rb +35 -0
  198. data/spec/integration/card/add_checklist_spec.rb +32 -0
  199. data/spec/integration/card/add_comment_spec.rb +19 -0
  200. data/spec/integration/card/add_memeber_spec.rb +19 -0
  201. data/spec/integration/card/associations/actions_spec.rb +17 -0
  202. data/spec/integration/card/associations/attachments_spec.rb +18 -0
  203. data/spec/integration/card/associations/board_spec.rb +17 -0
  204. data/spec/integration/card/associations/check_item_states_spec.rb +17 -0
  205. data/spec/integration/card/associations/checklists_spec.rb +18 -0
  206. data/spec/integration/card/associations/comments_spec.rb +19 -0
  207. data/spec/integration/card/associations/cover_image_spec.rb +18 -0
  208. data/spec/integration/card/associations/custom_field_items_spec.rb +18 -0
  209. data/spec/integration/card/associations/list_spec.rb +16 -0
  210. data/spec/integration/card/associations/members_spec.rb +18 -0
  211. data/spec/integration/card/associations/plugin_data_spec.rb +18 -0
  212. data/spec/integration/card/associations/voters_spec.rb +17 -0
  213. data/spec/integration/card/close!_spec.rb +16 -0
  214. data/spec/integration/card/create_new_check_list_spec.rb +19 -0
  215. data/spec/integration/card/create_spec.rb +84 -0
  216. data/spec/integration/card/delete_spec.rb +16 -0
  217. data/spec/integration/card/find_spec.rb +67 -0
  218. data/spec/integration/card/move_to_board_spec.rb +36 -0
  219. data/spec/integration/card/move_to_list_spec.rb +20 -0
  220. data/spec/integration/card/remove_member_spec.rb +19 -0
  221. data/spec/integration/card/save_spec.rb +61 -0
  222. data/spec/integration/card/update!_spec.rb +53 -0
  223. data/spec/integration/card/vote_spec.rb +50 -0
  224. data/spec/integration/checklist/add_item_spec.rb +20 -0
  225. data/spec/integration/checklist/create_spec.rb +23 -0
  226. data/spec/integration/checklist/delete_spec.rb +17 -0
  227. data/spec/integration/checklist/find_spec.rb +22 -0
  228. data/spec/integration/checklist/update!_spec.rb +21 -0
  229. data/spec/integration/checklist/update_item_state_spec.rb +20 -0
  230. data/spec/integration/custom_field/association/board_spec.rb +18 -0
  231. data/spec/integration/custom_field/association/custom_field_options_spec.rb +18 -0
  232. data/spec/integration/custom_field/create_spec.rb +29 -0
  233. data/spec/integration/custom_field/find_spec.rb +41 -0
  234. data/spec/integration/custom_field/update!_spec.rb +25 -0
  235. data/spec/integration/custom_field_item_spec.rb +47 -0
  236. data/spec/integration/custom_field_option/create_spec.rb +23 -0
  237. data/spec/integration/custom_field_option/delete_spec.rb +19 -0
  238. data/spec/integration/custom_field_option/find_spec.rb +21 -0
  239. data/spec/integration/label/association/board_spec.rb +18 -0
  240. data/spec/integration/label/create_spec.rb +23 -0
  241. data/spec/integration/label/delete_spec.rb +21 -0
  242. data/spec/integration/label/find_spec.rb +20 -0
  243. data/spec/integration/label/update!_spec.rb +25 -0
  244. data/spec/integration/list/archive_all_cards_spec.rb +20 -0
  245. data/spec/integration/list/associations/actions_spec.rb +18 -0
  246. data/spec/integration/list/associations/board_spec.rb +18 -0
  247. data/spec/integration/list/associations/cards_spec.rb +18 -0
  248. data/spec/integration/list/create_spec.rb +44 -0
  249. data/spec/integration/list/find_spec.rb +37 -0
  250. data/spec/integration/list/move_all_cards_spec.rb +31 -0
  251. data/spec/integration/list/save_spec.rb +40 -0
  252. data/spec/integration/list/update!_spec.rb +43 -0
  253. data/spec/integration/member/associations/actions_spec.rb +17 -0
  254. data/spec/integration/member/associations/boards_spec.rb +18 -0
  255. data/spec/integration/member/associations/cards_spec.rb +18 -0
  256. data/spec/integration/member/associations/notifications_spec.rb +18 -0
  257. data/spec/integration/member/associations/organizations_spec.rb +18 -0
  258. data/spec/integration/member/find_spec.rb +39 -0
  259. data/spec/integration/member/update!_spec.rb +18 -0
  260. data/spec/integration/notification/find_spec.rb +27 -0
  261. data/spec/integration/organization/associations/actions_spec.rb +18 -0
  262. data/spec/integration/organization/associations/boards_spec.rb +18 -0
  263. data/spec/integration/organization/associations/members_spec.rb +18 -0
  264. data/spec/integration/organization/create_spec.rb +23 -0
  265. data/spec/integration/organization/find_spec.rb +37 -0
  266. data/spec/integration/organization/update!_spec.rb +28 -0
  267. data/spec/integration/token/find_spec.rb +24 -0
  268. data/spec/integration/webhook/create_spec.rb +27 -0
  269. data/spec/integration/webhook/delete_spec.rb +21 -0
  270. data/spec/integration/webhook/find_spec.rb +22 -0
  271. data/spec/integration/webhook/update!_spec.rb +24 -0
  272. data/spec/item_spec.rb +2 -2
  273. data/spec/label_spec.rb +105 -28
  274. data/spec/list_spec.rb +32 -14
  275. data/spec/notification_spec.rb +3 -3
  276. data/spec/organization_spec.rb +6 -5
  277. data/spec/spec_helper.rb +118 -37
  278. data/spec/token_spec.rb +10 -11
  279. data/spec/unit/trello/association_builder/has_many_spec.rb +36 -0
  280. data/spec/unit/trello/association_builder/has_one_spec.rb +36 -0
  281. data/spec/unit/trello/association_fetcher/has_many/fetch_spec.rb +38 -0
  282. data/spec/unit/trello/association_fetcher/has_many/params_spec.rb +107 -0
  283. data/spec/unit/trello/association_fetcher/has_many_spec.rb +50 -0
  284. data/spec/unit/trello/association_fetcher/has_one/fetch_spec.rb +51 -0
  285. data/spec/unit/trello/association_fetcher/has_one/params_spec.rb +81 -0
  286. data/spec/unit/trello/association_fetcher/has_one_spec.rb +49 -0
  287. data/spec/unit/trello/association_infer_tool_spec.rb +41 -0
  288. data/spec/unit/trello/basic_data_spec.rb +113 -0
  289. data/spec/unit/trello/board/new_spec.rb +370 -0
  290. data/spec/unit/trello/board/save_spec.rb +49 -0
  291. data/spec/unit/trello/board/update_fields_spec.rb +129 -0
  292. data/spec/unit/trello/board/update_spec.rb +197 -0
  293. data/spec/unit/trello/card_spec.rb +103 -0
  294. data/spec/unit/trello/member/new_spec.rb +62 -0
  295. data/spec/unit/trello/member/update_fields_spec.rb +80 -0
  296. data/spec/unit/trello/schema/attribute/base_spec.rb +349 -0
  297. data/spec/unit/trello/schema/attribute/board_pref_spec.rb +208 -0
  298. data/spec/unit/trello/schema/attribute/default_spec.rb +236 -0
  299. data/spec/unit/trello/schema/attribute_builder_spec.rb +55 -0
  300. data/spec/unit/trello/schema/attribute_registration_spec.rb +59 -0
  301. data/spec/unit/trello/schema/serializer/default_spec.rb +19 -0
  302. data/spec/unit/trello/schema/serializer/time_spec.rb +39 -0
  303. data/spec/unit/trello/schema_spec.rb +25 -0
  304. data/spec/webhook_spec.rb +23 -7
  305. metadata +542 -29
@@ -43,162 +43,54 @@ module Trello
43
43
  # @return [Array<String>] Array of strings
44
44
 
45
45
  class Card < BasicData
46
- register_attributes :id, :short_id, :name, :desc, :due, :due_complete, :closed, :url, :short_url,
47
- :board_id, :member_ids, :list_id, :pos, :last_activity_date, :labels, :card_labels,
48
- :cover_image_id, :badges, :card_members, :source_card_id, :source_card_properties,
49
- readonly: [ :id, :short_id, :url, :short_url, :last_activity_date, :badges, :card_members ]
46
+ schema do
47
+ # readonly
48
+ attribute :id, readonly: true, primary_key: true
49
+ attribute :short_id, readonly: true, remote_key: 'idShort'
50
+ attribute :url, readonly: true
51
+ attribute :short_url, readonly: true, remote_key: 'shortUrl'
52
+ attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time'
53
+ attribute :labels, readonly: true, default: [], serializer: 'Labels'
54
+ attribute :badges, readonly: true
55
+ attribute :card_members, readonly: true, remote_key: 'members'
56
+
57
+ # Writable
58
+ attribute :name
59
+ attribute :desc
60
+ attribute :due, serializer: 'Time'
61
+ attribute :due_complete, remote_key: 'dueComplete'
62
+ attribute :member_ids, remote_key: 'idMembers'
63
+ attribute :list_id, remote_key: 'idList'
64
+ attribute :pos
65
+ attribute :card_labels, remote_key: 'idLabels'
66
+
67
+ # Writable but for create only
68
+ attribute :source_card_id, create_only: true, remote_key: 'idCardSource'
69
+ attribute :keep_from_source, create_only: true, remote_key: 'keepFromSource'
70
+
71
+ # Writable but for update only
72
+ attribute :closed, update_only: true
73
+ attribute :board_id, update_only: true, remote_key: 'idBoard'
74
+ attribute :cover_image_id, update_only: true, remote_key: 'idAttachmentCover'
75
+
76
+ # Deprecated
77
+ attribute :source_card_properties, create_only: true, remote_key: 'keepFromSource'
78
+ end
79
+
50
80
  validates_presence_of :id, :name, :list_id
51
81
  validates_length_of :name, in: 1..16384
52
82
  validates_length_of :desc, in: 0..16384
53
83
 
54
84
  include HasActions
55
85
 
56
- SYMBOL_TO_STRING = {
57
- id: 'id',
58
- short_id: 'idShort',
59
- name: 'name',
60
- desc: 'desc',
61
- due: 'due',
62
- due_complete: 'dueComplete',
63
- closed: 'closed',
64
- url: 'url',
65
- short_url: 'shortUrl',
66
- board_id: 'idBoard',
67
- member_ids: 'idMembers',
68
- cover_image_id: 'idAttachmentCover',
69
- list_id: 'idList',
70
- pos: 'pos',
71
- last_activity_date: 'dateLastActivity',
72
- card_labels: 'idLabels',
73
- labels: 'labels',
74
- badges: 'badges',
75
- card_members: 'members',
76
- source_card_id: "idCardSource",
77
- source_card_properties: "keepFromSource"
78
- }
79
-
80
- class << self
81
- # Find a specific card by its id.
82
- #
83
- # @raise [Trello::Error] if the card could not be found.
84
- #
85
- # @return [Trello::Card]
86
- def find(id, params = {})
87
- client.find(:card, id, params)
88
- end
89
-
90
- # Create a new card and save it on Trello.
91
- #
92
- # If using source_card_id to duplicate a card, make sure to save
93
- # the source card to Trello before calling this method to assure
94
- # the correct data is used in the duplication.
95
- #
96
- # @param [Hash] options
97
- # @option options [String] :name The name of the new card.
98
- # @option options [String] :list_id ID of the list that the card should
99
- # be added to.
100
- # @option options [String] :desc A string with a
101
- # length from 0 to 16384.
102
- # @option options [String] :member_ids A comma-separated list of
103
- # objectIds (24-character hex strings).
104
- # @option options [String] :card_labels A comma-separated list of
105
- # objectIds (24-character hex strings).
106
- # @option options [Date] :due A date, or `nil`.
107
- # @option options [String] :pos A position. `"top"`, `"bottom"`, or a
108
- # positive number. Defaults to `"bottom"`.
109
- # @option options [String] :source_card_id ID of the card to copy
110
- # @option options [String] :source_card_properties A single, or array of,
111
- # string properties to copy from source card.
112
- # `"all"`, `"checklists"`, `"due"`, `"members"`, or `nil`.
113
- # Defaults to `"all"`.
114
- #
115
- # @raise [Trello::Error] if the card could not be created.
116
- #
117
- # @return [Trello::Card]
118
- def create(options)
119
- client.create(:card,
120
- 'name' => options[:name],
121
- 'idList' => options[:list_id],
122
- 'desc' => options[:desc],
123
- 'idMembers' => options[:member_ids],
124
- 'idLabels' => options[:card_labels],
125
- 'due' => options[:due],
126
- 'due_complete' => options[:due_complete] || false,
127
- 'pos' => options[:pos],
128
- 'idCardSource' => options[:source_card_id],
129
- 'keepFromSource' => options.key?(:source_card_properties) ? options[:source_card_properties] : 'all'
130
- )
131
- end
132
- end
133
-
134
- # Update the fields of a card.
135
- #
136
- # Supply a hash of string keyed data retrieved from the Trello API representing
137
- # a card.
138
- #
139
- # Note that this this method does not save anything new to the Trello API,
140
- # it just assigns the input attributes to your local object. If you use
141
- # this method to assign attributes, call `save` or `update!` afterwards if
142
- # you want to persist your changes to Trello.
143
- #
144
- # @param [Hash] fields
145
- # @option fields [String] :id
146
- # @option fields [String] :short_id
147
- # @option fields [String] :name The new name of the card.
148
- # @option fields [String] :desc A string with a length from 0 to
149
- # 16384.
150
- # @option fields [Date] :due A date, or `nil`.
151
- # @option fields [Boolean] :due_complete
152
- # @option fields [Boolean] :closed
153
- # @option fields [String] :url
154
- # @option fields [String] :short_url
155
- # @option fields [String] :board_id
156
- # @option fields [String] :member_ids A comma-separated list of objectIds
157
- # (24-character hex strings).
158
- # @option fields [String] :pos A position. `"top"`, `"bottom"`, or a
159
- # positive number. Defaults to `"bottom"`.
160
- # @option fields [Array] :labels An Array of Trello::Label objects
161
- # derived from the JSON response
162
- # @option fields [String] :card_labels A comma-separated list of
163
- # objectIds (24-character hex strings).
164
- # @option fields [Object] :cover_image_id
165
- # @option fields [Object] :badges
166
- # @option fields [Object] :card_members
167
- # @option fields [String] :source_card_id
168
- # @option fields [Array] :source_card_properties
169
- #
170
- # @return [Trello::Card] self
171
- def update_fields(fields)
172
- attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || attributes[:id]
173
- attributes[:short_id] = fields[SYMBOL_TO_STRING[:short_id]] || attributes[:short_id]
174
- attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name]
175
- attributes[:desc] = fields[SYMBOL_TO_STRING[:desc]] || fields[:desc] || attributes[:desc]
176
- attributes[:due] = Time.iso8601(fields[SYMBOL_TO_STRING[:due]]) rescue nil if fields.has_key?(SYMBOL_TO_STRING[:due])
177
- attributes[:due] = fields[:due] if fields.has_key?(:due)
178
- attributes[:due_complete] = fields[SYMBOL_TO_STRING[:due_complete]] if fields.has_key?(SYMBOL_TO_STRING[:due_complete])
179
- attributes[:due_complete] ||= false
180
- attributes[:closed] = fields[SYMBOL_TO_STRING[:closed]] if fields.has_key?(SYMBOL_TO_STRING[:closed])
181
- attributes[:url] = fields[SYMBOL_TO_STRING[:url]] || attributes[:url]
182
- attributes[:short_url] = fields[SYMBOL_TO_STRING[:short_url]] || attributes[:short_url]
183
- attributes[:board_id] = fields[SYMBOL_TO_STRING[:board_id]] || attributes[:board_id]
184
- attributes[:member_ids] = fields[SYMBOL_TO_STRING[:member_ids]] || fields[:member_ids] || attributes[:member_ids]
185
- attributes[:list_id] = fields[SYMBOL_TO_STRING[:list_id]] || fields[:list_id] || attributes[:list_id]
186
- attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos]
187
- attributes[:labels] = (fields[SYMBOL_TO_STRING[:labels]] || []).map { |lbl| Trello::Label.new(lbl) }.presence || attributes[:labels].presence || []
188
- attributes[:card_labels] = fields[SYMBOL_TO_STRING[:card_labels]] || fields[:card_labels] || attributes[:card_labels]
189
- attributes[:last_activity_date] = Time.iso8601(fields[SYMBOL_TO_STRING[:last_activity_date]]) rescue nil if fields.has_key?(SYMBOL_TO_STRING[:last_activity_date])
190
- attributes[:cover_image_id] = fields[SYMBOL_TO_STRING[:cover_image_id]] || attributes[:cover_image_id]
191
- attributes[:badges] = fields[SYMBOL_TO_STRING[:badges]] || attributes[:badges]
192
- attributes[:card_members] = fields[SYMBOL_TO_STRING[:card_members]] || attributes[:card_members]
193
- attributes[:source_card_id] = fields[SYMBOL_TO_STRING[:source_card_id]] || fields[:source_card_id] || attributes[:source_card_id]
194
- attributes[:source_card_properties] = fields[SYMBOL_TO_STRING[:source_card_properties]] || fields[:source_card_properties] || attributes[:source_card_properties]
195
- self
196
- end
197
-
198
86
  # Returns a reference to the board this card is part of.
199
87
  one :board, path: :boards, using: :board_id
88
+
200
89
  # Returns a reference to the cover image attachment
201
- one :cover_image, path: :attachments, using: :cover_image_id
90
+ def cover_image(params = {})
91
+ response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params)
92
+ CoverImage.from_response(response)
93
+ end
202
94
 
203
95
  # Returns a list of checklists associated with the card.
204
96
  #
@@ -210,6 +102,9 @@ module Trello
210
102
  # Returns a list of plugins associated with the card
211
103
  many :plugin_data, path: "pluginData"
212
104
 
105
+ # List of custom field values on the card, only the ones that have been set
106
+ many :custom_field_items, path: 'customFieldItems'
107
+
213
108
  def check_item_states
214
109
  states = CheckItemState.from_response client.get("/cards/#{self.id}/checkItemStates")
215
110
  MultiAssociation.new(self, states).proxy
@@ -222,9 +117,7 @@ module Trello
222
117
  #
223
118
  # @return [Array<Trello::Member>]
224
119
  def members
225
- members = member_ids.map do |member_id|
226
- Member.from_response client.get("/members/#{member_id}")
227
- end
120
+ members = Member.from_response client.get("/cards/#{self.id}/members")
228
121
  MultiAssociation.new(self, members).proxy
229
122
  end
230
123
 
@@ -238,49 +131,6 @@ module Trello
238
131
  Member.from_response client.get("/cards/#{id}/membersVoted")
239
132
  end
240
133
 
241
- # Saves a record.
242
- #
243
- # @raise [Trello::Error] if the card could not be saved
244
- #
245
- # @return [String] The JSON representation of the saved card returned by
246
- # the Trello API.
247
- def save
248
- # If we have an id, just update our fields.
249
- return update! if id
250
-
251
- from_response client.post("/cards", {
252
- name: name,
253
- desc: desc,
254
- idList: list_id,
255
- idMembers: member_ids,
256
- idLabels: card_labels,
257
- pos: pos,
258
- due: due,
259
- dueComplete: due_complete,
260
- idCardSource: source_card_id,
261
- keepFromSource: source_card_properties
262
- })
263
- end
264
-
265
- # Update an existing record.
266
- #
267
- # Warning: this updates all fields using values already in memory. If
268
- # an external resource has updated these fields, you should refresh!
269
- # this object before making your changes, and before updating the record.
270
- #
271
- # @raise [Trello::Error] if the card could not be updated.
272
- #
273
- # @return [String] The JSON representation of the updated card returned by
274
- # the Trello API.
275
- def update!
276
- @previously_changed = changes
277
- # extract only new values to build payload
278
- payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
279
- @changed_attributes.clear
280
-
281
- client.put("/cards/#{id}", payload)
282
- end
283
-
284
134
  # Delete this card
285
135
  #
286
136
  # @return [String] the JSON response from the Trello API
@@ -313,7 +163,7 @@ module Trello
313
163
 
314
164
  # Is the record valid?
315
165
  def valid?
316
- name && list_id
166
+ !(name && list_id).nil?
317
167
  end
318
168
 
319
169
  # Add a comment with the supplied text.
@@ -322,10 +172,12 @@ module Trello
322
172
  end
323
173
 
324
174
  # Add a checklist to this card
325
- def add_checklist(checklist)
326
- client.post("/cards/#{id}/checklists", {
327
- value: checklist.id
328
- })
175
+ def add_checklist(checklist, name: nil, position: nil)
176
+ payload = { idChecklistSource: checklist.id }
177
+ payload[:name] = name if name
178
+ payload[:pos] = position if position
179
+
180
+ client.post("/cards/#{id}/checklists", payload)
329
181
  end
330
182
 
331
183
  # create a new checklist and add it to this card
@@ -364,14 +216,14 @@ module Trello
364
216
 
365
217
  # Add a member to this card
366
218
  def add_member(member)
367
- client.post("/cards/#{id}/members", {
219
+ client.post("/cards/#{id}/idMembers", {
368
220
  value: member.id
369
221
  })
370
222
  end
371
223
 
372
224
  # Remove a member from this card
373
225
  def remove_member(member)
374
- client.delete("/cards/#{id}/members/#{member.id}")
226
+ client.delete("/cards/#{id}/idMembers/#{member.id}")
375
227
  end
376
228
 
377
229
  # Current authenticated user upvotes a card
@@ -463,5 +315,6 @@ module Trello
463
315
  def me
464
316
  @me ||= Member.find(:me)
465
317
  end
318
+
466
319
  end
467
320
  end
@@ -5,78 +5,35 @@ module Trello
5
5
  # @return [String]
6
6
  # @!attribute [rw] name
7
7
  # @return [String]
8
- # @!attribute [r] description
9
- # @return [String]
10
- # @!attribute [r] closed
11
- # @return [Boolean]
12
8
  # @!attribute [rw] position
13
9
  # @return [Object]
14
- # @!attribute [r] url
15
- # @return [String]
16
10
  # @!attribute [r] check_items
17
11
  # @return [Object]
18
12
  # @!attribute [r] board_id
19
13
  # @return [String] A 24-character hex string
20
- # @!attribute [r] list_id
21
- # @return [String] A 24-character hex string
22
- # @!attribute [r] member_ids
23
- # @return [Array<String>] An array of 24-character hex strings
14
+ # @!attribute [rw] card_id
15
+ # @return [String]
16
+ # @!attribute [w] source_checklist_id
17
+ # @return [String]
24
18
  class Checklist < BasicData
25
- register_attributes :id, :name, :description, :closed, :position, :url, :check_items, :board_id, :list_id, :card_id, :member_ids,
26
- readonly: [:id, :description, :closed, :url, :check_items, :board_id, :list_id, :card_id, :member_ids]
27
- validates_presence_of :id, :board_id, :list_id
28
- validates_length_of :name, in: 1..16384
29
-
30
- class << self
31
- # Locate a specific checklist by its id.
32
- def find(id, params = {})
33
- client.find(:checklist, id, params)
34
- end
35
-
36
- def create(options)
37
- client.create(:checklist,
38
- 'name' => options[:name],
39
- 'idCard' => options[:card_id])
40
- end
41
- end
19
+ schema do
20
+ attribute :id, readonly: true, primary_key: true
42
21
 
43
- # Update the fields of a checklist.
44
- #
45
- # Supply a hash of string keyed data retrieved from the Trello API representing
46
- # a checklist.
47
- def update_fields(fields)
48
- attributes[:id] = fields['id'] || attributes[:id]
49
- attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
50
- attributes[:description] = fields['desc'] || attributes[:description]
51
- attributes[:closed] = fields['closed'] if fields.has_key?('closed')
52
- attributes[:url] = fields['url'] || attributes[:url]
53
- attributes[:check_items] = fields['checkItems'] if fields.has_key?('checkItems')
54
- attributes[:position] = fields['pos'] || attributes[:position]
55
- attributes[:board_id] = fields['idBoard'] || attributes[:board_id]
56
- attributes[:card_id] = fields['idCard'] || fields[:card_id] || attributes[:card_id]
57
- attributes[:list_id] = fields['idList'] || attributes[:list_id]
58
- attributes[:member_ids] = fields['idMembers'] || attributes[:member_ids]
59
- self
60
- end
22
+ # Readonly
23
+ attribute :check_items, readonly: true, remote_key: 'checkItems'
24
+ attribute :board_id, readonly: true, remote_key: 'idBoard'
61
25
 
62
- # Check if the checklist is currently active.
63
- def closed?
64
- closed
65
- end
26
+ # Writable
27
+ attribute :name
28
+ attribute :position, remote_key: 'pos'
66
29
 
67
- # Save a record.
68
- def save
69
- return update! if id
70
-
71
- from_response(client.post("/checklists", {
72
- name: name,
73
- idCard: card_id
74
- }))
30
+ # Writable but for update only
31
+ attribute :card_id, create_only: true, remote_key: 'idCard'
32
+ attribute :source_checklist_id, create_only: true, remote_key: 'idChecklistSource'
75
33
  end
76
34
 
77
- def update!
78
- from_response(client.put("/checklists/#{id}", {name: name, pos: position}))
79
- end
35
+ validates_presence_of :id
36
+ validates_length_of :name, in: 1..16384
80
37
 
81
38
  # Return a list of items on the checklist.
82
39
  def items
@@ -91,17 +48,6 @@ module Trello
91
48
  # Return a reference to the card the checklist is on.
92
49
  one :card, path: :checklists, using: :card_id
93
50
 
94
- # Return a reference to the list the checklist is on.
95
- one :list, path: :lists, using: :list_id
96
-
97
- # Return a list of members active in this checklist.
98
- def members
99
- members = member_ids.map do |member_id|
100
- Member.find(member_id)
101
- end
102
- MultiAssociation.new(self, members).proxy
103
- end
104
-
105
51
  # Add an item to the checklist
106
52
  def add_item(name, checked = false, position = 'bottom')
107
53
  client.post("/checklists/#{id}/checkItems", {name: name, checked: checked, pos: position})
@@ -1,39 +1,50 @@
1
1
  module Trello
2
2
  # A Comment is a string with a creation date; it resides inside a Card and belongs to a User.
3
3
  #
4
- # @!attribute [r] action_id
4
+ # @!attribute [r] id
5
5
  # @return [String]
6
- # @!attribute [r] text
6
+ # @!attribute [w] text
7
7
  # @return [String]
8
8
  # @!attribute [r] date
9
9
  # @return [Datetime]
10
- # @!attribute [r] member_creator_id
10
+ # @!attribute [r] creator_id
11
11
  # @return [String]
12
+ # @!attribute [r] data
13
+ # @return [Hash]
14
+ # @!attribute [r] type
15
+ # @return [String]
16
+ # @!attribute [r] limits
17
+ # @return [Hash]
18
+ # @!attribute [r] app_creator
19
+ # @return [String]
20
+ # @!attribute [r] display
21
+ # @return [Hash]
12
22
  class Comment < BasicData
13
- register_attributes :action_id, :text, :date, :member_creator_id,
14
- readonly: [ :action_id, :text, :date, :member_creator_id ]
15
- validates_presence_of :action_id, :text, :date, :member_creator_id
23
+
24
+ schema do
25
+ # Readonly
26
+ attribute :id, readonly: true, primary_key: true
27
+ attribute :creator_id, readonly: true, remote_key: 'idMemberCreator'
28
+ attribute :data, readonly: true
29
+ attribute :type, readonly: true
30
+ attribute :date, readonly: true, serializer: 'Time'
31
+ attribute :limits, readonly: true
32
+ attribute :app_creator, readonly: true, remote_key: 'appCreator'
33
+ attribute :display, readonly: true
34
+
35
+ # Writable
36
+ attribute :text, update_only: true
37
+ end
38
+
39
+ validates_presence_of :action_id, :text, :date, :creator_id
16
40
  validates_length_of :text, in: 1..16384
17
41
 
18
42
  class << self
19
- # Locate a specific action and return a new Comment object.
20
43
  def find(action_id)
21
- client.find(:action, action_id, filter: commentCard)
44
+ client.find(:action, action_id)
22
45
  end
23
46
  end
24
47
 
25
- # Update the attributes of a Comment
26
- #
27
- # Supply a hash of string keyed data retrieved from the Trello API representing
28
- # a Comment.
29
- def update_fields(fields)
30
- attributes[:action_id] = fields['id'] || attributes[:action_id]
31
- attributes[:text] = fields['data']['text'] || attributes[:text]
32
- attributes[:date] = Time.iso8601(fields['date']) if fields.has_key?('date')
33
- attributes[:member_creator_id] = fields['idMemberCreator'] || attributes[:member_creator_id]
34
- self
35
- end
36
-
37
48
  # Returns the board this comment is located
38
49
  def board
39
50
  Board.from_response client.get("/actions/#{action_id}/board")
@@ -55,8 +66,7 @@ module Trello
55
66
  client.delete(ruta)
56
67
  end
57
68
 
58
-
59
69
  # Returns the member who created the comment.
60
- one :member_creator, via: Member, path: :members, using: :member_creator_id
70
+ one :member_creator, via: Member, path: :members, using: :creator_id
61
71
  end
62
72
  end