ruby-trello 2.3.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -2
  3. data/lib/trello.rb +13 -7
  4. data/lib/trello/action.rb +27 -21
  5. data/lib/trello/attachment.rb +40 -27
  6. data/lib/trello/basic_data.rb +104 -9
  7. data/lib/trello/board.rb +88 -102
  8. data/lib/trello/card.rb +34 -235
  9. data/lib/trello/checklist.rb +17 -71
  10. data/lib/trello/comment.rb +32 -22
  11. data/lib/trello/cover_image.rb +20 -0
  12. data/lib/trello/custom_field.rb +31 -84
  13. data/lib/trello/custom_field_item.rb +36 -58
  14. data/lib/trello/custom_field_option.rb +40 -13
  15. data/lib/trello/item.rb +27 -16
  16. data/lib/trello/item_state.rb +7 -15
  17. data/lib/trello/json_utils.rb +1 -1
  18. data/lib/trello/label.rb +14 -101
  19. data/lib/trello/label_name.rb +22 -25
  20. data/lib/trello/list.rb +31 -44
  21. data/lib/trello/member.rb +77 -32
  22. data/lib/trello/notification.rb +27 -20
  23. data/lib/trello/organization.rb +53 -25
  24. data/lib/trello/plugin_datum.rb +11 -16
  25. data/lib/trello/schema.rb +31 -0
  26. data/lib/trello/schema/attribute/base.rb +79 -0
  27. data/lib/trello/schema/attribute/board_pref.rb +45 -0
  28. data/lib/trello/schema/attribute/custom_field_display.rb +45 -0
  29. data/lib/trello/schema/attribute/default.rb +45 -0
  30. data/lib/trello/schema/attribute_builder.rb +42 -0
  31. data/lib/trello/schema/attribute_registration.rb +47 -0
  32. data/lib/trello/schema/serializer/default.rb +17 -0
  33. data/lib/trello/schema/serializer/labels.rb +23 -0
  34. data/lib/trello/schema/serializer/time.rb +25 -0
  35. data/lib/trello/schema/serializer/webhooks.rb +25 -0
  36. data/lib/trello/token.rb +15 -12
  37. data/lib/trello/webhook.rb +18 -71
  38. data/spec/action_spec.rb +1 -2
  39. data/spec/board_spec.rb +43 -103
  40. data/spec/card_spec.rb +51 -50
  41. data/spec/cassettes/action_find_with_id_and_get_all_fields.yml +104 -0
  42. data/spec/cassettes/board_find_with_id_and_get_all_fields.yml +96 -0
  43. data/spec/cassettes/board_find_with_id_and_get_specific_fields.yml +96 -0
  44. data/spec/cassettes/can_add_a_member_to_a_board.yml +191 -0
  45. data/spec/cassettes/can_arvhice_all_cards_of_list.yml +397 -0
  46. data/spec/cassettes/can_get_actions_of_board.yml +188 -0
  47. data/spec/cassettes/can_get_actions_of_list.yml +202 -0
  48. data/spec/cassettes/can_get_actions_of_members.yml +199 -0
  49. data/spec/cassettes/can_get_actions_of_organization.yml +201 -0
  50. data/spec/cassettes/can_get_boards_of_custom_field.yml +198 -0
  51. data/spec/cassettes/can_get_boards_of_label.yml +197 -0
  52. data/spec/cassettes/can_get_boards_of_organization.yml +207 -0
  53. data/spec/cassettes/can_get_cards_of_board.yml +193 -0
  54. data/spec/cassettes/can_get_cards_of_list.yml +201 -0
  55. data/spec/cassettes/can_get_cards_of_member.yml +204 -0
  56. data/spec/cassettes/can_get_checklists_of_board.yml +187 -0
  57. data/spec/cassettes/can_get_custom_field_options_of_custom_field.yml +197 -0
  58. data/spec/cassettes/can_get_custom_fields_of_board.yml +187 -0
  59. data/spec/cassettes/can_get_label_names_of_board.yml +187 -0
  60. data/spec/cassettes/can_get_labels_of_board.yml +187 -0
  61. data/spec/cassettes/can_get_lists_of_board.yml +187 -0
  62. data/spec/cassettes/can_get_members_of_board.yml +188 -0
  63. data/spec/cassettes/can_get_members_of_organization.yml +200 -0
  64. data/spec/cassettes/can_get_notifications_of_member.yml +199 -0
  65. data/spec/cassettes/can_get_organization_of_board.yml +189 -0
  66. data/spec/cassettes/can_get_organizations_of_member.yml +203 -0
  67. data/spec/cassettes/can_get_plugin_data_of_board.yml +187 -0
  68. data/spec/cassettes/can_move_all_cards_to_another_list.yml +886 -0
  69. data/spec/cassettes/can_success_create_a_board.yml +98 -0
  70. data/spec/cassettes/can_success_create_a_board_with_full_parameters.yml +97 -0
  71. data/spec/cassettes/can_success_create_a_board_without_clone_from_other.yml +98 -0
  72. data/spec/cassettes/can_success_create_a_card_when_due_is_datetime.yml +98 -0
  73. data/spec/cassettes/can_success_create_a_card_when_due_is_time.yml +98 -0
  74. data/spec/cassettes/can_success_create_a_checklist.yml +102 -0
  75. data/spec/cassettes/can_success_create_a_custom_field.yml +102 -0
  76. data/spec/cassettes/can_success_create_a_custom_field_option.yml +102 -0
  77. data/spec/cassettes/can_success_create_a_label.yml +102 -0
  78. data/spec/cassettes/can_success_create_a_list.yml +102 -0
  79. data/spec/cassettes/can_success_create_a_list_with_full_parameters.yml +102 -0
  80. data/spec/cassettes/can_success_create_a_organization.yml +104 -0
  81. data/spec/cassettes/can_success_create_a_webhook.yml +102 -0
  82. data/spec/cassettes/can_success_delete_a_custom_field_option.yml +389 -0
  83. data/spec/cassettes/can_success_delete_checklist.yml +284 -0
  84. data/spec/cassettes/can_success_get_card_of_board_by_card_id.yml +188 -0
  85. data/spec/cassettes/can_success_remove_member_from_board.yml +186 -0
  86. data/spec/cassettes/can_success_return_all_boards_of_current_user.yml +195 -0
  87. data/spec/cassettes/can_success_upate_a_board.yml +191 -0
  88. data/spec/cassettes/can_success_upate_a_list.yml +296 -0
  89. data/spec/cassettes/can_success_update_bong_a_board.yml +39 -39
  90. data/spec/cassettes/can_success_update_bong_a_board_with_specific_fields.yml +284 -0
  91. data/spec/cassettes/can_success_update_bong_a_checklist_with_specific_fields.yml +296 -0
  92. data/spec/cassettes/can_success_update_bong_a_custom_field.yml +200 -0
  93. data/spec/cassettes/can_success_update_bong_a_label.yml +200 -0
  94. data/spec/cassettes/can_success_update_bong_a_list.yml +199 -0
  95. data/spec/cassettes/can_success_update_bong_a_list_with_specific_fields.yml +296 -0
  96. data/spec/cassettes/can_success_update_bong_a_organization.yml +203 -0
  97. data/spec/cassettes/can_success_update_bong_a_webhook.yml +296 -0
  98. data/spec/cassettes/checklist_can_add_an_item.yml +296 -0
  99. data/spec/cassettes/checklist_can_update_the_item_state.yml +296 -0
  100. data/spec/cassettes/checklist_find_with_id_and_get_all_fields.yml +100 -0
  101. data/spec/cassettes/custom_field_find_with_id_and_get_all_fields.yml +100 -0
  102. data/spec/cassettes/custom_field_find_with_id_and_get_specific_fields.yml +100 -0
  103. data/spec/cassettes/custom_field_item_save_1.yml +1 -1
  104. data/spec/cassettes/custom_field_item_save_2.yml +1 -1
  105. data/spec/cassettes/custom_field_option_find_with_id.yml +100 -0
  106. data/spec/cassettes/get_board_of_list.yml +197 -0
  107. data/spec/cassettes/get_boards_of_member.yml +207 -0
  108. data/spec/cassettes/label_delete.yml +285 -0
  109. data/spec/cassettes/label_find_with_id.yml +100 -0
  110. data/spec/cassettes/list_find_with_id_and_get_all_fields.yml +100 -0
  111. data/spec/cassettes/list_find_with_id_and_get_specific_fields.yml +100 -0
  112. data/spec/cassettes/member_find_with_id_and_get_all_fields.yml +101 -0
  113. data/spec/cassettes/member_find_with_id_and_get_specific_fields.yml +100 -0
  114. data/spec/cassettes/notification_find_with_id.yml +103 -0
  115. data/spec/cassettes/organization_find_with_id_and_get_all_fields.yml +102 -0
  116. data/spec/cassettes/organization_find_with_id_and_get_specific_fields.yml +100 -0
  117. data/spec/cassettes/token_find_with_token_string.yml +100 -0
  118. data/spec/cassettes/webhook_delete.yml +286 -0
  119. data/spec/cassettes/webhook_find_with_id.yml +100 -0
  120. data/spec/checklist_spec.rb +27 -43
  121. data/spec/custom_field_item_spec.rb +2 -2
  122. data/spec/custom_field_option_spec.rb +2 -2
  123. data/spec/custom_field_spec.rb +25 -13
  124. data/spec/integration/action/find_spec.rb +23 -0
  125. data/spec/integration/basic_data/many_spec.rb +4 -0
  126. data/spec/integration/basic_data/schema_spec.rb +156 -0
  127. data/spec/integration/board/add_member_spec.rb +21 -0
  128. data/spec/integration/board/all_spec.rb +20 -0
  129. data/spec/integration/board/associations/actions_spec.rb +18 -0
  130. data/spec/integration/board/associations/cards_spec.rb +18 -0
  131. data/spec/integration/board/associations/checklists_spec.rb +18 -0
  132. data/spec/integration/board/associations/custom_fields_spec.rb +18 -0
  133. data/spec/integration/board/associations/label_names_spec.rb +17 -0
  134. data/spec/integration/board/associations/labels_spec.rb +18 -0
  135. data/spec/integration/board/associations/lists_spec.rb +18 -0
  136. data/spec/integration/board/associations/members_spec.rb +18 -0
  137. data/spec/integration/board/associations/organization_spec.rb +19 -0
  138. data/spec/integration/board/associations/plugin_data_spec.rb +18 -0
  139. data/spec/integration/board/create_spec.rb +95 -0
  140. data/spec/integration/board/find_card_spec.rb +18 -0
  141. data/spec/integration/board/find_spec.rb +42 -0
  142. data/spec/integration/board/remove_member_spec.rb +21 -0
  143. data/spec/integration/board/save_spec.rb +37 -0
  144. data/spec/integration/board/update!_spec.rb +33 -2
  145. data/spec/integration/card/associations/plugin_data_spec.rb +1 -1
  146. data/spec/integration/card/create_spec.rb +36 -2
  147. data/spec/integration/card/find_spec.rb +1 -1
  148. data/spec/integration/card/save_spec.rb +2 -2
  149. data/spec/integration/checklist/add_item_spec.rb +20 -0
  150. data/spec/integration/checklist/create_spec.rb +23 -0
  151. data/spec/integration/checklist/delete_spec.rb +17 -0
  152. data/spec/integration/checklist/find_spec.rb +22 -0
  153. data/spec/integration/checklist/update!_spec.rb +21 -0
  154. data/spec/integration/checklist/update_item_state_spec.rb +20 -0
  155. data/spec/integration/custom_field/association/board_spec.rb +18 -0
  156. data/spec/integration/custom_field/association/custom_field_options_spec.rb +18 -0
  157. data/spec/integration/custom_field/create_spec.rb +29 -0
  158. data/spec/integration/custom_field/find_spec.rb +41 -0
  159. data/spec/integration/custom_field/update!_spec.rb +25 -0
  160. data/spec/integration/custom_field_option/create_spec.rb +23 -0
  161. data/spec/integration/custom_field_option/delete_spec.rb +19 -0
  162. data/spec/integration/custom_field_option/find_spec.rb +21 -0
  163. data/spec/integration/label/association/board_spec.rb +18 -0
  164. data/spec/integration/label/create_spec.rb +23 -0
  165. data/spec/integration/label/delete_spec.rb +21 -0
  166. data/spec/integration/label/find_spec.rb +20 -0
  167. data/spec/integration/label/update!_spec.rb +25 -0
  168. data/spec/integration/list/archive_all_cards_spec.rb +20 -0
  169. data/spec/integration/list/associations/actions_spec.rb +18 -0
  170. data/spec/integration/list/associations/board_spec.rb +18 -0
  171. data/spec/integration/list/associations/cards_spec.rb +18 -0
  172. data/spec/integration/list/create_spec.rb +44 -0
  173. data/spec/integration/list/find_spec.rb +37 -0
  174. data/spec/integration/list/move_all_cards_spec.rb +31 -0
  175. data/spec/integration/list/save_spec.rb +40 -0
  176. data/spec/integration/list/update!_spec.rb +43 -0
  177. data/spec/integration/member/associations/actions_spec.rb +17 -0
  178. data/spec/integration/member/associations/boards_spec.rb +18 -0
  179. data/spec/integration/member/associations/cards_spec.rb +18 -0
  180. data/spec/integration/member/associations/notifications_spec.rb +18 -0
  181. data/spec/integration/member/associations/organizations_spec.rb +18 -0
  182. data/spec/integration/member/find_spec.rb +39 -0
  183. data/spec/integration/member/update!_spec.rb +18 -0
  184. data/spec/integration/notification/find_spec.rb +27 -0
  185. data/spec/integration/organization/associations/actions_spec.rb +18 -0
  186. data/spec/integration/organization/associations/boards_spec.rb +18 -0
  187. data/spec/integration/organization/associations/members_spec.rb +18 -0
  188. data/spec/integration/organization/create_spec.rb +23 -0
  189. data/spec/integration/organization/find_spec.rb +37 -0
  190. data/spec/integration/organization/update!_spec.rb +28 -0
  191. data/spec/integration/token/find_spec.rb +24 -0
  192. data/spec/integration/webhook/create_spec.rb +27 -0
  193. data/spec/integration/webhook/delete_spec.rb +21 -0
  194. data/spec/integration/webhook/find_spec.rb +22 -0
  195. data/spec/integration/webhook/update!_spec.rb +24 -0
  196. data/spec/item_spec.rb +2 -2
  197. data/spec/label_spec.rb +31 -33
  198. data/spec/list_spec.rb +32 -14
  199. data/spec/notification_spec.rb +3 -3
  200. data/spec/organization_spec.rb +6 -5
  201. data/spec/spec_helper.rb +22 -14
  202. data/spec/token_spec.rb +10 -11
  203. data/spec/unit/trello/basic_data_spec.rb +67 -8
  204. data/spec/unit/trello/board/new_spec.rb +370 -0
  205. data/spec/unit/trello/board/save_spec.rb +49 -0
  206. data/spec/unit/trello/board/update_fields_spec.rb +129 -0
  207. data/spec/unit/trello/board/update_spec.rb +197 -0
  208. data/spec/unit/trello/member/new_spec.rb +62 -0
  209. data/spec/unit/trello/member/update_fields_spec.rb +80 -0
  210. data/spec/unit/trello/schema/attribute/base_spec.rb +349 -0
  211. data/spec/unit/trello/schema/attribute/board_pref_spec.rb +208 -0
  212. data/spec/unit/trello/schema/attribute/default_spec.rb +236 -0
  213. data/spec/unit/trello/schema/attribute_builder_spec.rb +55 -0
  214. data/spec/unit/trello/schema/attribute_registration_spec.rb +59 -0
  215. data/spec/unit/trello/schema/serializer/default_spec.rb +19 -0
  216. data/spec/unit/trello/schema/serializer/time_spec.rb +39 -0
  217. data/spec/unit/trello/schema_spec.rb +25 -0
  218. data/spec/webhook_spec.rb +23 -7
  219. metadata +422 -102
  220. data/lib/trello/register_attributes.rb +0 -54
  221. data/spec/integration/basic_data/register_attributes_spec.rb +0 -75
