ruby-trello 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45ec7bdcb469bf63f80f7291c787a4f4a8ec653f
4
- data.tar.gz: cc4a463550cfe8036d1c4e4cef421389dd6535f8
3
+ metadata.gz: 129649aadb5faffaa3dd64361d4eeffc6f46dd8d
4
+ data.tar.gz: 2ec4ff6b8555542d5006e24557c776cf28aca1fa
5
5
  SHA512:
6
- metadata.gz: fdd6a111315be371b94c6c84cd57742faea4519556136b2db601baed79ef46c670afde112408a1668563c4fdd513fc319221b72721b50f0103e240e69c6d5cfd
7
- data.tar.gz: 002b5cca51dd9640a148968a685c25da8b7b627c9446c33e6cb87c4eadc800a5566a14aed9a4205931dc90881cc63093548865894dfb9860b3dca3b59ca02c29
6
+ metadata.gz: 3b3388b34a9830bf26cb48a705b45bb0e67a8c4314108b2013a389cf71ae607aba2a7bdde48cdf8a095f126c01eacf545f15177cc39a3e3c99b59d46a2086071
7
+ data.tar.gz: 7c5dc7a800406537edbbaab5f79eab36f11f73e84137562125775b8173896887d0762ecc3fb27f101e70d5ddb360e5a6ba9c35af8913a32d62f4c80bacbdfa56
data/README.md CHANGED
@@ -24,7 +24,7 @@ illustrate that future versions may include ruby 1.9.3+ specific features.
24
24
 
25
25
  ## Configuration
26
26
 
27
- Basic authorization:
27
+ ####Basic authorization:
28
28
 
