ruby-trello 2.3.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +49 -23
  3. data/lib/trello/action.rb +27 -21
  4. data/lib/trello/attachment.rb +40 -27
  5. data/lib/trello/basic_data.rb +104 -9
  6. data/lib/trello/board.rb +88 -102
  7. data/lib/trello/card.rb +34 -235
  8. data/lib/trello/checklist.rb +17 -71
  9. data/lib/trello/client.rb +1 -1
  10. data/lib/trello/comment.rb +39 -26
  11. data/lib/trello/configuration.rb +8 -0
  12. data/lib/trello/cover_image.rb +20 -0
  13. data/lib/trello/custom_field.rb +31 -84
  14. data/lib/trello/custom_field_item.rb +36 -58
  15. data/lib/trello/custom_field_option.rb +40 -13
  16. data/lib/trello/item.rb +27 -16
  17. data/lib/trello/item_state.rb +7 -15
  18. data/lib/trello/json_utils.rb +11 -5
  19. data/lib/trello/label.rb +14 -101
  20. data/lib/trello/label_name.rb +22 -25
  21. data/lib/trello/list.rb +31 -44
  22. data/lib/trello/member.rb +77 -32
  23. data/lib/trello/net/faraday.rb +46 -0
  24. data/lib/trello/net/rest_client.rb +41 -0
  25. data/lib/trello/net.rb +1 -28
  26. data/lib/trello/notification.rb +27 -20
  27. data/lib/trello/organization.rb +53 -25
  28. data/lib/trello/plugin_datum.rb +11 -16
  29. data/lib/trello/schema/attribute/base.rb +79 -0
  30. data/lib/trello/schema/attribute/board_pref.rb +45 -0
  31. data/lib/trello/schema/attribute/custom_field_display.rb +45 -0
  32. data/lib/trello/schema/attribute/default.rb +45 -0
  33. data/lib/trello/schema/attribute_builder.rb +42 -0
  34. data/lib/trello/schema/attribute_registration.rb +47 -0
  35. data/lib/trello/schema/serializer/default.rb +17 -0
  36. data/lib/trello/schema/serializer/labels.rb +23 -0
  37. data/lib/trello/schema/serializer/time.rb +25 -0
  38. data/lib/trello/schema/serializer/webhooks.rb +25 -0
  39. data/lib/trello/schema.rb +31 -0
  40. data/lib/trello/token.rb +15 -12
  41. data/lib/trello/webhook.rb +18 -71
  42. data/lib/trello.rb +62 -7
  43. data/spec/action_spec.rb +1 -2
  44. data/spec/board_spec.rb +43 -103
  45. data/spec/card_spec.rb +51 -50
  46. data/spec/cassettes/action_find_with_id_and_get_all_fields.yml +104 -0
  47. data/spec/cassettes/board_find_with_id_and_get_all_fields.yml +96 -0
  48. data/spec/cassettes/board_find_with_id_and_get_specific_fields.yml +96 -0
  49. data/spec/cassettes/can_add_a_member_to_a_board.yml +191 -0
  50. data/spec/cassettes/can_arvhice_all_cards_of_list.yml +397 -0
  51. data/spec/cassettes/can_get_actions_of_board.yml +188 -0
  52. data/spec/cassettes/can_get_actions_of_list.yml +202 -0
  53. data/spec/cassettes/can_get_actions_of_members.yml +199 -0
  54. data/spec/cassettes/can_get_actions_of_organization.yml +201 -0
  55. data/spec/cassettes/can_get_boards_of_custom_field.yml +198 -0
  56. data/spec/cassettes/can_get_boards_of_label.yml +197 -0
  57. data/spec/cassettes/can_get_boards_of_organization.yml +207 -0
  58. data/spec/cassettes/can_get_cards_of_board.yml +193 -0
  59. data/spec/cassettes/can_get_cards_of_list.yml +201 -0
  60. data/spec/cassettes/can_get_cards_of_member.yml +204 -0
  61. data/spec/cassettes/can_get_checklists_of_board.yml +187 -0
  62. data/spec/cassettes/can_get_comments_board.yml +109 -0
  63. data/spec/cassettes/can_get_comments_card.yml +111 -0
  64. data/spec/cassettes/can_get_comments_list.yml +109 -0
  65. data/spec/cassettes/can_get_custom_field_options_of_custom_field.yml +197 -0
  66. data/spec/cassettes/can_get_custom_fields_of_board.yml +187 -0
  67. data/spec/cassettes/can_get_label_names_of_board.yml +187 -0
  68. data/spec/cassettes/can_get_labels_of_board.yml +187 -0
  69. data/spec/cassettes/can_get_lists_of_board.yml +187 -0
  70. data/spec/cassettes/can_get_members_of_board.yml +188 -0
  71. data/spec/cassettes/can_get_members_of_organization.yml +200 -0
  72. data/spec/cassettes/can_get_notifications_of_member.yml +199 -0
  73. data/spec/cassettes/can_get_organization_of_board.yml +189 -0
  74. data/spec/cassettes/can_get_organizations_of_member.yml +203 -0
  75. data/spec/cassettes/can_get_plugin_data_of_board.yml +187 -0
  76. data/spec/cassettes/can_move_all_cards_to_another_list.yml +886 -0
  77. data/spec/cassettes/can_success_create_a_board.yml +98 -0
  78. data/spec/cassettes/can_success_create_a_board_with_full_parameters.yml +97 -0
  79. data/spec/cassettes/can_success_create_a_board_without_clone_from_other.yml +98 -0
  80. data/spec/cassettes/can_success_create_a_card_when_due_is_datetime.yml +98 -0
  81. data/spec/cassettes/can_success_create_a_card_when_due_is_time.yml +98 -0
  82. data/spec/cassettes/can_success_create_a_checklist.yml +102 -0
  83. data/spec/cassettes/can_success_create_a_custom_field.yml +102 -0
  84. data/spec/cassettes/can_success_create_a_custom_field_option.yml +102 -0
  85. data/spec/cassettes/can_success_create_a_label.yml +102 -0
  86. data/spec/cassettes/can_success_create_a_list.yml +102 -0
  87. data/spec/cassettes/can_success_create_a_list_with_full_parameters.yml +102 -0
  88. data/spec/cassettes/can_success_create_a_organization.yml +104 -0
  89. data/spec/cassettes/can_success_create_a_webhook.yml +102 -0
  90. data/spec/cassettes/can_success_delete_a_custom_field_option.yml +389 -0
  91. data/spec/cassettes/can_success_delete_checklist.yml +284 -0
  92. data/spec/cassettes/can_success_get_card_of_board_by_card_id.yml +188 -0
  93. data/spec/cassettes/can_success_remove_member_from_board.yml +186 -0
  94. data/spec/cassettes/can_success_return_all_boards_of_current_user.yml +195 -0
  95. data/spec/cassettes/can_success_upate_a_board.yml +191 -0
  96. data/spec/cassettes/can_success_upate_a_list.yml +296 -0
  97. data/spec/cassettes/can_success_update_bong_a_board.yml +39 -39
  98. data/spec/cassettes/can_success_update_bong_a_board_with_specific_fields.yml +284 -0
  99. data/spec/cassettes/can_success_update_bong_a_checklist_with_specific_fields.yml +296 -0
  100. data/spec/cassettes/can_success_update_bong_a_custom_field.yml +200 -0
  101. data/spec/cassettes/can_success_update_bong_a_label.yml +200 -0
  102. data/spec/cassettes/can_success_update_bong_a_list.yml +199 -0
  103. data/spec/cassettes/can_success_update_bong_a_list_with_specific_fields.yml +296 -0
  104. data/spec/cassettes/can_success_update_bong_a_organization.yml +203 -0
  105. data/spec/cassettes/can_success_update_bong_a_webhook.yml +296 -0
  106. data/spec/cassettes/checklist_can_add_an_item.yml +296 -0
  107. data/spec/cassettes/checklist_can_update_the_item_state.yml +296 -0
  108. data/spec/cassettes/checklist_find_with_id_and_get_all_fields.yml +100 -0
  109. data/spec/cassettes/comment_delete.yml +331 -0
  110. data/spec/cassettes/comment_find_with_id.yml +116 -0
  111. data/spec/cassettes/custom_field_find_with_id_and_get_all_fields.yml +100 -0
  112. data/spec/cassettes/custom_field_find_with_id_and_get_specific_fields.yml +100 -0
  113. data/spec/cassettes/custom_field_item_save_1.yml +1 -1
  114. data/spec/cassettes/custom_field_item_save_2.yml +1 -1
  115. data/spec/cassettes/custom_field_option_find_with_id.yml +100 -0
  116. data/spec/cassettes/get_board_of_list.yml +197 -0
  117. data/spec/cassettes/get_boards_of_member.yml +207 -0
  118. data/spec/cassettes/label_delete.yml +285 -0
  119. data/spec/cassettes/label_find_with_id.yml +100 -0
  120. data/spec/cassettes/list_find_with_id_and_get_all_fields.yml +100 -0
  121. data/spec/cassettes/list_find_with_id_and_get_specific_fields.yml +100 -0
  122. data/spec/cassettes/member_find_with_id_and_get_all_fields.yml +101 -0
  123. data/spec/cassettes/member_find_with_id_and_get_specific_fields.yml +100 -0
  124. data/spec/cassettes/notification_find_with_id.yml +103 -0
  125. data/spec/cassettes/organization_find_with_id_and_get_all_fields.yml +102 -0
  126. data/spec/cassettes/organization_find_with_id_and_get_specific_fields.yml +100 -0
  127. data/spec/cassettes/token_find_with_token_string.yml +100 -0
  128. data/spec/cassettes/webhook_delete.yml +286 -0
  129. data/spec/cassettes/webhook_find_with_id.yml +100 -0
  130. data/spec/checklist_spec.rb +27 -43
  131. data/spec/client_spec.rb +57 -3
  132. data/spec/configuration_spec.rb +13 -0
  133. data/spec/custom_field_item_spec.rb +2 -2
  134. data/spec/custom_field_option_spec.rb +2 -2
  135. data/spec/custom_field_spec.rb +25 -13
  136. data/spec/integration/action/find_spec.rb +23 -0
  137. data/spec/integration/basic_data/many_spec.rb +4 -0
  138. data/spec/integration/basic_data/schema_spec.rb +156 -0
  139. data/spec/integration/board/add_member_spec.rb +20 -0
  140. data/spec/integration/board/all_spec.rb +20 -0
  141. data/spec/integration/board/associations/actions_spec.rb +18 -0
  142. data/spec/integration/board/associations/cards_spec.rb +18 -0
  143. data/spec/integration/board/associations/checklists_spec.rb +18 -0
  144. data/spec/integration/board/associations/custom_fields_spec.rb +18 -0
  145. data/spec/integration/board/associations/label_names_spec.rb +17 -0
  146. data/spec/integration/board/associations/labels_spec.rb +18 -0
  147. data/spec/integration/board/associations/lists_spec.rb +18 -0
  148. data/spec/integration/board/associations/members_spec.rb +18 -0
  149. data/spec/integration/board/associations/organization_spec.rb +19 -0
  150. data/spec/integration/board/associations/plugin_data_spec.rb +18 -0
  151. data/spec/integration/board/create_spec.rb +95 -0
  152. data/spec/integration/board/find_card_spec.rb +18 -0
  153. data/spec/integration/board/find_spec.rb +42 -0
  154. data/spec/integration/board/remove_member_spec.rb +21 -0
  155. data/spec/integration/board/save_spec.rb +37 -0
  156. data/spec/integration/board/update!_spec.rb +33 -2
  157. data/spec/integration/card/associations/plugin_data_spec.rb +1 -1
  158. data/spec/integration/card/create_spec.rb +36 -2
  159. data/spec/integration/card/delete_spec.rb +2 -2
  160. data/spec/integration/card/find_spec.rb +1 -1
  161. data/spec/integration/card/save_spec.rb +2 -2
  162. data/spec/integration/checklist/add_item_spec.rb +20 -0
  163. data/spec/integration/checklist/create_spec.rb +23 -0
  164. data/spec/integration/checklist/delete_spec.rb +17 -0
  165. data/spec/integration/checklist/find_spec.rb +22 -0
  166. data/spec/integration/checklist/update!_spec.rb +21 -0
  167. data/spec/integration/checklist/update_item_state_spec.rb +20 -0
  168. data/spec/integration/comment/association/board_spec.rb +17 -0
  169. data/spec/integration/comment/association/card_spec.rb +17 -0
  170. data/spec/integration/comment/association/list_spec.rb +17 -0
  171. data/spec/integration/comment/delete_spec.rb +20 -0
  172. data/spec/integration/comment/find_spec.rb +17 -0
  173. data/spec/integration/custom_field/association/board_spec.rb +18 -0
  174. data/spec/integration/custom_field/association/custom_field_options_spec.rb +18 -0
  175. data/spec/integration/custom_field/create_spec.rb +29 -0
  176. data/spec/integration/custom_field/find_spec.rb +41 -0
  177. data/spec/integration/custom_field/update!_spec.rb +25 -0
  178. data/spec/integration/custom_field_option/create_spec.rb +23 -0
  179. data/spec/integration/custom_field_option/delete_spec.rb +19 -0
  180. data/spec/integration/custom_field_option/find_spec.rb +21 -0
  181. data/spec/integration/integration_test.rb +3 -3
  182. data/spec/integration/label/association/board_spec.rb +18 -0
  183. data/spec/integration/label/create_spec.rb +23 -0
  184. data/spec/integration/label/delete_spec.rb +21 -0
  185. data/spec/integration/label/find_spec.rb +20 -0
  186. data/spec/integration/label/update!_spec.rb +25 -0
  187. data/spec/integration/list/archive_all_cards_spec.rb +20 -0
  188. data/spec/integration/list/associations/actions_spec.rb +18 -0
  189. data/spec/integration/list/associations/board_spec.rb +18 -0
  190. data/spec/integration/list/associations/cards_spec.rb +18 -0
  191. data/spec/integration/list/create_spec.rb +44 -0
  192. data/spec/integration/list/find_spec.rb +37 -0
  193. data/spec/integration/list/move_all_cards_spec.rb +31 -0
  194. data/spec/integration/list/save_spec.rb +40 -0
  195. data/spec/integration/list/update!_spec.rb +43 -0
  196. data/spec/integration/member/associations/actions_spec.rb +17 -0
  197. data/spec/integration/member/associations/boards_spec.rb +18 -0
  198. data/spec/integration/member/associations/cards_spec.rb +18 -0
  199. data/spec/integration/member/associations/notifications_spec.rb +18 -0
  200. data/spec/integration/member/associations/organizations_spec.rb +18 -0
  201. data/spec/integration/member/find_spec.rb +39 -0
  202. data/spec/integration/member/update!_spec.rb +18 -0
  203. data/spec/integration/notification/find_spec.rb +27 -0
  204. data/spec/integration/organization/associations/actions_spec.rb +18 -0
  205. data/spec/integration/organization/associations/boards_spec.rb +18 -0
  206. data/spec/integration/organization/associations/members_spec.rb +18 -0
  207. data/spec/integration/organization/create_spec.rb +23 -0
  208. data/spec/integration/organization/find_spec.rb +37 -0
  209. data/spec/integration/organization/update!_spec.rb +28 -0
  210. data/spec/integration/token/find_spec.rb +24 -0
  211. data/spec/integration/webhook/create_spec.rb +27 -0
  212. data/spec/integration/webhook/delete_spec.rb +21 -0
  213. data/spec/integration/webhook/find_spec.rb +22 -0
  214. data/spec/integration/webhook/update!_spec.rb +24 -0
  215. data/spec/item_spec.rb +2 -2
  216. data/spec/label_spec.rb +31 -33
  217. data/spec/list_spec.rb +32 -14
  218. data/spec/notification_spec.rb +3 -3
  219. data/spec/organization_spec.rb +6 -5
  220. data/spec/spec_helper.rb +31 -14
  221. data/spec/token_spec.rb +10 -11
  222. data/spec/unit/trello/basic_data_spec.rb +67 -8
  223. data/spec/unit/trello/board/new_spec.rb +370 -0
  224. data/spec/unit/trello/board/save_spec.rb +49 -0
  225. data/spec/unit/trello/board/update_fields_spec.rb +129 -0
  226. data/spec/unit/trello/board/update_spec.rb +197 -0
  227. data/spec/unit/trello/member/new_spec.rb +62 -0
  228. data/spec/unit/trello/member/update_fields_spec.rb +80 -0
  229. data/spec/unit/trello/schema/attribute/base_spec.rb +349 -0
  230. data/spec/unit/trello/schema/attribute/board_pref_spec.rb +208 -0
  231. data/spec/unit/trello/schema/attribute/default_spec.rb +236 -0
  232. data/spec/unit/trello/schema/attribute_builder_spec.rb +55 -0
  233. data/spec/unit/trello/schema/attribute_registration_spec.rb +59 -0
  234. data/spec/unit/trello/schema/serializer/default_spec.rb +19 -0
  235. data/spec/unit/trello/schema/serializer/time_spec.rb +39 -0
  236. data/spec/unit/trello/schema_spec.rb +25 -0
  237. data/spec/webhook_spec.rb +23 -7
  238. metadata +444 -102
  239. data/lib/trello/register_attributes.rb +0 -54
  240. data/spec/integration/basic_data/register_attributes_spec.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e7396e189c2f3b43af4bf1eacbdd78ec358ef684d2526d7c3537c1af1ca4abd