@@ -43,147 +43,46 @@ 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
- %i[
173
- name desc due due_complete closed
174
- board_id member_ids list_id pos
175
- card_labels cover_image_id
176
- ].each do |key|
177
- send("#{key}_will_change!") if fields_has_key?(fields, key)
178
- end
179
-
180
- initialize_fields(fields)
181
- end
182
-
183
- def initialize(fields = {})
184
- initialize_fields(fields)
185
- end
186
-
187
86
  # Returns a reference to the board this card is part of.
188
87
  one :board, path: :boards, using: :board_id
189
88
 
@@ -232,75 +131,6 @@ module Trello
232
131
  Member.from_response client.get("/cards/#{id}/membersVoted")
233
132
  end
234
133
 
235
- # Saves a record.
236
- #
237
- # @raise [Trello::Error] if the card could not be saved
238
- #
239
- # @return [String] The JSON representation of the saved card returned by
240
- # the Trello API.
241
- def save
242
- # If we have an id, just update our fields.
243
- return update! if id
244
-
245
- from_response client.post("/cards", {
246
- name: name,
247
- desc: desc,
248
- idList: list_id,
249
- idMembers: member_ids,
250
- idLabels: card_labels,
251
- pos: pos,
252
- due: due,
253
- dueComplete: due_complete,
254
- idCardSource: source_card_id,
255
- keepFromSource: source_card_properties
256
- })
257
- end
258
-
259
- # Update an existing record.
260
- #
261
- # Warning: this updates all fields using values already in memory. If
262
- # an external resource has updated these fields, you should refresh!
263
- # this object before making your changes, and before updating the record.
264
- #
265
- # @raise [Trello::Error] if the card could not be updated.
266
- #
267
- # @return [Trello::Card] updated self
268
- def update!
269
- @previously_changed = changes
270
- # extract only new values to build payload
271
- payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
272
-
273
- response = client.put("/cards/#{id}", payload)
274
- updated_card = from_response(response)
275
-
276
- @changed_attributes.clear if @changed_attributes.respond_to?(:clear)
277
- changes_applied if respond_to?(:changes_applied)
278
-
279
- attributes[:id] = updated_card.id
280
- attributes[:short_id] = updated_card.short_id
281
- attributes[:name] = updated_card.name
282
- attributes[:desc] = updated_card.desc
283
- attributes[:due] = updated_card.due
284
- attributes[:due_complete] = updated_card.due_complete
285
- attributes[:closed] = updated_card.closed
286
- attributes[:url] = updated_card.url
287
- attributes[:short_url] = updated_card.short_url
288
- attributes[:board_id] = updated_card.board_id
289
- attributes[:member_ids] = updated_card.member_ids
290
- attributes[:list_id] = updated_card.list_id
291
- attributes[:pos] = updated_card.pos
292
- attributes[:labels] = updated_card.labels
293
- attributes[:card_labels] = updated_card.card_labels
294
- attributes[:last_activity_date] = updated_card.last_activity_date
295
- attributes[:cover_image_id] = updated_card.cover_image_id
296
- attributes[:badges] = updated_card.badges
297
- attributes[:card_members] = updated_card.card_members
298
- attributes[:source_card_id] = updated_card.source_card_id
299
- attributes[:source_card_properties] = updated_card.source_card_properties
300
-
301
- self
302
- end
303
-
304
134
  # Delete this card