29
29
  1. Get your API keys from [trello.com/app-key](https://trello.com/app-key).
30
30
  2. Visit the URL [trello.com/1/authorize], with the following GET parameters:
@@ -32,8 +32,9 @@ Basic authorization:
32
32
  - `response_type`: "token"
33
33
  - `expiration`: "never" if you don't want your token to ever expire. If you leave this blank,
34
34
  your generated token will expire after 30 days.
35
+ - `scope`: "read,write" (optional) by default the API key will only give read access. You must set the scope to "read,write" if you would like ruby-trello to have permissions to create and delete.
35
36
  - The URL will look like this:
36
- `https://trello.com/1/authorize?key=YOURAPIKEY&response_type=token&expiration=never`
37
+ `https://trello.com/1/authorize?key=YOURAPIKEY&response_type=token&expiration=never&scope=read,write`
37
38
  3. You should see a page asking you to authorize your Trello application. Click "allow" and you should see a second page with a long alphanumeric string. This is your member token.
38
39
 
39
40
  ```ruby
@@ -45,7 +46,7 @@ Trello.configure do |config|
45
46
  end
46
47
  ```
47
48
 
48
- 2-legged OAuth authorization
49
+ ####2-legged OAuth authorization
49
50
 
50
51
  ```ruby
51
52
  Trello.configure do |config|
@@ -56,7 +57,7 @@ Trello.configure do |config|
56
57
  end
57
58
  ```
58
59
 
59
- 3-legged OAuth authorization
60
+ ####3-legged OAuth authorization
60
61
 
61
62
  ```ruby
62
63
  Trello.configure do |config|
@@ -123,6 +124,6 @@ of refactoring and functionality to be deserving of a beer and this special than
123
124
 
124
125
  Several ways you can contribute. Documentation, code, tests, feature requests, bug reports.
125
126
 
126
- We develop ruby-trello using [Trello itself](https://trello.com/board/ruby-trello/4f092b2ee23cb6fe6d1aaabd).
127
+ If you submit a pull request that's accepted, you'll be given commit access to this repository.
127
128
 
128
129
  Please see the `CONTRIBUTING.md` file for more information.
data/lib/trello/board.rb CHANGED
@@ -18,7 +18,7 @@ module Trello
18
18
  # @return [Hash] A 24-character hex string
19
19
  class Board < BasicData
20
20
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs,
21
- readonly: [ :id, :url, :prefs ]
21
+ readonly: [ :id, :url ]
22
22
  validates_presence_of :id, :name
23
23
  validates_length_of :name, in: 1..16384
24
24
  validates_length_of :description, maximum: 16384
@@ -154,13 +154,11 @@ module Trello
154
154
  # Returns a reference to the organization this board belongs to.
155
155
  one :organization, path: :organizations, using: :organization_id
156
156
 
157
- def labels names=true
158
- if names
159
- labels = client.get("/boards/#{id}/labelnames").json_into(LabelName)
160
- else
161
- labels = client.get("/boards/#{id}/labels").json_into(Label)
162
- end
163
- MultiAssociation.new(self, labels).proxy
157
+ many :labels
158
+
159
+ def label_names
160
+ label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName)
161
+ MultiAssociation.new(self, label_names).proxy
164
162
  end
165
163
 
166
164
  # :nodoc:
data/lib/trello/card.rb CHANGED
@@ -177,7 +177,8 @@ module Trello
177
177
  MultiAssociation.new(self, states).proxy
178
178
  end
179
179
 
180
-
180
+ many :labels
181
+
181
182
  # Returns a reference to the list this card is currently in.
182
183
  one :list, path: :lists, using: :list_id
183
184
 
@@ -207,7 +208,8 @@ module Trello
207
208
  idList: list_id,
208
209
  idMembers: member_ids,
209
210
  labels: card_labels,
210
- pos: pos
211
+ pos: pos,
212
+ due: due
211
213
  }).json_into(self)
212
214
  end
213
215
 
@@ -313,39 +315,23 @@ module Trello
313
315
  def remove_member(member)
314
316
  client.delete("/cards/#{id}/members/#{member.id}")
315
317
  end
316
-
317
- # Retrieve a list of labels
318
- def labels
319
- labels = client.get("/cards/#{id}/labels").json_into(Label)
320
- MultiAssociation.new(self, labels).proxy
321
- end
322
318
 
323
319
  # Add a label
324
- def add_label(value)
325
- if value.is_a? String
326
- colour = value
327
- unless Label.label_colours.include? colour
328
- errors.add(:label, "colour '#{colour}' does not exist")
329
- return Trello.logger.warn "The label colour '#{colour}' does not exist."
330
- end
331
- client.post("/cards/#{id}/labels", { value: colour })
332
- elsif value.is_a? Label
333
- client.post("/cards/#{id}/idLabels", {value: value.id})
320
+ def add_label(label)
321
+ unless label.valid?
322
+ errors.add(:label, "is not valid.")
323
+ return Trello.logger.warn "Label is not valid." unless label.valid?
334
324
  end
325
+ client.post("/cards/#{id}/idLabels", {value: label.id})
335
326
  end
336
327
 
337
328
  # Remove a label
338
- def remove_label(value)
339
- if value.is_a? String
340
- colour = value
341
- unless Label.label_colours.include? colour
342
- errors.add(:label, "colour '#{colour}' does not exist")
343
- return Trello.logger.warn "The label colour '#{colour}' does not exist." unless Label.label_colours.include? colour
329
+ def remove_label(label)
330
+ unless label.valid?
331
+ errors.add(:label, "is not valid.")
332
+ return Trello.logger.warn "Label is not valid." unless label.valid?
344
333
  end
345
- client.delete("/cards/#{id}/labels/#{colour}")
346
- elsif value.is_a? Label
347
- client.delete("/cards/#{id}/idLabels/#{value.id}")
348
- end
334
+ client.delete("/cards/#{id}/idLabels/#{label.id}")
349
335
  end
350
336
 
351
337
  # Add an attachment to this card
@@ -112,5 +112,19 @@ module Trello
112
112
  def delete
113
113
  client.delete("/checklists/#{id}")
114
114
  end
115
+
116
+ # Copy a checklist (i.e., same attributes, items, etc.)
117
+ def copy
118
+ checklist_copy = self.class.create(name: self.name, board_id: self.board_id)
119
+ copy_items_to(checklist_copy)
120
+ return checklist_copy
121
+ end
122
+
123
+ private
124
+ def copy_items_to(another_checklist)
125
+ items.each do |item|
126
+ another_checklist.add_item(item.name, item.complete?)
127
+ end
128
+ end
115
129
  end
116
130
  end
data/lib/trello/item.rb CHANGED
@@ -27,5 +27,9 @@ module Trello
27
27
  attributes[:pos] = fields['pos']
28
28
  self
29
29
  end
30
+
31
+ def complete?
32
+ state == "complete"
33
+ end
30
34
  end
31
35
  end
data/lib/trello/label.rb CHANGED
@@ -11,7 +11,7 @@ module Trello
11
11
  readonly: [ :id, :uses, :board_id ]
12
12
  validates_presence_of :id, :uses, :board_id, :name
13
13
  validates_length_of :name, in: 1..16384
14
-
14
+
15
15
  SYMBOL_TO_STRING = {
16
16
  id: 'id',
17
17
  name: 'name',
@@ -26,7 +26,7 @@ module Trello
26
26
  client.find(:label, id, params)
27
27
  end
28
28
 
29
- # Create a new card and save it on Trello.
29
+ # Create a new label and save it on Trello.
30
30
  def create(options)
31
31
  client.create(:label,
32
32
  'name' => options[:name],
@@ -98,7 +98,7 @@ module Trello
98
98
  client.put("/labels/#{id}", payload)
99
99
  end
100
100
 
101
- # Delete this card
101
+ # Delete this label
102
102
  def delete
103
103
  client.delete("/labels/#{id}")
104
104
  end
data/lib/trello/list.rb CHANGED
@@ -30,7 +30,8 @@ module Trello
30
30
  def create(options)
31
31
  client.create(:list,
32
32
  'name' => options[:name],
33
- 'idBoard' => options[:board_id])
33
+ 'idBoard' => options[:board_id],
34
+ 'pos' => options[:pos])
34
35
  end
35
36
  end
36
37
 
@@ -53,14 +54,16 @@ module Trello
53
54
  client.post("/lists", {
54
55
  name: name,
55
56
  closed: closed || false,
56
- idBoard: board_id
57
+ idBoard: board_id,
58
+ pos: pos
57
59
  }).json_into(self)
58
60
  end
59
61
 
60
62
  def update!
61
63
  client.put("/lists/#{id}", {
62
64
  name: name,
63
- closed: closed
65
+ closed: closed,
66
+ pos: pos
64
67
  })
65
68
  end
66
69
 
@@ -88,6 +91,13 @@ module Trello
88
91
  # :filter => [ :none, :open, :closed, :all ] # default :open
89
92
  many :cards, filter: :open
90
93
 
94
+ def move_all_cards(other_list)
95
+ client.post("/lists/#{id}/moveAllCards", {
96
+ idBoard: other_list.board_id,
97
+ idList: other_list.id
98
+ })
99
+ end
100
+
91
101
  # :nodoc:
92
102
  def request_prefix
93
103
  "/lists/#{id}"
@@ -12,8 +12,10 @@ module Trello
12
12
  # @!attribute [r] url
13
13
  # @return [String]
14
14
  class Organization < BasicData
15
- register_attributes :id, :name, :display_name, :description, :url,
16
- readonly: [ :id, :name, :display_name, :description, :url ]
15
+ register_attributes :id, :name, :display_name, :description, :url, :invited,
16
+ :website, :logo_hash, :billable_member_count, :active_billable_member_count,
17
+ readonly: [ :id, :name, :display_name, :description, :url, :invited,
18
+ :website, :logo_hash, :billable_member_count, :active_billable_member_count ]
17
19
  validates_presence_of :id, :name
18
20
 
19
21
  include HasActions
@@ -30,11 +32,16 @@ module Trello
30
32
  # Supply a hash of string keyed data retrieved from the Trello API representing
31
33
  # an Organization.
32
34
  def update_fields(fields)
33
- attributes[:id] = fields['id']
34
- attributes[:name] = fields['name']
35
- attributes[:display_name] = fields['displayName']
36
- attributes[:description] = fields['description']
37
- attributes[:url] = fields['url']
35
+ attributes[:id] = fields['id']
36
+ attributes[:name] = fields['name']
37
+ attributes[:display_name] = fields['displayName']
38
+ attributes[:description] = fields['desc']
39
+ attributes[:url] = fields['url']
40
+ attributes[:invited] = fields['invited']
41
+ attributes[:website] = fields['website']
42
+ attributes[:logo_hash] = fields['logoHash']
43
+ attributes[:billable_member_count] = fields['billableMemberCount']
44
+ attributes[:active_billable_member_count] = fields['activeBillableMemberCount']
38
45
  self
39
46
  end
40
47
 
data/spec/action_spec.rb CHANGED
@@ -4,33 +4,44 @@ module Trello
4
4
  describe Action do
5
5
  include Helpers
6
6
 
7
- let(:action) { client.find(:action, '4ee2482134a81a757a08af47') }
8
- let(:client) { Client.new }
9
-
10
- before(:each) do
11
- client.stub(:get).with('/actions/4ee2482134a81a757a08af47', {}).
12
- and_return JSON.generate(actions_details.first)
7
+ let(:client) { Client.new }
8
+ let(:action) { client.find(:action, '4ee2482134a81a757a08af47') }
9
+
10
+ before do
11
+ allow(client)
12
+ .to receive(:get)
13
+ .with('/actions/4ee2482134a81a757a08af47', {})
14
+ .and_return JSON.generate(actions_details.first)
13
15
  end
14
16
 
15
17
  context 'finding' do
16
18
  let(:client) { Trello.client }
17
19
 
18
20
  it 'delegates to Trello.client#find' do
19
- client.should_receive(:find).with(:action, '4ee2482134a81a757a08af47', {})
21
+ expect(client)
22
+ .to receive(:find)
23
+ .with(:action, '4ee2482134a81a757a08af47', {})
24
+
20
25
  Action.find('4ee2482134a81a757a08af47')
21
26
  end
22
27
 
23
- it 'is equivalent to client#find' do
24
- Action.find('4ee2482134a81a757a08af47').should eq(action)
28
+ it do
29
+ expect(Action.find('4ee2482134a81a757a08af47')).to eq(action)
25
30
  end
26
31
  end
27
32
 
28
33
  context 'search' do
29
34
  let(:client) { Trello.client }
35
+ let(:payload) { JSON.generate({ "cards" => cards_details }) }
36
+
37
+ it "searches and get back a card object" do
38
+ expect(client)
39
+ .to receive(:get)
40
+ .with("/search/", { query: "something"})
41
+ .and_return payload
30
42
 
31
- it "should search and get back a card object" do
32
- client.should_receive(:get).with("/search/", { query: "something"}).and_return(JSON.generate({ "cards" => cards_details }))
33
- Action.search("something").should eq({ "cards" => cards_details.jsoned_into(Card) })
43
+ expect(Action.search("something"))
44
+ .to eq({ "cards" => cards_details.jsoned_into(Card) })
34
45
  end
35
46
  end
36
47
 
@@ -38,54 +49,79 @@ module Trello
38
49
  let(:detail) { actions_details.first }
39
50
 
40
51
  it 'gets its id' do
41
- action.id.should == detail['id']
52
+ expect(action.id).to eq detail['id']
42
53
  end
43
54
 
44
55
  it 'gets its type' do
45
- action.type.should == detail['type']
56
+ expect(action.type).to eq detail['type']
46
57
  end
47
58
 
48
59
  it 'has the same data' do
49
- action.data.should == detail['data']
60
+ expect(action.data).to eq detail['data']
50
61
  end
51
62
 
52
63
  it 'gets the date' do
53
- action.date.utc.iso8601.should == detail['date']
64
+ expect(action.date.utc.iso8601).to eq detail['date']
54
65
  end
55
66
  end
56
67
 
57
68
  context 'boards' do
58
- it 'has a board' do
59
- client.stub(:get).with('/actions/4ee2482134a81a757a08af47/board').
60
- and_return JSON.generate(boards_details.first)
69
+ let(:payload) { JSON.generate(boards_details.first) }
70
+
71
+ before do
72
+ allow(client)
73
+ .to receive(:get)
74
+ .with('/actions/4ee2482134a81a757a08af47/board')
75
+ .and_return payload
76
+ end
61
77
 
62
- action.board.should_not be_nil
78
+ it 'has a board' do
79
+ expect(action.board).to_not be_nil
63
80
  end
64
81
  end
65
82
 
83
+
66
84
  context 'card' do
67
- it 'has a card' do
68
- client.stub(:get).with('/actions/4ee2482134a81a757a08af47/card').
69
- and_return JSON.generate(cards_details.first)
85
+ let(:payload) { JSON.generate(cards_details.first) }
86
+
87
+ before do
88
+ allow(client)
89
+ .to receive(:get)
90
+ .with('/actions/4ee2482134a81a757a08af47/card')
91
+ .and_return payload
92
+ end
70
93
 
71
- action.card.should_not be_nil
94
+ it 'has a card' do
95
+ expect(action.card).to_not be_nil
72
96
  end
73
97
  end
74
98
 
75
99
  context 'list' do
76
- it 'has a list of lists' do
77
- client.stub(:get).with('/actions/4ee2482134a81a757a08af47/list').
78
- and_return JSON.generate(lists_details.first)
100
+ let(:payload) { JSON.generate(lists_details.first) }
101
+
102
+ before do
103
+ allow(client)
104
+ .to receive(:get)
105
+ .with('/actions/4ee2482134a81a757a08af47/list')
106
+ .and_return payload
107
+ end
79
108
 
80
- action.list.should_not be_nil
109
+ it 'has a list of lists' do
110
+ expect(action.list).to_not be_nil
81
111
  end
82
112
  end
83
113
 
84
114
  context 'member creator' do
85
- it 'knows its member creator' do
86
- client.stub(:get).with('/members/abcdef123456789123456789', {}).and_return user_payload
87
115
 
88
- action.member_creator.should_not be_nil
116
+ before do
117
+ allow(client)
118
+ .to receive(:get)
119
+ .with('/members/abcdef123456789123456789', {})
120
+ .and_return user_payload
121
+ end
122
+
123
+ it 'knows its member creator' do
124
+ expect(action.member_creator).to_not be_nil
89
125
  end
90
126
  end
91
127
  end