ruby-trello 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -10
- data/lib/trello.rb +47 -35
- data/lib/trello/action.rb +4 -2
- data/lib/trello/association_builder/has_many.rb +17 -0
- data/lib/trello/association_builder/has_one.rb +16 -0
- data/lib/trello/association_fetcher/has_many.rb +26 -0
- data/lib/trello/association_fetcher/has_many/fetch.rb +47 -0
- data/lib/trello/association_fetcher/has_many/params.rb +56 -0
- data/lib/trello/association_fetcher/has_one.rb +25 -0
- data/lib/trello/association_fetcher/has_one/fetch.rb +49 -0
- data/lib/trello/association_fetcher/has_one/params.rb +36 -0
- data/lib/trello/association_infer_tool.rb +13 -0
- data/lib/trello/association_proxy.rb +1 -1
- data/lib/trello/basic_data.rb +7 -48
- data/lib/trello/board.rb +1 -1
- data/lib/trello/card.rb +88 -36
- data/lib/trello/custom_field.rb +26 -9
- data/lib/trello/custom_field_item.rb +32 -12
- data/lib/trello/label.rb +24 -7
- data/lib/trello/member.rb +1 -1
- data/lib/trello/register_attributes.rb +54 -0
- data/spec/action_spec.rb +1 -1
- data/spec/card_spec.rb +98 -22
- data/spec/cassettes/can_add_a_file_from_url_on_a_card.yml +189 -0
- data/spec/cassettes/can_add_a_file_on_a_card.yml +200 -0
- data/spec/cassettes/can_add_a_member_to_a_card.yml +190 -0
- data/spec/cassettes/can_add_label_on_a_card.yml +281 -0
- data/spec/cassettes/can_close_bong_a_card.yml +189 -0
- data/spec/cassettes/can_get_actions.yml +196 -0
- data/spec/cassettes/can_get_attachments.yml +187 -0
- data/spec/cassettes/can_get_comments.yml +193 -0
- data/spec/cassettes/can_move_a_card_to_another_board_with_specific_list.yml +373 -0
- data/spec/cassettes/can_move_a_card_to_another_board_without_specific_list.yml +281 -0
- data/spec/cassettes/can_move_a_card_to_another_list.yml +281 -0
- data/spec/cassettes/can_remove_a_member_from_a_card.yml +185 -0
- data/spec/cassettes/can_remove_an_attachment_on_a_card.yml +277 -0
- data/spec/cassettes/can_remove_an_upvote_on_a_card.yml +465 -0
- data/spec/cassettes/can_remove_label_on_a_card.yml +279 -0
- data/spec/cassettes/can_success_add_comment_to_a_card.yml +196 -0
- data/spec/cassettes/can_success_copy_checklist_to_a_card.yml +281 -0
- data/spec/cassettes/can_success_copy_checklist_to_a_card_without_name_pos.yml +281 -0
- data/spec/cassettes/can_success_create_a_card.yml +99 -0
- data/spec/cassettes/can_success_create_new_checklist_to_a_card.yml +189 -0
- data/spec/cassettes/can_success_delete_card.yml +185 -0
- data/spec/cassettes/can_success_upate_a_card.yml +189 -0
- data/spec/cassettes/can_success_update_bong_a_card.yml +191 -0
- data/spec/cassettes/can_upvote_on_a_card.yml +469 -0
- data/spec/cassettes/card_find_with_id_and_get_all_fields.yml +95 -0
- data/spec/cassettes/card_find_with_id_and_get_specific_fields.yml +96 -0
- data/spec/cassettes/custom_field_item_save_1.yml +97 -0
- data/spec/cassettes/custom_field_item_save_2.yml +281 -0
- data/spec/cassettes/get_board_of_card.yml +187 -0
- data/spec/cassettes/get_check_item_states_of_card.yml +188 -0
- data/spec/cassettes/get_checklists_of_card.yml +187 -0
- data/spec/cassettes/get_cover_image_of_card.yml +187 -0
- data/spec/cassettes/get_custom_field_items_of_card.yml +187 -0
- data/spec/cassettes/get_list_of_card.yml +188 -0
- data/spec/cassettes/get_lists.yml +187 -0
- data/spec/cassettes/get_members_of_card.yml +189 -0
- data/spec/cassettes/get_plugin_data_of_card.yml +187 -0
- data/spec/cassettes/get_voters_of_card.yml +188 -0
- data/spec/cassettes/remove_upvote_on_a_card_when_have_not_voted.yml +366 -0
- data/spec/cassettes/revote_on_a_card.yml +464 -0
- data/spec/custom_field_item_spec.rb +74 -0
- data/spec/custom_field_spec.rb +76 -0
- data/spec/integration/basic_data/many_spec.rb +123 -0
- data/spec/integration/basic_data/one_spec.rb +84 -0
- data/spec/integration/basic_data/register_attributes_spec.rb +75 -0
- data/spec/integration/board_lists_spec.rb +21 -0
- data/spec/integration/card/add_and_remove_attachment_spec.rb +45 -0
- data/spec/integration/card/add_and_remove_label_spec.rb +35 -0
- data/spec/integration/card/add_checklist_spec.rb +32 -0
- data/spec/integration/card/add_comment_spec.rb +19 -0
- data/spec/integration/card/add_memeber_spec.rb +19 -0
- data/spec/integration/card/associations/actions_spec.rb +17 -0
- data/spec/integration/card/associations/attachments_spec.rb +18 -0
- data/spec/integration/card/associations/board_spec.rb +17 -0
- data/spec/integration/card/associations/check_item_states_spec.rb +17 -0
- data/spec/integration/card/associations/checklists_spec.rb +18 -0
- data/spec/integration/card/associations/comments_spec.rb +19 -0
- data/spec/integration/card/associations/cover_image_spec.rb +18 -0
- data/spec/integration/card/associations/custom_field_items_spec.rb +18 -0
- data/spec/integration/card/associations/list_spec.rb +16 -0
- data/spec/integration/card/associations/members_spec.rb +18 -0
- data/spec/integration/card/associations/plugin_data_spec.rb +18 -0
- data/spec/integration/card/associations/voters_spec.rb +17 -0
- data/spec/integration/card/close!_spec.rb +16 -0
- data/spec/integration/card/create_new_check_list_spec.rb +19 -0
- data/spec/integration/card/create_spec.rb +50 -0
- data/spec/integration/card/delete_spec.rb +16 -0
- data/spec/integration/card/find_spec.rb +67 -0
- data/spec/integration/card/move_to_board_spec.rb +36 -0
- data/spec/integration/card/move_to_list_spec.rb +20 -0
- data/spec/integration/card/remove_member_spec.rb +19 -0
- data/spec/integration/card/save_spec.rb +61 -0
- data/spec/integration/card/update!_spec.rb +53 -0
- data/spec/integration/card/vote_spec.rb +50 -0
- data/spec/integration/custom_field_item_spec.rb +47 -0
- data/spec/label_spec.rb +79 -0
- data/spec/spec_helper.rb +48 -23
- data/spec/unit/trello/association_builder/has_many_spec.rb +36 -0
- data/spec/unit/trello/association_builder/has_one_spec.rb +36 -0
- data/spec/unit/trello/association_fetcher/has_many/fetch_spec.rb +38 -0
- data/spec/unit/trello/association_fetcher/has_many/params_spec.rb +107 -0
- data/spec/unit/trello/association_fetcher/has_many_spec.rb +50 -0
- data/spec/unit/trello/association_fetcher/has_one/fetch_spec.rb +51 -0
- data/spec/unit/trello/association_fetcher/has_one/params_spec.rb +81 -0
- data/spec/unit/trello/association_fetcher/has_one_spec.rb +49 -0
- data/spec/unit/trello/association_infer_tool_spec.rb +41 -0
- data/spec/unit/trello/basic_data_spec.rb +54 -0
- data/spec/unit/trello/card_spec.rb +103 -0
- metadata +185 -6
@@ -0,0 +1,36 @@
|
|
1
|
+
module Trello
|
2
|
+
module AssociationFetcher
|
3
|
+
class HasOne
|
4
|
+
class Params
|
5
|
+
attr_reader :association_owner
|
6
|
+
|
7
|
+
def initialize(association_owner:, association_name:, association_options:)
|
8
|
+
@association_owner = association_owner
|
9
|
+
@association_name = association_name
|
10
|
+
@association_options = association_options || {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def association_class
|
14
|
+
association_options[:via] || infer_class_on(association_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def association_restful_name
|
18
|
+
association_options[:path]
|
19
|
+
end
|
20
|
+
|
21
|
+
def association_restful_id
|
22
|
+
id_field = association_options[:using] || :id
|
23
|
+
association_owner.send(id_field)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :association_name, :association_options
|
29
|
+
|
30
|
+
def infer_class_on(name)
|
31
|
+
AssociationInferTool.infer_class_on_name(name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Trello
|
2
|
+
class AssociationInferTool
|
3
|
+
class << self
|
4
|
+
def infer_restful_resource_on_class(klass)
|
5
|
+
klass.to_s.split('::').last.downcase.pluralize
|
6
|
+
end
|
7
|
+
|
8
|
+
def infer_class_on_name(name)
|
9
|
+
Trello.const_get(name.to_s.singularize.camelize)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/trello/basic_data.rb
CHANGED
@@ -42,61 +42,20 @@ module Trello
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def self.register_attributes(*
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# Defines the attribute getter and setters.
|
50
|
-
class_eval do
|
51
|
-
define_method :attributes do
|
52
|
-
@__attributes ||= names.reduce({}) { |hash, k| hash.merge(k.to_sym => nil) }
|
53
|
-
end
|
54
|
-
|
55
|
-
names.each do |key|
|
56
|
-
define_method(:"#{key}") { @__attributes[key] }
|
57
|
-
|
58
|
-
unless options[:readonly].include?(key.to_sym)
|
59
|
-
define_method :"#{key}=" do |val|
|
60
|
-
send(:"#{key}_will_change!") unless val == @__attributes[key]
|
61
|
-
@__attributes[key] = val
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
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
|
65
49
|
|
66
|
-
|
67
|
-
end
|
50
|
+
RegisterAttributes.execute(self, attributes, readonly_attributes)
|
68
51
|
end
|
69
52
|
|
70
53
|
def self.one(name, opts = {})
|
71
|
-
|
72
|
-
define_method(:"#{name}") do |*args|
|
73
|
-
options = opts.dup
|
74
|
-
klass = options.delete(:via) || Trello.const_get(name.to_s.camelize)
|
75
|
-
ident = options.delete(:using) || :id
|
76
|
-
path = options.delete(:path)
|
77
|
-
|
78
|
-
if path
|
79
|
-
client.find(path, self.send(ident))
|
80
|
-
else
|
81
|
-
klass.find(self.send(ident))
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
54
|
+
AssociationBuilder::HasOne.build(self, name, opts)
|
85
55
|
end
|
86
56
|
|
87
57
|
def self.many(name, opts = {})
|
88
|
-
|
89
|
-
define_method(:"#{name}") do |*args|
|
90
|
-
options = opts.dup
|
91
|
-
resource = options.delete(:in) || self.class.to_s.split("::").last.downcase.pluralize
|
92
|
-
klass = options.delete(:via) || Trello.const_get(name.to_s.singularize.camelize)
|
93
|
-
path = options.delete(:path) || name
|
94
|
-
params = options.merge(args[0] || {})
|
95
|
-
|
96
|
-
resources = client.find_many(klass, "/#{resource}/#{id}/#{path}", params)
|
97
|
-
MultiAssociation.new(self, resources).proxy
|
98
|
-
end
|
99
|
-
end
|
58
|
+
AssociationBuilder::HasMany.build(self, name, opts)
|
100
59
|
end
|
101
60
|
|
102
61
|
def self.client
|
data/lib/trello/board.rb
CHANGED
@@ -72,7 +72,7 @@ module Trello
|
|
72
72
|
fail "Cannot save new instance." unless self.id
|
73
73
|
|
74
74
|
@previously_changed = changes
|
75
|
-
@changed_attributes.
|
75
|
+
@changed_attributes.clear if @changed_attributes.respond_to?(:clear)
|
76
76
|
changes_applied if respond_to?(:changes_applied)
|
77
77
|
|
78
78
|
fields = {
|
data/lib/trello/card.rb
CHANGED
@@ -169,36 +169,29 @@ module Trello
|
|
169
169
|
#
|
170
170
|
# @return [Trello::Card] self
|
171
171
|
def update_fields(fields)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
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)
|
196
185
|
end
|
197
186
|
|
198
187
|
# Returns a reference to the board this card is part of.
|
199
188
|
one :board, path: :boards, using: :board_id
|
189
|
+
|
200
190
|
# Returns a reference to the cover image attachment
|
201
|
-
|
191
|
+
def cover_image(params = {})
|
192
|
+
response = client.get("/cards/#{id}/attachments/#{cover_image_id}", params)
|
193
|
+
CoverImage.from_response(response)
|
194
|
+
end
|
202
195
|
|
203
196
|
# Returns a list of checklists associated with the card.
|
204
197
|
#
|
@@ -271,16 +264,41 @@ module Trello
|
|
271
264
|
#
|
272
265
|
# @raise [Trello::Error] if the card could not be updated.
|
273
266
|
#
|
274
|
-
# @return [
|
275
|
-
# the Trello API.
|
267
|
+
# @return [Trello::Card] updated self
|
276
268
|
def update!
|
277
269
|
@previously_changed = changes
|
278
270
|
# extract only new values to build payload
|
279
271
|
payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
|
280
|
-
|
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)
|
281
277
|
changes_applied if respond_to?(:changes_applied)
|
282
278
|
|
283
|
-
|
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
|
284
302
|
end
|
285
303
|
|
286
304
|
# Delete this card
|
@@ -315,7 +333,7 @@ module Trello
|
|
315
333
|
|
316
334
|
# Is the record valid?
|
317
335
|
def valid?
|
318
|
-
name && list_id
|
336
|
+
!(name && list_id).nil?
|
319
337
|
end
|
320
338
|
|
321
339
|
# Add a comment with the supplied text.
|
@@ -324,10 +342,12 @@ module Trello
|
|
324
342
|
end
|
325
343
|
|
326
344
|
# Add a checklist to this card
|
327
|
-
def add_checklist(checklist)
|
328
|
-
|
329
|
-
|
330
|
-
|
345
|
+
def add_checklist(checklist, name: nil, position: nil)
|
346
|
+
payload = { idChecklistSource: checklist.id }
|
347
|
+
payload[:name] = name if name
|
348
|
+
payload[:pos] = position if position
|
349
|
+
|
350
|
+
client.post("/cards/#{id}/checklists", payload)
|
331
351
|
end
|
332
352
|
|
333
353
|
# create a new checklist and add it to this card
|
@@ -366,14 +386,14 @@ module Trello
|
|
366
386
|
|
367
387
|
# Add a member to this card
|
368
388
|
def add_member(member)
|
369
|
-
client.post("/cards/#{id}/
|
389
|
+
client.post("/cards/#{id}/idMembers", {
|
370
390
|
value: member.id
|
371
391
|
})
|
372
392
|
end
|
373
393
|
|
374
394
|
# Remove a member from this card
|
375
395
|
def remove_member(member)
|
376
|
-
client.delete("/cards/#{id}/
|
396
|
+
client.delete("/cards/#{id}/idMembers/#{member.id}")
|
377
397
|
end
|
378
398
|
|
379
399
|
# Current authenticated user upvotes a card
|
@@ -465,5 +485,37 @@ module Trello
|
|
465
485
|
def me
|
466
486
|
@me ||= Member.find(:me)
|
467
487
|
end
|
488
|
+
|
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
|
+
|
468
520
|
end
|
469
521
|
end
|
data/lib/trello/custom_field.rb
CHANGED
@@ -58,14 +58,14 @@ module Trello
|
|
58
58
|
many :custom_field_options, path: 'options'
|
59
59
|
|
60
60
|
def update_fields(fields)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
send('name_will_change!') if fields_has_key?(fields, :name)
|
62
|
+
send('pos_will_change!') if fields_has_key?(fields, :pos)
|
63
|
+
|
64
|
+
initialize_fields(fields)
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(fields = {})
|
68
|
+
initialize_fields(fields)
|
69
69
|
end
|
70
70
|
|
71
71
|
# Saves a record.
|
@@ -88,7 +88,7 @@ module Trello
|
|
88
88
|
@previously_changed = changes
|
89
89
|
# extract only new values to build payload
|
90
90
|
payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
|
91
|
-
@changed_attributes.
|
91
|
+
@changed_attributes.clear if @changed_attributes.respond_to?(:clear)
|
92
92
|
changes_applied if respond_to?(:changes_applied)
|
93
93
|
|
94
94
|
client.put("/customFields/#{id}", payload)
|
@@ -110,5 +110,22 @@ module Trello
|
|
110
110
|
def delete_option(option_id)
|
111
111
|
client.delete("/customFields/#{id}/options/#{option_id}")
|
112
112
|
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def fields_has_key?(fields, key)
|
117
|
+
fields.key?(SYMBOL_TO_STRING[key]) || fields.key?(key)
|
118
|
+
end
|
119
|
+
|
120
|
+
def initialize_fields(fields)
|
121
|
+
attributes[:id] = fields[SYMBOL_TO_STRING[:id]] || fields[:id] || attributes[:id]
|
122
|
+
attributes[:name] = fields[SYMBOL_TO_STRING[:name]] || fields[:name] || attributes[:name]
|
123
|
+
attributes[:model_id] = fields[SYMBOL_TO_STRING[:model_id]] || fields[:model_id] || attributes[:model_id]
|
124
|
+
attributes[:model_type] = fields[SYMBOL_TO_STRING[:model_type]] || fields[:model_type] || attributes[:model_type]
|
125
|
+
attributes[:field_group] = fields[SYMBOL_TO_STRING[:field_group]] || fields[:field_group] || attributes[:field_group]
|
126
|
+
attributes[:type] = fields[SYMBOL_TO_STRING[:type]] || fields[:type] || attributes[:type]
|
127
|
+
attributes[:pos] = fields[SYMBOL_TO_STRING[:pos]] || fields[:pos] || attributes[:pos]
|
128
|
+
self
|
129
|
+
end
|
113
130
|
end
|
114
131
|
end
|
@@ -17,23 +17,24 @@ module Trello
|
|
17
17
|
# Supply a hash of string keyed data retrieved from the Trello API representing
|
18
18
|
# an item state.
|
19
19
|
def update_fields(fields)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
if fields_has_key?(fields, 'value')
|
21
|
+
send('value_will_change!')
|
22
|
+
elsif fields_has_key?(fields, 'idValue')
|
23
|
+
send('option_id_will_change!')
|
24
|
+
end
|
25
|
+
|
26
|
+
initialize_fields(fields)
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(fields = {})
|
30
|
+
initialize_fields(fields)
|
30
31
|
end
|
31
32
|
|
32
33
|
def update!
|
33
34
|
@previously_changed = changes
|
34
35
|
# extract only new values to build payload
|
35
36
|
payload = Hash[changes.map { |key, values| [key.to_sym, values[1]] }]
|
36
|
-
@changed_attributes.
|
37
|
+
@changed_attributes.clear if @changed_attributes.respond_to?(:clear)
|
37
38
|
changes_applied if respond_to?(:changes_applied)
|
38
39
|
|
39
40
|
client.put("/card/#{model_id}/customField/#{custom_field_id}/item", payload)
|
@@ -49,7 +50,7 @@ module Trello
|
|
49
50
|
# If we have an id, just update our fields.
|
50
51
|
return update! if id
|
51
52
|
|
52
|
-
from_response client.
|
53
|
+
from_response client.put("/card/#{model_id}/customField/#{custom_field_id}/item", {
|
53
54
|
value: value
|
54
55
|
})
|
55
56
|
end
|
@@ -74,5 +75,24 @@ module Trello
|
|
74
75
|
option.value
|
75
76
|
end
|
76
77
|
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def fields_has_key?(fields, key)
|
82
|
+
fields.key?(key.to_s) || fields.key?(key.to_sym)
|
83
|
+
end
|
84
|
+
|
85
|
+
def initialize_fields(fields)
|
86
|
+
attributes[:id] = fields['id'] || fields[:id] || attributes[:id]
|
87
|
+
attributes[:model_id] = fields['idModel'] || fields[:model_id] || attributes[:model_id]
|
88
|
+
attributes[:custom_field_id] = fields['idCustomField'] || fields[:custom_field_id] || attributes[:custom_field_id]
|
89
|
+
attributes[:model_type] = fields['modelType'] || fields[:model_type] || attributes[:model_type]
|
90
|
+
# Dropdown custom field items do not have a value, they have an ID that maps to
|
91
|
+
# a different endpoint to get the value
|
92
|
+
attributes[:option_id] = fields['idValue'] || fields[:idValue] if fields_has_key?(fields, 'idValue')
|
93
|
+
# value format: { "text": "hello world" }
|
94
|
+
attributes[:value] = fields['value'] || fields[:value] if fields_has_key?(fields, 'value')
|
95
|
+
self
|
96
|
+
end
|
77
97
|
end
|
78
98
|
end
|
data/lib/trello/label.rb
CHANGED
@@ -64,12 +64,14 @@ module Trello
|
|
64
64
|
# Supply a hash of stringkeyed data retrieved from the Trello API representing
|
65
65
|
# a label.
|
66
66
|
def update_fields(fields)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
send('name_will_change!') if fields_has_key?(fields, :name)
|
68
|
+
send('color_will_change!') if fields_has_key?(fields, :color)
|
69
|
+
|
70
|
+
initialize_fields(fields)
|
71
|
+
end
|
72
|
+
|
73
|
+
def initialize(fields = {})
|
74
|
+
initialize_fields(fields)
|
73
75
|
end
|
74
76
|
|
75
77
|
# Returns a reference to the board this label is currently connected.
|
@@ -95,7 +97,7 @@ module Trello
|
|
95
97
|
@previously_changed = changes
|
96
98
|
# extract only new values to build payload
|
97
99
|
payload = Hash[changes.map { |key, values| [SYMBOL_TO_STRING[key.to_sym].to_sym, values[1]] }]
|
98
|
-
@changed_attributes.
|
100
|
+
@changed_attributes.clear if @changed_attributes.respond_to?(:clear)
|
99
101
|
changes_applied if respond_to?(:changes_applied)
|
100
102
|
|
101
103
|
client.put("/labels/#{id}", payload)
|
@@ -105,5 +107,20 @@ module Trello
|
|
105
107
|
def delete
|
106
108
|
client.delete("/labels/#{id}")
|
107
109
|
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def fields_has_key?(fields, key)
|
114
|
+
fields.key?(SYMBOL_TO_STRING[key]) || fields.key?(key)
|
115
|
+
end
|
116
|
+
|
117
|
+
def initialize_fields(fields)
|
118
|
+
attributes[:id] = fields['id'] || attributes[:id]
|
119
|
+
attributes[:name] = fields['name'] || fields[:name] || attributes[:name]
|
120
|
+
attributes[:color] = fields['color'] || fields[:color] || attributes[:color]
|
121
|
+
attributes[:board_id] = fields['idBoard'] || fields[:board_id] || attributes[:board_id]
|
122
|
+
attributes[:uses] = fields['uses'] if fields.has_key?('uses')
|
123
|
+
self
|
124
|
+
end
|
108
125
|
end
|
109
126
|
end
|