305
135
  #
306
136
  # @return [String] the JSON response from the Trello API
@@ -486,36 +316,5 @@ module Trello
486
316
  @me ||= Member.find(:me)
487
317
  end
488
318
 
489
- def fields_has_key?(fields, key)
490
- fields.key?(SYMBOL_TO_STRING[key]) || fields.key?(key)
491
- end
492
-
493
- def initialize_fields(fields)
494
- attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || attributes[:id]
495
- attributes[:short_id] = fields[SYMBOL_TO_STRING[:short_id]] || attributes[:short_id]
496
- attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name]
497
- attributes[:desc] = fields[SYMBOL_TO_STRING[:desc]] || fields[:desc] || attributes[:desc]
498
- attributes[:due] = Time.iso8601(fields[SYMBOL_TO_STRING[:due]]) rescue nil if fields.has_key?(SYMBOL_TO_STRING[:due])
499
- attributes[:due] = fields[:due] if fields.has_key?(:due)
500
- attributes[:due_complete] = fields[SYMBOL_TO_STRING[:due_complete]] if fields.has_key?(SYMBOL_TO_STRING[:due_complete])
501
- attributes[:due_complete] ||= false
502
- attributes[:closed] = fields[SYMBOL_TO_STRING[:closed]] if fields.has_key?(SYMBOL_TO_STRING[:closed])
503
- attributes[:url] = fields[SYMBOL_TO_STRING[:url]] || attributes[:url]
504
- attributes[:short_url] = fields[SYMBOL_TO_STRING[:short_url]] || attributes[:short_url]
505
- attributes[:board_id] = fields[SYMBOL_TO_STRING[:board_id]] || attributes[:board_id]
506
- attributes[:member_ids] = fields[SYMBOL_TO_STRING[:member_ids]] || fields[:member_ids] || attributes[:member_ids]
507
- attributes[:list_id] = fields[SYMBOL_TO_STRING[:list_id]] || fields[:list_id] || attributes[:list_id]
508
- attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos]
509
- attributes[:labels] = (fields[SYMBOL_TO_STRING[:labels]] || []).map { |lbl| Trello::Label.new(lbl) }.presence || attributes[:labels].presence || []
510
- attributes[:card_labels] = fields[SYMBOL_TO_STRING[:card_labels]] || fields[:card_labels] || attributes[:card_labels]
511
- 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])
512
- attributes[:cover_image_id] = fields[SYMBOL_TO_STRING[:cover_image_id]] || attributes[:cover_image_id]
513
- attributes[:badges] = fields[SYMBOL_TO_STRING[:badges]] || attributes[:badges]
514
- attributes[:card_members] = fields[SYMBOL_TO_STRING[:card_members]] || attributes[:card_members]
515
- attributes[:source_card_id] = fields[SYMBOL_TO_STRING[:source_card_id]] || fields[:source_card_id] || attributes[:source_card_id]
516
- attributes[:source_card_properties] = fields[SYMBOL_TO_STRING[:source_card_properties]] || fields[:source_card_properties] || attributes[:source_card_properties]
517
- self
518
- end
519
-
520
319
  end
521
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