ruby-trello-czuger 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +182 -0
  3. data/lib/trello.rb +163 -0
  4. data/lib/trello/action.rb +68 -0
  5. data/lib/trello/association.rb +14 -0
  6. data/lib/trello/association_proxy.rb +42 -0
  7. data/lib/trello/attachment.rb +40 -0
  8. data/lib/trello/authorization.rb +187 -0
  9. data/lib/trello/basic_data.rb +132 -0
  10. data/lib/trello/board.rb +211 -0
  11. data/lib/trello/card.rb +467 -0
  12. data/lib/trello/checklist.rb +143 -0
  13. data/lib/trello/client.rb +120 -0
  14. data/lib/trello/comment.rb +62 -0
  15. data/lib/trello/configuration.rb +68 -0
  16. data/lib/trello/core_ext/array.rb +6 -0
  17. data/lib/trello/core_ext/hash.rb +6 -0
  18. data/lib/trello/core_ext/string.rb +6 -0
  19. data/lib/trello/cover_image.rb +8 -0
  20. data/lib/trello/has_actions.rb +9 -0
  21. data/lib/trello/item.rb +37 -0
  22. data/lib/trello/item_state.rb +30 -0
  23. data/lib/trello/json_utils.rb +64 -0
  24. data/lib/trello/label.rb +108 -0
  25. data/lib/trello/label_name.rb +31 -0
  26. data/lib/trello/list.rb +114 -0
  27. data/lib/trello/member.rb +112 -0
  28. data/lib/trello/multi_association.rb +12 -0
  29. data/lib/trello/net.rb +39 -0
  30. data/lib/trello/notification.rb +61 -0
  31. data/lib/trello/organization.rb +68 -0
  32. data/lib/trello/plugin_datum.rb +34 -0
  33. data/lib/trello/token.rb +37 -0
  34. data/lib/trello/webhook.rb +103 -0
  35. data/spec/action_spec.rb +149 -0
  36. data/spec/array_spec.rb +13 -0
  37. data/spec/association_spec.rb +26 -0
  38. data/spec/basic_auth_policy_spec.rb +51 -0
  39. data/spec/board_spec.rb +442 -0
  40. data/spec/card_spec.rb +822 -0
  41. data/spec/checklist_spec.rb +296 -0
  42. data/spec/client_spec.rb +257 -0
  43. data/spec/configuration_spec.rb +95 -0
  44. data/spec/hash_spec.rb +15 -0
  45. data/spec/integration/how_to_authorize_spec.rb +53 -0
  46. data/spec/integration/how_to_use_boards_spec.rb +48 -0
  47. data/spec/integration/integration_test.rb +40 -0
  48. data/spec/item_spec.rb +75 -0
  49. data/spec/json_utils_spec.rb +73 -0
  50. data/spec/label_spec.rb +205 -0
  51. data/spec/list_spec.rb +253 -0
  52. data/spec/member_spec.rb +159 -0
  53. data/spec/notification_spec.rb +143 -0
  54. data/spec/oauth_policy_spec.rb +160 -0
  55. data/spec/organization_spec.rb +71 -0
  56. data/spec/spec_helper.rb +435 -0
  57. data/spec/string_spec.rb +55 -0
  58. data/spec/token_spec.rb +89 -0
  59. data/spec/trello_spec.rb +134 -0
  60. data/spec/webhook_spec.rb +130 -0
  61. metadata +200 -0
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'trello/core_ext/array'
3
+
4
+ describe Array, '#jsoned_into' do
5
+ include Helpers
6
+
7
+ it "should convert an array of parsed json into cards" do
8
+ expected = cards_details.map do |card_details|
9
+ card_details.jsoned_into(Trello::Card)
10
+ end
11
+ expect(cards_details.jsoned_into(Trello::Card)).to eq(expected)
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Association do
5
+ include Helpers
6
+
7
+ let(:organization) { client.find(:organization, '4ee7e59ae582acdec8000291') }
8
+ let(:client) { Client.new(consumer_key: 'xxx') }
9
+
10
+ before do
11
+ allow(client)
12
+ .to receive(:get)
13
+ .with('/organizations/4ee7e59ae582acdec8000291', {})
14
+ .and_return organization_payload
15
+
16
+ allow(client)
17
+ .to receive(:get)
18
+ .with('/organizations/4ee7e59ae582acdec8000291/boards/all')
19
+ .and_return boards_payload
20
+ end
21
+
22
+ it 'should set the proper client for all associated boards of the organization' do
23
+ expect(organization.boards.first.client.consumer_key).to eq 'xxx'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ include Trello
4
+ include Trello::Authorization
5
+
6
+ describe BasicAuthPolicy do
7
+ before do
8
+ BasicAuthPolicy.developer_public_key = 'xxx'
9
+ BasicAuthPolicy.member_token = 'xxx'
10
+ end
11
+
12
+ it 'adds key and token query parameters' do
13
+ BasicAuthPolicy.developer_public_key = 'xxx_developer_public_key_xxx'
14
+ BasicAuthPolicy.member_token = 'xxx_member_token_xxx'
15
+
16
+ uri = Addressable::URI.parse('https://xxx/')
17
+
18
+ request = Request.new :get, uri
19
+
20
+ authorized_request = BasicAuthPolicy.authorize request
21
+
22
+ the_query_parameters = Addressable::URI.parse(authorized_request.uri).query_values
23
+
24
+ expect(the_query_parameters['key']).to eq 'xxx_developer_public_key_xxx'
25
+ expect(the_query_parameters['token']).to eq 'xxx_member_token_xxx'
26
+ end
27
+
28
+ it 'preserves other query parameters' do
29
+ uri = Addressable::URI.parse('https://xxx/?name=Phil')
30
+
31
+ request = Request.new :get, uri, {example_header: 'example_value'}
32
+
33
+ authorized_request = BasicAuthPolicy.authorize request
34
+
35
+ the_query_parameters = Addressable::URI.parse(authorized_request.uri).query_values
36
+
37
+ expect(the_query_parameters['name']).to eq 'Phil'
38
+ end
39
+
40
+ it 'preserves headers' do
41
+ uri = Addressable::URI.parse('https://xxx/')
42
+
43
+ request = Request.new :get, uri, {example_header: 'example_value'}
44
+
45
+ authorized_request = BasicAuthPolicy.authorize request
46
+
47
+ expect(authorized_request.headers).to eq request.headers
48
+ end
49
+
50
+ it 'does what when a query parameter already exists called key or token?'
51
+ end
@@ -0,0 +1,442 @@
1
+ require 'spec_helper'
2
+
3
+ module Trello
4
+ describe Board do
5
+ include Helpers
6
+
7
+ let(:board) { client.find(:board, 'abcdef123456789123456789') }
8
+ let(:client) { Client.new }
9
+ let(:member) { Member.new(user_payload) }
10
+
11
+ before do
12
+ allow(client)
13
+ .to receive(:get)
14
+ .with("/boards/abcdef123456789123456789", {})
15
+ .and_return JSON.generate(boards_details.first)
16
+ end
17
+
18
+ context "finding" do
19
+ let(:client) { Trello.client }
20
+
21
+ it "delegates to client#find" do
22
+ expect(client)
23
+ .to receive(:find)
24
+ .with(:board, 'abcdef123456789123456789', {})
25
+
26
+ Board.find('abcdef123456789123456789')
27
+ end
28
+
29
+ it "is equivalent to client#find" do
30
+ expect(Board.find('abcdef123456789123456789')).to eq(board)
31
+ end
32
+ end
33
+
34
+ context "self.all" do
35
+ let(:client) { Trello.client }
36
+
37
+ before do
38
+ allow(Member)
39
+ .to receive_message_chain(:find, :username)
40
+ .and_return "testuser"
41
+
42
+ allow(client)
43
+ .to receive(:get)
44
+ .with("/members/testuser/boards")
45
+ .and_return boards_payload
46
+ end
47
+
48
+ it "gets all boards" do
49
+ expect(Board.all.first).to eq Board.new(boards_details.first)
50
+ end
51
+ end
52
+
53
+ context "fields" do
54
+ it "gets an id" do
55
+ expect(board.id).to_not be_nil
56
+ end
57
+
58
+ it "gets a name" do
59
+ expect(board.name).to_not be_nil
60
+ end
61
+
62
+ it "gets the description" do
63
+ expect(board.description).to_not be_nil
64
+ end
65
+
66
+ it "knows if it is closed or open" do
67
+ expect(board).to_not be_closed
68
+ end
69
+
70
+ it "knows if it is starred or not" do
71
+ expect(board).to_not be_starred
72
+ end
73
+
74
+ it "gets its url" do
75
+ expect(board.url).to_not be_nil
76
+ end
77
+
78
+ it "gets its last_activity_date" do
79
+ expect(board.last_activity_date).to_not be_nil
80
+ end
81
+
82
+ it "gets a Time object for last_activity_date" do
83
+ expect(board.last_activity_date).to be_a(Time)
84
+ end
85
+ end
86
+
87
+ context "actions" do
88
+ before do
89
+ allow(client)
90
+ .to receive(:get)
91
+ .with("/boards/abcdef123456789123456789/actions", {filter: :all})
92
+ .and_return actions_payload
93
+ end
94
+
95
+ it "has a list of actions" do
96
+ expect(board.actions.count).to be > 0
97
+ end
98
+ end
99
+
100
+ context "cards" do
101
+ before do
102
+ allow(client)
103
+ .to receive(:get)
104
+ .with("/boards/abcdef123456789123456789/cards", {filter: :open})
105
+ .and_return cards_payload
106
+ end
107
+
108
+ it "gets its list of cards" do
109
+ expect(board.cards.count).to be > 0
110
+ end
111
+ end
112
+
113
+ context "labels" do
114
+ before do
115
+ allow(client)
116
+ .to receive(:get)
117
+ .with("/boards/abcdef123456789123456789/labels")
118
+ .and_return label_payload
119
+
120
+ allow(client)
121
+ .to receive(:get)
122
+ .with("/boards/abcdef123456789123456789/labelnames")
123
+ .and_return label_name_payload
124
+ end
125
+
126
+ it "gets the specific labels for the board" do
127
+ allow(client).to receive(:get).with("/boards/abcdef123456789123456789/labels", {:limit => 1000}).
128
+ and_return label_payload
129
+ labels = board.labels
130
+
131
+ expect(labels.count).to eq(4)
132
+ expect(labels[2].color).to eq('red')
133
+ expect(labels[2].id).to eq('cbcdef123456789123456789')
134
+ expect(labels[2].board_id).to eq('abcdef123456789123456789')
135
+ expect(labels[2].name).to eq('deploy')
136
+ expect(labels[2].uses).to eq(2)
137
+ expect(labels[3].color).to eq('blue')
138
+ expect(labels[3].id).to eq('dbcdef123456789123456789')
139
+ expect(labels[3].board_id).to eq('abcdef123456789123456789')
140
+ expect(labels[3].name).to eq('on hold')
141
+ expect(labels[3].uses).to eq(6)
142
+ end
143
+
144
+ it "passes the label limit" do
145
+ allow(client).to receive(:get).with("/boards/abcdef123456789123456789/labels", {:limit => 50}).
146
+ and_return label_payload
147
+ labels = board.labels(:limit => 50)
148
+ end
149
+ end
150
+
151
+ context "find_card" do
152
+ before do
153
+ allow(client)
154
+ .to receive(:get)
155
+ .with("/boards/abcdef123456789123456789/cards/1")
156
+ .and_return card_payload
157
+ end
158
+
159
+ it "gets a card" do
160
+ expect(board.find_card(1)).to be_a(Card)
161
+ end
162
+ end
163
+
164
+ context "add_member" do
165
+ before do
166
+ allow(client)
167
+ .to receive(:put)
168
+ end
169
+
170
+ it "adds a member to the board as a normal user (default)" do
171
+ expect(client)
172
+ .to receive(:put)
173
+ .with("/boards/abcdef123456789123456789/members/id", type: :normal)
174
+
175
+ board.add_member(member)
176
+ end
177
+
178
+ it "adds a member to the board as an admin" do
179
+ expect(client)
180
+ .to receive(:put)
181
+ .with("/boards/abcdef123456789123456789/members/id", type: :admin)
182
+
183
+ board.add_member(member, :admin)
184
+ end
185
+ end
186
+
187
+ context "remove_member" do
188
+ before do
189
+ allow(client)
190
+ .to receive(:delete)
191
+ end
192
+
193
+ it "removes a member from the board" do
194
+ expect(client)
195
+ .to receive(:delete)
196
+ .with("/boards/abcdef123456789123456789/members/id")
197
+
198
+ board.remove_member(member)
199
+ end
200
+ end
201
+
202
+ context "lists" do
203
+ before do
204
+ allow(client)
205
+ .to receive(:get)
206
+ .with("/boards/abcdef123456789123456789/lists", hash_including(filter: :open))
207
+ .and_return lists_payload
208
+ end
209
+
210
+ it "has a list of lists" do
211
+ expect(board).to be_has_lists
212
+ end
213
+ end
214
+
215
+ context "members" do
216
+ before do
217
+ allow(client)
218
+ .to receive(:get)
219
+ .with("/boards/abcdef123456789123456789/members", hash_including(filter: :all))
220
+ .and_return JSON.generate([user_details])
221
+ end
222
+
223
+ it "has a list of members" do
224
+ expect(board.members.count).to be > 0
225
+ end
226
+ end
227
+
228
+ context "checklists" do
229
+ before do
230
+ allow(client)
231
+ .to receive(:get)
232
+ .with("/boards/abcdef123456789123456789/checklists", {filter: :all})
233
+ .and_return checklists_payload
234
+ end
235
+
236
+ it "has a list of checklists" do
237
+ expect(board.checklists.count).to be > 0
238
+ end
239
+ end
240
+
241
+ context "organization" do
242
+ before do
243
+ allow(client)
244
+ .to receive(:get)
245
+ .with("/organizations/abcdef123456789123456789", {})
246
+ .and_return JSON.generate(orgs_details.first)
247
+ end
248
+
249
+ it "belongs to an organization" do
250
+ expect(board.organization).to_not be_nil
251
+ end
252
+ end
253
+
254
+ it "is not closed" do
255
+ expect(board).not_to be_closed
256
+ end
257
+
258
+ it "is not starred" do
259
+ expect(board).not_to be_starred
260
+ end
261
+
262
+ describe "#update_fields" do
263
+ it "does not set any fields when the fields argument is empty" do
264
+ expected = {
265
+ 'id' => "id",
266
+ 'name' => "name",
267
+ 'desc' => "desc",
268
+ 'closed' => false,
269
+ 'starred' => false,
270
+ 'url' => "url",
271
+ 'idOrganization' => "org_id"
272
+ }
273
+
274
+ board = Board.new(expected)
275
+ board.client = client
276
+
277
+ board.update_fields({})
278
+
279
+ expected.each_pair do |key, value|
280
+ if board.respond_to?(key)
281
+ expect(board.send(key)).to eq value
282
+ end
283
+ end
284
+
285
+ expect(board.description).to eq expected['desc']
286
+ expect(board.organization_id).to eq expected['idOrganization']
287
+ end
288
+
289
+ it "initializes all fields from response-like formatted hash" do
290
+ board_details = boards_details.first
291
+ board = Board.new(board_details)
292
+ expect(board.id).to eq board_details['id']
293
+ expect(board.name).to eq board_details['name']
294
+ expect(board.description).to eq board_details['desc']
295
+ expect(board.closed).to eq board_details['closed']
296
+ expect(board.starred).to eq board_details['starred']
297
+ expect(board.organization_id).to eq board_details['idOrganization']
298
+ expect(board.url).to eq board_details['url']
299
+ expect(board.last_activity_date).to eq board_details['dateLastActivity']
300
+ end
301
+
302
+ it "initializes all fields from options-like formatted hash" do
303
+ board_details = boards_details[1]
304
+ board = Board.new(board_details)
305
+ expect(board.name).to eq board_details[:name]
306
+ expect(board.description).to eq board_details[:desc]
307
+ expect(board.closed).to eq board_details[:closed]
308
+ expect(board.starred).to eq board_details[:starred]
309
+ expect(board.organization_id).to eq board_details[:organization_id]
310
+ end
311
+ end
312
+
313
+ describe "#save" do
314
+ let(:client) { Trello.client }
315
+
316
+ let(:any_board_json) do
317
+ JSON.generate(boards_details.first)
318
+ end
319
+
320
+ before do
321
+ allow(client)
322
+ .to receive(:put)
323
+ end
324
+
325
+ it "cannot currently save a new instance" do
326
+ expect(client).to_not receive(:put)
327
+ expect {
328
+ Board.new.save
329
+ }.to raise_error(Trello::ConfigurationError)
330
+ end
331
+
332
+ it "puts all fields except id" do
333
+ expected_fields = %w{ name description closed starred idOrganization}.map { |s| s.to_sym }
334
+
335
+ expect(client).to receive(:put) do |anything, body|
336
+ expect(body.keys).to match expected_fields
337
+ any_board_json
338
+ end
339
+
340
+ Board.new('id' => "xxx").save
341
+ end
342
+
343
+ it "mutates the current instance" do
344
+ allow(client)
345
+ .to receive(:put)
346
+ .and_return any_board_json
347
+
348
+ board = Board.new 'id' => "xxx"
349
+ expect(board.save).to eq board
350
+ end
351
+
352
+ it "uses the correct resource" do
353
+ expected_resource_id = "xxx_board_id_xxx"
354
+
355
+ expect(client).to receive(:put) do |path, anything|
356
+ expect(path).to match(/#{expected_resource_id}\/\z/)
357
+ any_board_json
358
+ end
359
+
360
+ Board.new('id' => expected_resource_id).save
361
+ end
362
+
363
+ it "saves OR updates depending on whether or not it has an id set"
364
+ end
365
+
366
+ describe '#update!' do
367
+ let(:client) { Trello.client }
368
+
369
+ let(:any_board_json) do
370
+ JSON.generate(boards_details.first)
371
+ end
372
+
373
+ it "puts basic attributes" do
374
+ board = Board.new 'id' => "board_id"
375
+
376
+ board.name = "new name"
377
+ board.description = "new description"
378
+ board.closed = true
379
+ board.starred = true
380
+
381
+ expect(client)
382
+ .to receive(:put)
383
+ .with("/boards/#{board.id}/", {
384
+ name: "new name",
385
+ description: "new description",
386
+ closed: true,
387
+ starred: true,
388
+ idOrganization: nil })
389
+ .and_return any_board_json
390
+
391
+ board.update!
392
+ end
393
+ end
394
+
395
+ describe "Repository" do
396
+ include Helpers
397
+
398
+ let(:client) { Trello.client }
399
+
400
+ let(:any_board_json) do
401
+ JSON.generate(boards_details.first)
402
+ end
403
+
404
+ before do
405
+ allow(client)
406
+ .to receive(:post)
407
+ end
408
+
409
+ it "creates a new board with whatever attributes are supplied " do
410
+ expected_attributes = { name: "Any new board name", description: "Any new board desription" }
411
+ sent_attributes = { name: expected_attributes[:name], desc: expected_attributes[:description] }
412
+
413
+ expect(client)
414
+ .to receive(:post)
415
+ .with("/boards", sent_attributes)
416
+ .and_return any_board_json
417
+
418
+ Board.create expected_attributes
419
+ end
420
+
421
+ it "posts to the boards collection" do
422
+ expect(client)
423
+ .to receive(:post)
424
+ .with("/boards", anything)
425
+ .and_return any_board_json
426
+
427
+ Board.create xxx: ""
428
+ end
429
+
430
+ it "returns a board" do
431
+ allow(client)
432
+ .to receive(:post)
433
+ .with("/boards", anything)
434
+ .and_return any_board_json
435
+
436
+ expect(Board.create(xxx: "")).to be_a Board
437
+ end
438
+
439
+ it "at least name is required"
440
+ end
441
+ end
442
+ end