ruby-trello 1.1.3 → 1.2.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 +3 -1
- data/lib/trello/action.rb +17 -5
- data/lib/trello/attachment.rb +15 -0
- data/lib/trello/authorization.rb +9 -9
- data/lib/trello/basic_data.rb +2 -2
- data/lib/trello/board.rb +90 -18
- data/lib/trello/card.rb +127 -18
- data/lib/trello/checklist.rb +29 -8
- data/lib/trello/configuration.rb +8 -8
- data/lib/trello/has_actions.rb +1 -1
- data/lib/trello/item.rb +13 -2
- data/lib/trello/item_state.rb +8 -1
- data/lib/trello/label.rb +5 -0
- data/lib/trello/label_name.rb +8 -3
- data/lib/trello/list.rb +23 -9
- data/lib/trello/member.rb +26 -9
- data/lib/trello/net.rb +5 -5
- data/lib/trello/notification.rb +15 -2
- data/lib/trello/organization.rb +12 -1
- data/lib/trello/token.rb +13 -2
- data/lib/trello/webhook.rb +40 -12
- data/spec/association_spec.rb +5 -5
- data/spec/basic_auth_policy_spec.rb +2 -2
- data/spec/board_spec.rb +45 -14
- data/spec/card_spec.rb +29 -29
- data/spec/checklist_spec.rb +16 -16
- data/spec/client_spec.rb +14 -14
- data/spec/configuration_spec.rb +25 -25
- data/spec/integration/how_to_authorize_spec.rb +5 -5
- data/spec/integration/how_to_use_boards_spec.rb +5 -5
- data/spec/list_spec.rb +10 -10
- data/spec/member_spec.rb +7 -7
- data/spec/oauth_policy_spec.rb +4 -4
- data/spec/organization_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/token_spec.rb +1 -1
- data/spec/webhook_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 260b90a4f5cc53cb0c695edb040c75144a24a2f0
|
4
|
+
data.tar.gz: 1b6e24750bb32ae29d798912b43a60e98ece7088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 913d7972b22fce3998ea166fc1dc94c8d4e699ef2f1b2b686fd585fb951b430769b74dbb8d3e2d90bd3e99791da8b5018f15839bbf79a636917e52fbb1d492c6
|
7
|
+
data.tar.gz: f68c3097b8e2c8cf043587b98aa7559b8aeb14c35891bea11de1edab13cf6e04be0adaf48df7dd0db4be4afb17211fd21cc5e865105435c5fd139f1fc6ac18fd
|
data/README.md
CHANGED
@@ -26,12 +26,14 @@ illustrate that future versions may include ruby 1.9.3+ specific features.
|
|
26
26
|
|
27
27
|
Basic authorization:
|
28
28
|
|
29
|
-
1. Get your API keys from [trello.com/app-key](https://trello.com/app-key).
|
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:
|
31
31
|
- `key`: the API key you got in step 1.
|
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
|
+
- The URL will look like this:
|
36
|
+
`https://trello.com/1/authorize?key=YOURAPIKEY&response_type=token&expiration=never`
|
35
37
|
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.
|
36
38
|
|
37
39
|
```ruby
|
data/lib/trello/action.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
module Trello
|
2
2
|
# Action represents some event that occurred. For instance, when a card is created.
|
3
|
+
#
|
4
|
+
# @!attribute [r] id
|
5
|
+
# @return [String]
|
6
|
+
# @!attribute [r] type
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute [r] data
|
9
|
+
# @return [Hash]
|
10
|
+
# @!attribute [r] date
|
11
|
+
# @return [Datetime]
|
12
|
+
# @!attribute [r] member_creator_id
|
13
|
+
# @return [String]
|
14
|
+
# @!attribute [r] member_participant
|
15
|
+
# @return [Object]
|
3
16
|
class Action < BasicData
|
4
17
|
register_attributes :id, :type, :data, :date, :member_creator_id, :member_participant,
|
5
|
-
:
|
18
|
+
readonly: [ :id, :type, :data, :date, :member_creator_id, :member_participant ]
|
6
19
|
validates_presence_of :id, :type, :date, :member_creator_id
|
7
20
|
|
8
21
|
class << self
|
@@ -13,9 +26,8 @@ module Trello
|
|
13
26
|
|
14
27
|
def search(query, opts={})
|
15
28
|
response = client.get("/search/", { query: query }.merge(opts))
|
16
|
-
|
17
|
-
res.merge
|
18
|
-
res
|
29
|
+
JSON.parse(response).except("options").inject({}) do |res, key|
|
30
|
+
res.merge({ key.first => key.last.jsoned_into("Trello::#{key.first.singularize.capitalize}".constantize) })
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
@@ -50,6 +62,6 @@ module Trello
|
|
50
62
|
end
|
51
63
|
|
52
64
|
# Returns the member who created the action.
|
53
|
-
one :member_creator, :
|
65
|
+
one :member_creator, via: Member, path: :members, using: :member_creator_id
|
54
66
|
end
|
55
67
|
end
|
data/lib/trello/attachment.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
module Trello
|
2
2
|
# A file or url that is linked to a Trello card
|
3
|
+
#
|
4
|
+
# @!attribute id
|
5
|
+
# @return [String]
|
6
|
+
# @!attribute name
|
7
|
+
# @return [String]
|
8
|
+
# @!attribute url
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute bytes
|
11
|
+
# @return [Fixnum]
|
12
|
+
# @!attribute date
|
13
|
+
# @return [Datetime]
|
14
|
+
# @!attribute is_upload
|
15
|
+
# @return [Boolean]
|
16
|
+
# @!attribute mime_type
|
17
|
+
# @return [String]
|
3
18
|
class Attachment < BasicData
|
4
19
|
register_attributes :name, :id, :url, :bytes, :member_id, :date, :is_upload, :mime_type
|
5
20
|
# Update the fields of an attachment.
|
data/lib/trello/authorization.rb
CHANGED
@@ -31,7 +31,7 @@ module Trello
|
|
31
31
|
def authorize(request)
|
32
32
|
the_uri = Addressable::URI.parse(request.uri)
|
33
33
|
existing_values = the_uri.query_values.nil? ? {} : the_uri.query_values
|
34
|
-
new_values = { :
|
34
|
+
new_values = { key: @developer_public_key, token: @member_token }
|
35
35
|
the_uri.query_values = new_values.merge existing_values
|
36
36
|
|
37
37
|
Request.new request.verb, the_uri, request.headers, request.body
|
@@ -100,8 +100,8 @@ module Trello
|
|
100
100
|
request.headers = {"Authorization" => get_auth_header(request.uri, :get)}
|
101
101
|
request
|
102
102
|
else
|
103
|
-
consumer(:
|
104
|
-
request_token = consumer.get_request_token(:
|
103
|
+
consumer(return_url: return_url, callback_method: :postMessage)
|
104
|
+
request_token = consumer.get_request_token(oauth_callback: return_url)
|
105
105
|
callback.call request_token
|
106
106
|
return nil
|
107
107
|
end
|
@@ -151,12 +151,12 @@ module Trello
|
|
151
151
|
|
152
152
|
def consumer_params(params = {})
|
153
153
|
{
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
154
|
+
scheme: :header,
|
155
|
+
scope: 'read,write,account',
|
156
|
+
http_method: :get,
|
157
|
+
request_token_path: "https://trello.com/1/OAuthGetRequestToken",
|
158
|
+
authorize_path: "https://trello.com/1/OAuthAuthorizeToken",
|
159
|
+
access_token_path: "https://trello.com/1/OAuthGetAccessToken"
|
160
160
|
}.merge!(params)
|
161
161
|
end
|
162
162
|
|
data/lib/trello/basic_data.rb
CHANGED
@@ -44,7 +44,7 @@ module Trello
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.register_attributes(*names)
|
47
|
-
options = { :
|
47
|
+
options = { readonly: [] }
|
48
48
|
options.merge!(names.pop) if names.last.kind_of? Hash
|
49
49
|
|
50
50
|
# Defines the attribute getter and setters.
|
@@ -102,7 +102,7 @@ module Trello
|
|
102
102
|
Trello.client
|
103
103
|
end
|
104
104
|
|
105
|
-
register_attributes :id, :
|
105
|
+
register_attributes :id, readonly: [ :id ]
|
106
106
|
|
107
107
|
attr_writer :client
|
108
108
|
|
data/lib/trello/board.rb
CHANGED
@@ -1,16 +1,40 @@
|
|
1
1
|
module Trello
|
2
|
+
|
3
|
+
# A board on Trello
|
4
|
+
#
|
5
|
+
# @!attribute [r] id
|
6
|
+
# @return [String]
|
7
|
+
# @!attribute [r] name
|
8
|
+
# @return [String]
|
9
|
+
# @!attribute [rw] description
|
10
|
+
# @return [String]
|
11
|
+
# @!attribute [rw] closed
|
12
|
+
# @return [Boolean]
|
13
|
+
# @!attribute [r] url
|
14
|
+
# @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
|
2
19
|
class Board < BasicData
|
3
|
-
register_attributes :id, :name, :description, :closed, :url, :organization_id, :prefs,
|
4
|
-
:
|
20
|
+
register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs,
|
21
|
+
readonly: [ :id, :url, :prefs ]
|
5
22
|
validates_presence_of :id, :name
|
6
|
-
validates_length_of :name, :
|
7
|
-
validates_length_of :description, :
|
23
|
+
validates_length_of :name, in: 1..16384
|
24
|
+
validates_length_of :description, maximum: 16384
|
8
25
|
|
9
26
|
include HasActions
|
10
27
|
|
11
28
|
class << self
|
12
29
|
# Finds a board.
|
13
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
|
+
#
|
14
38
|
# @return [Trello::Board]
|
15
39
|
def find(id, params = {})
|
16
40
|
client.find(:board, id, params)
|
@@ -20,8 +44,10 @@ module Trello
|
|
20
44
|
data = {
|
21
45
|
'name' => fields[:name],
|
22
46
|
'desc' => fields[:description],
|
23
|
-
'closed' => fields[:closed] || false
|
47
|
+
'closed' => fields[:closed] || false,
|
48
|
+
'starred' => fields[:starred] || false }
|
24
49
|
data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id]
|
50
|
+
data.merge!('prefs' => fields[:prefs]) if fields[:prefs]
|
25
51
|
client.create(:board, data)
|
26
52
|
end
|
27
53
|
|
@@ -34,9 +60,10 @@ module Trello
|
|
34
60
|
def save
|
35
61
|
return update! if id
|
36
62
|
|
37
|
-
fields = { :
|
38
|
-
fields.merge!(:
|
39
|
-
fields.merge!(:
|
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)
|
40
67
|
|
41
68
|
client.post("/boards", fields).json_into(self)
|
42
69
|
end
|
@@ -47,12 +74,16 @@ module Trello
|
|
47
74
|
@previously_changed = changes
|
48
75
|
@changed_attributes.clear
|
49
76
|
|
50
|
-
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
|
77
|
+
fields = {
|
78
|
+
name: attributes[:name],
|
79
|
+
description: attributes[:description],
|
80
|
+
closed: attributes[:closed],
|
81
|
+
starred: attributes[:starred],
|
82
|
+
idOrganization: attributes[:organization_id]
|
83
|
+
}
|
84
|
+
fields.merge!(flat_prefs)
|
85
|
+
|
86
|
+
client.put("/boards/#{self.id}/", fields).json_into(self)
|
56
87
|
end
|
57
88
|
|
58
89
|
def update_fields(fields)
|
@@ -60,6 +91,7 @@ module Trello
|
|
60
91
|
attributes[:name] = fields['name'] if fields['name']
|
61
92
|
attributes[:description] = fields['desc'] if fields['desc']
|
62
93
|
attributes[:closed] = fields['closed'] if fields.has_key?('closed')
|
94
|
+
attributes[:starred] = fields['starred'] if fields.has_key?('starred')
|
63
95
|
attributes[:url] = fields['url'] if fields['url']
|
64
96
|
attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization']
|
65
97
|
attributes[:prefs] = fields['prefs'] || {}
|
@@ -71,6 +103,11 @@ module Trello
|
|
71
103
|
attributes[:closed]
|
72
104
|
end
|
73
105
|
|
106
|
+
# @return [Boolean]
|
107
|
+
def starred?
|
108
|
+
attributes[:starred]
|
109
|
+
end
|
110
|
+
|
74
111
|
# @return [Boolean]
|
75
112
|
def has_lists?
|
76
113
|
lists.size > 0
|
@@ -82,29 +119,40 @@ module Trello
|
|
82
119
|
client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card)
|
83
120
|
end
|
84
121
|
|
122
|
+
# Add a member to this Board.
|
123
|
+
# type => [ :admin, :normal, :observer ]
|
124
|
+
def add_member(member, type = :normal)
|
125
|
+
client.put("/boards/#{self.id}/members/#{member.id}", { type: type })
|
126
|
+
end
|
127
|
+
|
128
|
+
# Remove a member of this Board.
|
129
|
+
def remove_member(member)
|
130
|
+
client.delete("/boards/#{self.id}/members/#{member.id}")
|
131
|
+
end
|
132
|
+
|
85
133
|
# Return all the cards on this board.
|
86
134
|
#
|
87
135
|
# This method, when called, can take a hash table with a filter key containing any
|
88
136
|
# of the following values:
|
89
137
|
# :filter => [ :none, :open, :closed, :all ] # default :open
|
90
|
-
many :cards, :
|
138
|
+
many :cards, filter: :open
|
91
139
|
|
92
140
|
# Returns all the lists on this board.
|
93
141
|
#
|
94
142
|
# This method, when called, can take a hash table with a filter key containing any
|
95
143
|
# of the following values:
|
96
144
|
# :filter => [ :none, :open, :closed, :all ] # default :open
|
97
|
-
many :lists, :
|
145
|
+
many :lists, filter: :open
|
98
146
|
|
99
147
|
# Returns an array of members who are associated with this board.
|
100
148
|
#
|
101
149
|
# This method, when called, can take a hash table with a filter key containing any
|
102
150
|
# of the following values:
|
103
151
|
# :filter => [ :none, :normal, :owners, :all ] # default :all
|
104
|
-
many :members, :
|
152
|
+
many :members, filter: :all
|
105
153
|
|
106
154
|
# Returns a reference to the organization this board belongs to.
|
107
|
-
one :organization, :
|
155
|
+
one :organization, path: :organizations, using: :organization_id
|
108
156
|
|
109
157
|
def labels
|
110
158
|
labels = client.get("/boards/#{id}/labelnames").json_into(LabelName)
|
@@ -115,5 +163,29 @@ module Trello
|
|
115
163
|
def request_prefix
|
116
164
|
"/boards/#{id}"
|
117
165
|
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
# On creation
|
170
|
+
# https://trello.com/docs/api/board/#post-1-boards
|
171
|
+
# - permissionLevel
|
172
|
+
# - voting
|
173
|
+
# - comments
|
174
|
+
# - invitations
|
175
|
+
# - selfJoin
|
176
|
+
# - cardCovers
|
177
|
+
# - background
|
178
|
+
# - cardAging
|
179
|
+
#
|
180
|
+
# On update
|
181
|
+
# https://trello.com/docs/api/board/#put-1-boards-board-id
|
182
|
+
# Same as above plus:
|
183
|
+
# - calendarFeedEnabled
|
184
|
+
def flat_prefs
|
185
|
+
separator = id ? "/" : "_"
|
186
|
+
attributes[:prefs].inject({}) do |hash, (pref, v)|
|
187
|
+
hash.merge("prefs#{separator}#{pref}" => v)
|
188
|
+
end
|
189
|
+
end
|
118
190
|
end
|
119
191
|
end
|
data/lib/trello/card.rb
CHANGED
@@ -1,13 +1,48 @@
|
|
1
1
|
module Trello
|
2
2
|
# A Card is a container that can house checklists and comments; it resides inside a List.
|
3
|
+
#
|
4
|
+
# @!attribute [r] id
|
5
|
+
# @return [String]
|
6
|
+
# @!attribute [r] short_id
|
7
|
+
# @return [Fixnum]
|
8
|
+
# @!attribute [rw] name
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [rw] desc
|
11
|
+
# @return [String]
|
12
|
+
# @!attribute [rw] due
|
13
|
+
# @return [Datetime]
|
14
|
+
# @!attribute [rw] closed
|
15
|
+
# @return [Boolean]
|
16
|
+
# @!attribute [r] url
|
17
|
+
# @return [String]
|
18
|
+
# @!attribute [r] short_url
|
19
|
+
# @return [String]
|
20
|
+
# @!attribute [rw] board_id
|
21
|
+
# @return [String] A 24-character hex string
|
22
|
+
# @!attribute [rw] member_ids
|
23
|
+
# @return [Array<String>] An Array of 24-character hex strings
|
24
|
+
# @!attribute [rw] list_id
|
25
|
+
# @return [String] A 24-character hex string
|
26
|
+
# @!attribute [rw] pos
|
27
|
+
# @return [Float]
|
28
|
+
# @!attribute [r] last_activity_date
|
29
|
+
# @return [Dateime]
|
30
|
+
# @!attribute [rw] card_labels
|
31
|
+
# @return [Array<Hash>]
|
32
|
+
# @!attribute [rw] cover_image_id
|
33
|
+
# @return [String] A 24-character hex string
|
34
|
+
# @!attribute [r] badges
|
35
|
+
# @return [Hash]
|
36
|
+
# @!attribute [r] card_members
|
37
|
+
# @return [Object]
|
3
38
|
class Card < BasicData
|
4
39
|
register_attributes :id, :short_id, :name, :desc, :due, :closed, :url, :short_url,
|
5
40
|
:board_id, :member_ids, :list_id, :pos, :last_activity_date, :card_labels,
|
6
41
|
:cover_image_id, :badges, :card_members,
|
7
|
-
:
|
42
|
+
readonly: [ :id, :short_id, :url, :short_url, :last_activity_date, :badges, :card_members ]
|
8
43
|
validates_presence_of :id, :name, :list_id
|
9
|
-
validates_length_of :name, :
|
10
|
-
validates_length_of :desc, :
|
44
|
+
validates_length_of :name, in: 1..16384
|
45
|
+
validates_length_of :desc, in: 0..16384
|
11
46
|
|
12
47
|
include HasActions
|
13
48
|
|
@@ -33,11 +68,32 @@ module Trello
|
|
33
68
|
|
34
69
|
class << self
|
35
70
|
# Find a specific card by its id.
|
71
|
+
#
|
72
|
+
# @raise [Trello::Error] if the card could not be found.
|
73
|
+
#
|
74
|
+
# @return [Trello::Card]
|
36
75
|
def find(id, params = {})
|
37
76
|
client.find(:card, id, params)
|
38
77
|
end
|
39
78
|
|
40
79
|
# Create a new card and save it on Trello.
|
80
|
+
#
|
81
|
+
# @param [Hash] options # @option options [String] :name The name of the new card.
|
82
|
+
# @option options [String] :list_id ID of the list that the card should
|
83
|
+
# be added to.
|
84
|
+
# @option options [String] :desc A string with a
|
85
|
+
# length from 0 to 16384.
|
86
|
+
# @option options [String] :member_ids A comma-separated list of
|
87
|
+
# objectIds (24-character hex strings).
|
88
|
+
# @option options [String] :card_labels A comma-separated list of
|
89
|
+
# objectIds (24-character hex strings).
|
90
|
+
# @option options [Date] :due A date, or `nil`.
|
91
|
+
# @option options [String] :pos A position. `"top"`, `"bottom"`, or a
|
92
|
+
# positive number. Defaults to `"bottom"`.
|
93
|
+
#
|
94
|
+
# @raise [Trello::Error] if the card could not be created.
|
95
|
+
#
|
96
|
+
# @return [Trello::Card]
|
41
97
|
def create(options)
|
42
98
|
client.create(:card,
|
43
99
|
'name' => options[:name],
|
@@ -55,6 +111,34 @@ module Trello
|
|
55
111
|
#
|
56
112
|
# Supply a hash of string keyed data retrieved from the Trello API representing
|
57
113
|
# a card.
|
114
|
+
#
|
115
|
+
# Note that this this method does not save anything new to the Trello API,
|
116
|
+
# it just assigns the input attributes to your local object. If you use
|
117
|
+
# this method to assign attributes, call `save` or `update!` afterwards if
|
118
|
+
# you want to persist your changes to Trello.
|
119
|
+
#
|
120
|
+
# @param [Hash] fields
|
121
|
+
# @option fields [String] :id
|
122
|
+
# @option fields [String] :short_id
|
123
|
+
# @option fields [String] :name The new name of the card.
|
124
|
+
# @option fields [String] :desc A string with a length from 0 to
|
125
|
+
# 16384.
|
126
|
+
# @option fields [Date] :due A date, or `nil`.
|
127
|
+
# @option fields [Boolean] :closed
|
128
|
+
# @option fields [String] :url
|
129
|
+
# @option fields [String] :short_url
|
130
|
+
# @option fields [String] :board_id
|
131
|
+
# @option fields [String] :member_ids A comma-separated list of objectIds
|
132
|
+
# (24-character hex strings).
|
133
|
+
# @option fields [String] :pos A position. `"top"`, `"bottom"`, or a
|
134
|
+
# positive number. Defaults to `"bottom"`.
|
135
|
+
# @option fields [String] :card_labels A comma-separated list of
|
136
|
+
# objectIds (24-character hex strings).
|
137
|
+
# @option fields [Object] :cover_image_id
|
138
|
+
# @option fields [Object] :badges
|
139
|
+
# @option fields [Object] :card_members
|
140
|
+
#
|
141
|
+
# @return [Trello::Card] self
|
58
142
|
def update_fields(fields)
|
59
143
|
attributes[:id] = fields[SYMBOL_TO_STRING[:id]]
|
60
144
|
attributes[:short_id] = fields[SYMBOL_TO_STRING[:short_id]]
|
@@ -77,16 +161,16 @@ module Trello
|
|
77
161
|
end
|
78
162
|
|
79
163
|
# Returns a reference to the board this card is part of.
|
80
|
-
one :board, :
|
164
|
+
one :board, path: :boards, using: :board_id
|
81
165
|
# Returns a reference to the cover image attachment
|
82
|
-
one :cover_image, :
|
166
|
+
one :cover_image, path: :attachments, using: :cover_image_id
|
83
167
|
|
84
168
|
# Returns a list of checklists associated with the card.
|
85
169
|
#
|
86
170
|
# The options hash may have a filter key which can have its value set as any
|
87
171
|
# of the following values:
|
88
172
|
# :filter => [ :none, :all ] # default :all
|
89
|
-
many :checklists, :
|
173
|
+
many :checklists, filter: :all
|
90
174
|
|
91
175
|
def check_item_states
|
92
176
|
states = client.get("/cards/#{self.id}/checkItemStates").json_into(CheckItemState)
|
@@ -95,9 +179,11 @@ module Trello
|
|
95
179
|
|
96
180
|
|
97
181
|
# Returns a reference to the list this card is currently in.
|
98
|
-
one :list, :
|
182
|
+
one :list, path: :lists, using: :list_id
|
99
183
|
|
100
184
|
# Returns a list of members who are assigned to this card.
|
185
|
+
#
|
186
|
+
# @return [Array<Trello::Member>]
|
101
187
|
def members
|
102
188
|
members = member_ids.map do |member_id|
|
103
189
|
client.get("/members/#{member_id}").json_into(Member)
|
@@ -106,6 +192,11 @@ module Trello
|
|
106
192
|
end
|
107
193
|
|
108
194
|
# Saves a record.
|
195
|
+
#
|
196
|
+
# @raise [Trello::Error] if the card could not be saved
|
197
|
+
#
|
198
|
+
# @return [String] The JSON representation of the saved card returned by
|
199
|
+
# the Trello API.
|
109
200
|
def save
|
110
201
|
# If we have an id, just update our fields.
|
111
202
|
return update! if id
|
@@ -121,9 +212,15 @@ module Trello
|
|
121
212
|
end
|
122
213
|
|
123
214
|
# Update an existing record.
|
124
|
-
#
|
215
|
+
#
|
216
|
+
# Warning: this updates all fields using values already in memory. If
|
125
217
|
# an external resource has updated these fields, you should refresh!
|
126
218
|
# this object before making your changes, and before updating the record.
|
219
|
+
#
|
220
|
+
# @raise [Trello::Error] if the card could not be updated.
|
221
|
+
#
|
222
|
+
# @return [String] The JSON representation of the updated card returned by
|
223
|
+
# the Trello API.
|
127
224
|
def update!
|
128
225
|
@previously_changed = changes
|
129
226
|
# extract only new values to build payload
|
@@ -133,7 +230,10 @@ module Trello
|
|
133
230
|
client.put("/cards/#{id}", payload)
|
134
231
|
end
|
135
232
|
|
233
|
+
|
136
234
|
# Delete this card
|
235
|
+
#
|
236
|
+
# @return [String] the JSON response from the Trello API
|
137
237
|
def delete
|
138
238
|
client.delete("/cards/#{id}")
|
139
239
|
end
|
@@ -143,6 +243,15 @@ module Trello
|
|
143
243
|
closed
|
144
244
|
end
|
145
245
|
|
246
|
+
# Close the card.
|
247
|
+
#
|
248
|
+
# This only marks your local copy card as closed. Use `close!` if you
|
249
|
+
# want to close the card and persist the change to the Trello API.
|
250
|
+
#
|
251
|
+
# @return [Boolean] always returns true
|
252
|
+
#
|
253
|
+
# @return [String] The JSON representation of the closed card returned by
|
254
|
+
# the Trello API.
|
146
255
|
def close
|
147
256
|
self.closed = true
|
148
257
|
end
|
@@ -159,13 +268,13 @@ module Trello
|
|
159
268
|
|
160
269
|
# Add a comment with the supplied text.
|
161
270
|
def add_comment(text)
|
162
|
-
client.post("/cards/#{id}/actions/comments", :
|
271
|
+
client.post("/cards/#{id}/actions/comments", text: text)
|
163
272
|
end
|
164
273
|
|
165
274
|
# Add a checklist to this card
|
166
275
|
def add_checklist(checklist)
|
167
276
|
client.post("/cards/#{id}/checklists", {
|
168
|
-
:
|
277
|
+
value: checklist.id
|
169
278
|
})
|
170
279
|
end
|
171
280
|
|
@@ -187,7 +296,7 @@ module Trello
|
|
187
296
|
# Move this card to the given board (and optional list on this board)
|
188
297
|
def move_to_board(new_board, new_list = nil)
|
189
298
|
unless board_id == new_board.id
|
190
|
-
payload = { :
|
299
|
+
payload = { value: new_board.id }
|
191
300
|
payload[:idList] = new_list.id if new_list
|
192
301
|
client.put("/cards/#{id}/idBoard", payload)
|
193
302
|
end
|
@@ -196,7 +305,7 @@ module Trello
|
|
196
305
|
# Add a member to this card
|
197
306
|
def add_member(member)
|
198
307
|
client.post("/cards/#{id}/members", {
|
199
|
-
:
|
308
|
+
value: member.id
|
200
309
|
})
|
201
310
|
end
|
202
311
|
|
@@ -222,7 +331,7 @@ module Trello
|
|
222
331
|
errors.add(:label, "colour '#{colour}' does not exist")
|
223
332
|
return Trello.logger.warn "The label colour '#{colour}' does not exist."
|
224
333
|
end
|
225
|
-
client.post("/cards/#{id}/labels", { :
|
334
|
+
client.post("/cards/#{id}/labels", { value: colour })
|
226
335
|
end
|
227
336
|
|
228
337
|
# Remove a label
|
@@ -238,13 +347,13 @@ module Trello
|
|
238
347
|
def add_attachment(attachment, name='')
|
239
348
|
if attachment.is_a? File
|
240
349
|
client.post("/cards/#{id}/attachments", {
|
241
|
-
:
|
242
|
-
:
|
350
|
+
file: attachment,
|
351
|
+
name: name
|
243
352
|
})
|
244
353
|
else
|
245
354
|
client.post("/cards/#{id}/attachments", {
|
246
|
-
:
|
247
|
-
:
|
355
|
+
url: attachment,
|
356
|
+
name: name
|
248
357
|
})
|
249
358
|
end
|
250
359
|
end
|
@@ -255,7 +364,7 @@ module Trello
|
|
255
364
|
MultiAssociation.new(self, attachments).proxy
|
256
365
|
end
|
257
366
|
|
258
|
-
|
367
|
+
# Remove an attachment from this card
|
259
368
|
def remove_attachment(attachment)
|
260
369
|
client.delete("/cards/#{id}/attachments/#{attachment.id}")
|
261
370
|
end
|