4
- data.tar.gz: c8e2c74d10eaedb521829b3598e4500119c8fbfdd8c8cd71758254580eee1079
3
+ metadata.gz: 46d6d62edf1eb8973cfea687f157402b32ab4741b4f5cf3c638dd3b2704d5ad8
4
+ data.tar.gz: a31459e8d18d04b759be5ec6385b9fa75e55250fb691b37c484a639a799f8ee6
5
5
  SHA512:
6
- metadata.gz: 1d441be6f124b3dd47ff332da22ccbf71eb201ff90ddf82775fc3f208eb6621dd10acc2cff21c81d30231d9b50f4aa9cf867cf66d26e9c894e16f1a1596a11fa
7
- data.tar.gz: 647e16d5104ba1cf8dc3a7811117f168d6e132503e4b0989e8316a8abd9b30f3401cc04814da202cb4fc74846c5b9dee88a80fc36358fa0cd9c5f65340aba97b
6
+ metadata.gz: ca3cffbb4c3e0b3ce88ec21dade8b5a21bf0b2bedb2cdb259523fac0986632d521eb04f3c607273192cd4ce617b73005152507dedfa42c370b51cf75e4d1ec45
7
+ data.tar.gz: 7b13d2e420d26fde4cdd62e09f7f199dd170102272f17c630554c2156aaee2ddc2f2f76a62a67707df23d252ce2723edd5de1b6697b64ca7ef2b9f30c6f56c15
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Ruby Trello API
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/jeremytregunna/ruby-trello.svg)](http://travis-ci.org/jeremytregunna/ruby-trello)
4
- [![security](https://hakiri.io/github/jeremytregunna/ruby-trello/master.svg)](https://hakiri.io/github/jeremytregunna/ruby-trello/master)
3
+ [![Ruby](https://github.com/jeremytregunna/ruby-trello/actions/workflows/main.yml/badge.svg)](https://github.com/jeremytregunna/ruby-trello/actions/workflows/main.yml)
5
4
  [![Code Climate](https://codeclimate.com/github/jeremytregunna/ruby-trello/badges/gpa.svg)](https://codeclimate.com/github/jeremytregunna/ruby-trello)
6
5
 
7
6
  This library implements the [Trello](http://www.trello.com/) [API](https://developers.trello.com/).
@@ -16,9 +15,21 @@ to, please just [create an issue](https://github.com/jeremytregunna/ruby-trello/
16
15
 
17
16
  ## Requirements
18
17
 
18
+ | Ruby \ ActiveModel | 4.2 | 5.2 | 6.0 | 6.1 | 7.0 |
19
+ | ---- | ---- | ---- | ---- | ---- | ---- |
20
+ | 2.5 | ✅ | ✅ | ✅ | ✅ | ❌ |
21
+ | 2.6 | ✅ | ✅ | ✅ | ✅ | ❌ |
22
+ | 2.7 | ❌ | ✅ | ✅ | ✅ | ✅ |
23
+ | 3.0 | ❌ | ❌ | ✅ | ✅ | ✅ |
24
+ | 3.1 | ❌ | ❌ | ✅ | ✅ | ✅ |
25
+ | jRuby 9.3 | ✅ | ✅ | ✅ | ✅ | ❌ |
26
+
19
27
  Use the newest version for Ruby 2.5.0 or newer support.
28
+
20
29
  Use version 2.2.1 or earlier for Ruby 2.1 ~ 2.4 support.
30
+
21
31
  Use version 1.3.0 or earlier for Ruby 1.9.3 support.
32
+
22
33
  Use version 1.4.x or earlier for Ruby 2.0.0 support.
23
34
 
24
35
  ## Installation
@@ -76,7 +87,19 @@ end
76
87
 
77
88
  All the calls this library makes to Trello require authentication using these keys. Be sure to protect them.
78
89
 
79
- #### Usage
90
+ #### HTTP Client
91
+
92
+ By default, ruby-trello uses [rest-client](https://rubygems.org/gems/rest-client) for network calls. You can configure ruby-trello to use either rest-client or [faraday](https://rubygems.org/gems/faraday), depending on your project's needs. In the next major version, ruby-trello will not require either gem in the gemspec and will default to faraday if both are present.
93
+
94
+ ```ruby
95
+ Trello.configure do |config|
96
+ config.http_client = 'rest-client'
97
+ # OR
98
+ config.http_client = 'faraday'
99
+ end
100
+ ```
101
+
102
+ ## Usage
80
103
 
81
104
  So let's say you want to get information about the user *bobtester*. We can do something like this:
82
105
 
@@ -92,7 +115,7 @@ puts bob.bio # A wonderfully delightful test user
92
115
  # How about a list of his boards?
93
116
  bob.boards
94
117
 
95
- # And then to read the lists of the first board do :
118
+ # And then to read the lists of the first board do :
96
119
  bob.boards.first.lists
97
120
  ```
98
121
 
@@ -119,10 +142,10 @@ pp Trello::Card.find( card_id ).checklists
119
142
 
120
143
  ##### Changing a checkbox state
121
144
  ```ruby
122
- # First get your checklist id
145
+ # First get your checklist id
123
146
  checklist = Trello::Checklist.find( checklist_id )
124
147
 
125
- # At this point, there is no more ids. To get your checklist item,
148
+ # At this point, there is no more ids. To get your checklist item,
126
149
  # you have to know it's position (same as in the trello interface).
127
150
  # Let's take the first
128
151
  checklist_item = checklist.items.first
@@ -185,38 +208,41 @@ Please see the `CONTRIBUTING.md` file for more information.
185
208
 
186
209
  ## Local Development
187
210
 
188
- Init all Gemfile.lock.* files
211
+ Use [matrixeval-ruby](https://github.com/MatrixEval/matrixeval-ruby) to test code againsts different ruby and active_model versions on local.
212
+
213
+ Check available commands with:
189
214
 
190
215
  ```bash
191
- make init
216
+ matrixeval --help
217
+ # Or
218
+ meval --help
192
219
  ```
193
220
 
194
- Bundle install for all Ruby versions
221
+ ### Some examples:
222
+
223
+ Generate MatrixEval config file
195
224
 
196
225
  ```bash
197
- make bundle:all
226
+ matrixeval init
198
227
  ```
199
228
 
200
- Run tests for all Ruby versions
229
+ Run bundle install
201
230
 
202
231
  ```bash
203
- make test:all
232
+ matrixeval --all bundle install
204
233
  ```
205
234
 
206
- Run tests for each Ruby versions individual
235
+ Run tests
207
236
 
208
237
  ```bash
209
- make test:ruby_2_5
210
- make test:ruby_2_6
211
- make test:ruby_2_7
212
- make test:jruby_9_2
238
+ matrixeval --all rspec
239
+ matrixeval --ruby 3.0 rspec spec/a_spec.rb
240
+ matrixeval --ruby 3.0 --active_model 7.0 rspec
213
241
  ```
214
242
 
215
- Do development for each Ruby versions individual
243
+ Bash
216
244
 
217
245
  ```bash
218
- make dev:ruby_2_5
219
- make dev:ruby_2_6
220
- make dev:ruby_2_7
221
- make dev:jruby_9_2
222
- ```
246
+ matrixeval bash
247
+ matrixeval --ruby 3.0 --active_model 7.0 bash
248
+ ```
data/lib/trello/action.rb CHANGED
@@ -3,20 +3,40 @@ module Trello
3
3
  #
4
4
  # @!attribute [r] id
5
5
  # @return [String]
6
- # @!attribute [r] type
6
+ # @!attribute [r] creator_id
7
7
  # @return [String]
8
8
  # @!attribute [r] data
9
9
  # @return [Hash]
10
+ # @!attribute [r] type
11
+ # @return [String]
10
12
  # @!attribute [r] date
11
13
  # @return [Datetime]
12
- # @!attribute [r] member_creator_id
14
+ # @!attribute [r] limits
15
+ # @return [Hash]
16
+ # @!attribute [r] app_creator
17
+ # @return [String]
18
+ # @!attribute [r] display
19
+ # @return [Hash]
20
+ # @!attribute [w] text
13
21
  # @return [String]
14
- # @!attribute [r] member_participant
15
- # @return [Object]
16
22
  class Action < BasicData
17
- register_attributes :id, :type, :data, :date, :member_creator_id, :member_participant,
18
- readonly: [ :id, :type, :data, :date, :member_creator_id, :member_participant ]
19
- validates_presence_of :id, :type, :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 :id, :type, :date, :creator_id
20
40
 
21
41
  class << self
22
42
  # Locate a specific action and return a new Action object.
@@ -33,20 +53,6 @@ module Trello
33
53
  end
34
54
  end
35
55
 
36
- # Update the attributes of an action
37
- #
38
- # Supply a hash of string keyed data retrieved from the Trello API representing
39
- # an Action.
40
- def update_fields(fields)
41
- attributes[:id] = fields['id'] || attributes[:id]
42
- attributes[:type] = fields['type'] || attributes[:type]
43
- attributes[:data] = fields['data'] || attributes[:data]
44
- attributes[:date] = Time.iso8601(fields['date']) rescue nil if fields.has_key?('date')
45
- attributes[:member_creator_id] = fields['idMemberCreator'] || attributes[:member_creator_id]
46
- attributes[:member_participant] = fields['member'] || attributes[:member_participant]
47
- self
48
- end
49
-
50
56
  # Returns the board this action occurred on.
51
57
  def board
52
58
  Board.from_response client.get("/actions/#{id}/board")
@@ -1,40 +1,53 @@
1
1
  module Trello
2
2
  # A file or url that is linked to a Trello card
3
3
  #
4
- # @!attribute id
4
+ # @!attribute [r] id
5
5
  # @return [String]
6
- # @!attribute name
7
- # @return [String]
8
- # @!attribute url
9
- # @return [String]
10
- # @!attribute pos
6
+ # @!attribute [r] position
11
7
  # @return [Float]
12
- # @!attribute bytes
8
+ # @!attribute [r] bytes
13
9
  # @return [Fixnum]
14
- # @!attribute date
10
+ # @!attribute [r] member_id
11
+ # @return [String]
12
+ # @!attribute [r] date
15
13
  # @return [Datetime]
16
- # @!attribute is_upload
14
+ # @!attribute [r] is_upload
17
15
  # @return [Boolean]
18
- # @!attribute mime_type
16
+ # @!attribute [r] previews
17
+ # @return [Array]
18
+ # @!attribute [r] file_name
19
+ # @return [String]
20
+ # @!attribute [r] edge_color
21
+ # @return [String]
22
+ # @!attribute [rw] name
19
23
  # @return [String]
24
+ # @!attribute [rw] url
25
+ # @return [String]
26
+ # @!attribute [rw] mime_type
27
+ # @return [String]
28
+ # @!attribute [w] file
29
+ # @return [String]
30
+ # @!attribute [w] set_as_cover
31
+ # @return [Boolean]
20
32
  class Attachment < BasicData
21
- register_attributes :name, :id, :pos, :url, :bytes, :member_id, :date, :is_upload, :mime_type, :previews
22
- # Update the fields of an attachment.
23
- #
24
- # Supply a hash of stringkeyed data retrieved from the Trello API representing
25
- # an attachment.
26
- def update_fields(fields)
27
- attributes[:name] = fields['name'] || attributes[:name]
28
- attributes[:id] = fields['id'] || attributes[:id]
29
- attributes[:pos] = fields['pos'] || attributes[:pos]
30
- attributes[:url] = fields['url'] || attributes[:url]
31
- attributes[:bytes] = fields['bytes'].to_i || attributes[:bytes]
32
- attributes[:member_id] = fields['idMember'] || attributes[:member_id]
33
- attributes[:date] = Time.parse(fields['date']).presence || attributes[:date]
34
- attributes[:is_upload] = fields['isUpload'] if fields.has_key?('isUpload')
35
- attributes[:mime_type] = fields['mimeType'] || attributes[:mime_type]
36
- attributes[:previews] = fields['previews'] if fields.has_key?('previews')
37
- self
33
+ schema do
34
+ # Readonly
35
+ attribute :id, readonly: true, primary_key: true
36
+ attribute :position, readonly: true, remote_key: 'pos'
37
+ attribute :bytes, readonly: true
38
+ attribute :member_id, remote_key: 'idMember', readonly: true
39
+ attribute :date, serializer: 'Time', readonly: true
40
+ attribute :is_upload, remote_key: 'isUpload', readonly: true
41
+ attribute :previews, readonly: true
42
+ attribute :file_name, remote_key: 'fileName', readonly: true
43
+ attribute :edge_color, remote_key: 'edgeColor', readonly: true
44
+
45
+ # Writable but create only
46
+ attribute :name, create_only: true
47
+ attribute :url, create_only: true
48
+ attribute :mime_type, remote_key: 'mimeType', create_only: true
49
+ attribute :file, create_only: true
50
+ attribute :set_as_cover, remote_key: 'setCover', create_only: true
38
51
  end
39
52
  end
40
53
  end
@@ -42,12 +42,21 @@ module Trello
42
42
  end
43
43
  end
44
44
 
45
- def self.register_attributes(*names_and_options)
46
- has_opts = names_and_options.last.kind_of?(Hash)
47
- readonly_attributes = has_opts ? names_and_options.pop[:readonly] : []
48
- attributes = names_and_options
45
+ def self.schema(&block)
46
+ @schema ||= Schema.new
47
+ return @schema unless block_given?
49
48
 
50
- RegisterAttributes.execute(self, attributes, readonly_attributes)
49
+ @schema.instance_eval(&block)
50
+
51
+ register_attrs
52
+
53
+ @schema
54
+ end
55
+
56
+ def self.register_attrs
57
+ schema.attrs.values.each do |attribute|
58
+ attribute.register(self)
59
+ end
51
60
  end
52
61
 
53
62
  def self.one(name, opts = {})
@@ -62,16 +71,72 @@ module Trello
62
71
  Trello.client
63
72
  end
64
73
 
65
- register_attributes :id, readonly: [ :id ]
66
-
67
74
  attr_writer :client
68
75
 
69
76
  def initialize(fields = {})
70
- update_fields(fields)
77
+ initialize_fields(fields)
78
+ end
79
+
80
+ def save
81
+ return update! if id
82
+
83
+ payload = {}
84
+
85
+ schema.attrs.each do |_, attribute|
86
+ payload = attribute.build_payload_for_create(attributes, payload)
87
+ end
88
+
89
+ post(collection_path, payload)
90
+ end
91
+
92
+ def update!
93
+ fail "Cannot save new instance." unless id
94
+
95
+ @previously_changed = changes
96
+
97
+ payload = {}
98
+ changed_attrs = attributes.select {|name, _| changed.include?(name.to_s)}
99
+
100
+ schema.attrs.each do |_, attribute|
101
+ payload = attribute.build_payload_for_update(changed_attrs, payload)
102
+ end
103
+
104
+ from_response client.put(element_path, payload)
105
+
106
+ @changed_attributes.clear if @changed_attributes.respond_to?(:clear)
107
+ changes_applied if respond_to?(:changes_applied)
108
+
109
+ self
71
110
  end
72
111
 
73
112
  def update_fields(fields)
74
- raise NotImplementedError, "#{self.class} does not implement update_fields."
113
+ attrs = {}
114
+
115
+ schema.attrs.each do |_, attribute|
116
+ attrs = attribute.build_pending_update_attributes(fields, attrs)
117
+ end
118
+
119
+ attrs.each do |name, value|
120
+ send("#{name}=", value)
121
+ end
122
+
123
+ self
124
+ end
125
+
126
+ def collection_path
127
+ "/#{collection_name}"
128
+ end
129
+
130
+ def element_path
131
+ "/#{collection_name}/#{id}"
132
+ end
133
+
134
+ def collection_name
135
+ @collection_path ||= ActiveSupport::Inflector.pluralize(element_name)
136
+ end
137
+
138
+ def element_name
139
+ @element_name ||= model_name.element
75
140
  end
76
141
 
77
142
  # Refresh the contents of our object.
@@ -95,5 +160,35 @@ module Trello
95
160
  def client
96
161
  @client ||= self.class.client
97
162
  end
163
+
164
+ def schema
165
+ self.class.schema
166
+ end
167
+
168
+ def attributes
169
+ @__attributes ||= ActiveSupport::HashWithIndifferentAccess.new
170
+ end
171
+
172
+ private
173
+
174
+ def attributes=(attrs)
175
+ @__attributes = attrs
176
+ end
177
+
178
+ def initialize_fields(fields)
179
+ schema.attrs.each do |_, attribute|
180
+ self.attributes = attribute.build_attributes(fields, attributes)
181
+ end
182
+
183
+ self
184
+ end
185
+
186
+ def post(path, body)
187
+ from_response client.post(path, body)
188
+ end
189
+
190
+ def put(path, body)
191
+ from_response client.put(path, body)
192
+ end
98
193
  end
99
194
  end
data/lib/trello/board.rb CHANGED
@@ -4,21 +4,100 @@ module Trello
4
4
  #
5
5
  # @!attribute [r] id
6
6
  # @return [String]
7
- # @!attribute [r] name
7
+ # @!attribute [r] starred
8
+ # @return [Boolean]
9
+ # @!attribute [r] pinned
10
+ # @return [Boolean]
11
+ # @!attribute [r] url
12
+ # @return [String]
13
+ # @!attribute [r] short_url
14
+ # @return [String]
15
+ # @!attribute [r] prefs
16
+ # @return [Hash]
17
+ # @!attribute [r] last_activity_date
18
+ # @return [Datetime]
19
+ # @!attribute [r] description_data
20
+ # @return [Datetime]
21
+ # @!attribute [r] enterprise_id
22
+ # @return [String]
23
+ # @!attribute [rw] name
8
24
  # @return [String]
9
25
  # @!attribute [rw] description
10
26
  # @return [String]
11
- # @!attribute [rw] closed
27
+ # @!attribute [rw] organization_id
28
+ # @return [String]
29
+ # @!attribute [rw] visibility_level
30
+ # @return [String]
31
+ # @!attribute [rw] voting_permission_level
32
+ # @return [String]
33
+ # @!attribute [rw] comment_permission_level
34
+ # @return [String]
35
+ # @!attribute [rw] invitation_permission_level
36
+ # @return [String]
37
+ # @!attribute [rw] enable_self_join
12
38
  # @return [Boolean]
13
- # @!attribute [r] url
39
+ # @!attribute [rw] enable_card_covers
40
+ # @return [Boolean]
41
+ # @!attribute [rw] background_color
14
42
  # @return [String]
15
- # @!attribute [rw] organization_id
16
- # @return [String] A 24-character hex string
17
- # @!attribute [r] prefs
18
- # @return [Hash] A 24-character hex string
43
+ # @!attribute [rw] background_image
44
+ # @return [String]
45
+ # @!attribute [rw] card_aging_type
46
+ # @return [String]
47
+ # @!attribute [w] use_default_labels
48
+ # @return [Boolean]
49
+ # @!attribute [w] use_default_lists
50
+ # @return [Boolean]
51
+ # @!attribute [w] source_board_id
52
+ # @return [String]
53
+ # @!attribute [w] keep_cards_from_source
54
+ # @return [String]
55
+ # @!attribute [w] power_ups
56
+ # @return [String]
57
+ # @!attribute [rw] closed
58
+ # @return [Boolean]
59
+ # @!attribute [w] subscribed
60
+ # @return [Boolean]
19
61
  class Board < BasicData
20
- register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
21
- readonly: [ :id, :url, :last_activity_date ]
62
+ schema do
63
+ attribute :id, readonly: true, primary_key: true
64
+
65
+ # Readonly
66
+ attribute :starred, readonly: true
67
+ attribute :pinned, readonly: true
68
+ attribute :url, readonly: true
69
+ attribute :short_url, readonly: true, remote_key: 'shortUrl'
70
+ attribute :prefs, readonly: true, default: {}
71
+ attribute :last_activity_date, readonly: true, remote_key: 'dateLastActivity', serializer: 'Time'
72
+ attribute :description_data, readonly: true, remote_key: 'descData'
73
+ attribute :enterprise_id, readonly: true, remote_key: 'idEnterprise'
74
+
75
+ # Writable
76
+ attribute :name
77
+ attribute :description, remote_key: 'desc'
78
+ attribute :organization_id, remote_key: 'idOrganization'
79
+ attribute :visibility_level, remote_key: 'permissionLevel', class_name: 'BoardPref'
80
+ attribute :voting_permission_level, remote_key: 'voting', class_name: 'BoardPref'
81
+ attribute :comment_permission_level, remote_key: 'comments', class_name: 'BoardPref'
82
+ attribute :invitation_permission_level, remote_key: 'invitations', class_name: 'BoardPref'
83
+ attribute :enable_self_join, remote_key: 'selfJoin', class_name: 'BoardPref'
84
+ attribute :enable_card_covers, remote_key: 'cardCovers', class_name: 'BoardPref'
85
+ attribute :background_color, remote_key: 'background', class_name: 'BoardPref'
86
+ attribute :background_image, remote_key: 'backgroundImage', class_name: 'BoardPref'
87
+ attribute :card_aging_type, remote_key: 'cardAging', class_name: 'BoardPref'
88
+
89
+ # Writable but for create only
90
+ attribute :use_default_labels, create_only: true, remote_key: 'defaultLabels'
91
+ attribute :use_default_lists, create_only: true, remote_key: 'defaultLists'
92
+ attribute :source_board_id, create_only: true, remote_key: 'idBoardSource'
93
+ attribute :keep_cards_from_source, create_only: true, remote_key: 'keepFromSource'
94
+ attribute :power_ups, create_only: true, remote_key: 'powerUps'
95
+
96
+ # Writable but for update only
97
+ attribute :closed, update_only: true
98
+ attribute :subscribed, update_only: true
99
+ end
100
+
22
101
  validates_presence_of :id, :name
23
102
  validates_length_of :name, in: 1..16384
24
103
  validates_length_of :description, maximum: 16384
@@ -26,82 +105,12 @@ module Trello
26
105
  include HasActions
27
106
 
28
107
  class << self
29
- # Finds a board.
30
- #
31
- # @param [String] id Either the board's short ID (an alphanumeric string,
32
- # found e.g. in the board's URL) or its long ID (a 24-character hex
33
- # string.)
34
- # @param [Hash] params
35
- #
36
- # @raise [Trello::Board] if a board with the given ID could not be found.
37
- #
38
- # @return [Trello::Board]
39
- def find(id, params = {})
40
- client.find(:board, id, params)
41
- end
42
-
43
- def create(fields)
44
- data = {
45
- 'name' => fields[:name],
46
- 'desc' => fields[:description],
47
- 'closed' => fields[:closed] || false,
48
- 'starred' => fields[:starred] || false }
49
- data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id]
50
- data.merge!('prefs' => fields[:prefs]) if fields[:prefs]
51
- client.create(:board, data)
52
- end
53
-
54
108
  # @return [Array<Trello::Board>] all boards for the current user
55
109
  def all
56
110
  from_response client.get("/members/#{Member.find(:me).username}/boards")
57
111
  end
58
112
  end
59
113
 
60
- def save
61
- return update! if id
62
-
63
- fields = { name: name }
64
- fields.merge!(desc: description) if description
65
- fields.merge!(idOrganization: organization_id) if organization_id
66
- fields.merge!(flat_prefs)
67
-
68
- from_response(client.post("/boards", fields))
69
- end
70
-
71
- def update!
72
- fail "Cannot save new instance." unless self.id
73
-
74
- @previously_changed = changes
75
- @changed_attributes.clear if @changed_attributes.respond_to?(:clear)
76
- changes_applied if respond_to?(:changes_applied)
77
-
78
- fields = {
79
- name: attributes[:name],
80
- desc: attributes[:description],
81
- closed: attributes[:closed],
82
- starred: attributes[:starred],
83
- idOrganization: attributes[:organization_id]
84
- }
85
- fields.merge!(flat_prefs)
86
-
87
- from_response client.put("/boards/#{self.id}/", fields)
88
- end
89
-
90
- def update_fields(fields)
91
- attributes[:id] = fields['id'] || fields[:id] if fields['id'] || fields[:id]
92
- attributes[:name] = fields['name'] || fields[:name] if fields['name'] || fields[:name]
93
- attributes[:description] = fields['desc'] || fields[:desc] if fields['desc'] || fields[:desc]
94
- attributes[:closed] = fields['closed'] if fields.has_key?('closed')
95
- attributes[:closed] = fields[:closed] if fields.has_key?(:closed)
96
- attributes[:starred] = fields['starred'] if fields.has_key?('starred')
97
- attributes[:starred] = fields[:starred] if fields.has_key?(:starred)
98
- attributes[:url] = fields['url'] if fields['url']
99
- attributes[:organization_id] = fields['idOrganization'] || fields[:organization_id] if fields['idOrganization'] || fields[:organization_id]
100
- attributes[:prefs] = fields['prefs'] || fields[:prefs] || {}
101
- attributes[:last_activity_date] = Time.iso8601(fields['dateLastActivity']) rescue nil
102
- self
103
- end
104
-
105
114
  # @return [Boolean]
106
115
  def closed?
107
116
  attributes[:closed]
@@ -188,28 +197,5 @@ module Trello
188
197
  "/boards/#{id}"
189
198
  end
190
199
 
191
- private
192
-
193
- # On creation
194
- # https://trello.com/docs/api/board/#post-1-boards
195
- # - permissionLevel
196
- # - voting
197
- # - comments
198
- # - invitations
199
- # - selfJoin
200
- # - cardCovers
201
- # - background
202
- # - cardAging
203
- #
204
- # On update
205
- # https://trello.com/docs/api/board/#put-1-boards-board-id
206
- # Same as above plus:
207
- # - calendarFeedEnabled
208
- def flat_prefs
209
- separator = id ? "/" : "_"
210
- attributes[:prefs].inject({}) do |hash, (pref, v)|
211
- hash.merge("prefs#{separator}#{pref}" => v)
212
- end
213
- end
214
200
  end
215
201
  end