Class: Trello::Board
- Includes:
- HasActions
- Defined in:
- lib/trello/board.rb
Overview
A board on Trello
Instance Attribute Summary collapse
- #closed ⇒ Boolean
- #description ⇒ String
- #id ⇒ String readonly
- #name ⇒ String readonly
-
#organization_id ⇒ String
A 24-character hex string.
-
#prefs ⇒ Hash
readonly
A 24-character hex string.
- #url ⇒ String readonly
Attributes inherited from BasicData
Class Method Summary collapse
-
.all ⇒ Array<Trello::Board>
All boards for the current user.
- .create(fields) ⇒ Object
-
.find(id, params = {}) ⇒ Trello::Board
Finds a board.
Instance Method Summary collapse
-
#add_member(member, type = :normal) ⇒ Object
Add a member to this Board.
- #closed? ⇒ Boolean
-
#find_card(card_id) ⇒ Trello::Card
Find a card on this Board with the given ID.
- #has_lists? ⇒ Boolean
- #label_names ⇒ Object
-
#remove_member(member) ⇒ Object
Remove a member of this Board.
-
#request_prefix ⇒ Object
:nodoc:.
- #save ⇒ Object
- #starred? ⇒ Boolean
- #update! ⇒ Object
- #update_fields(fields) ⇒ Object
Methods included from HasActions
Methods inherited from BasicData
#==, client, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save
Constructor Details
This class inherits a constructor from Trello::BasicData
Instance Attribute Details
#closed ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
#description ⇒ String
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
#id ⇒ String (readonly)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
#name ⇒ String (readonly)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
#organization_id ⇒ String
Returns A 24-character hex string.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
#prefs ⇒ Hash (readonly)
Returns A 24-character hex string.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
#url ⇒ String (readonly)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/trello/board.rb', line 19 class Board < BasicData register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, readonly: [ :id, :url ] validates_presence_of :id, :name validates_length_of :name, in: 1..16384 validates_length_of :description, maximum: 16384 include HasActions class << self # Finds a board. # # @param [String] id Either the board's short ID (an alphanumeric string, # found e.g. in the board's URL) or its long ID (a 24-character hex # string.) # @param [Hash] params # # @raise [Trello::Board] if a board with the given ID could not be found. # # @return [Trello::Board] def find(id, params = {}) client.find(:board, id, params) end def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end # @return [Array<Trello::Board>] all boards for the current user def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end end def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end # @return [Boolean] def closed? attributes[:closed] end # @return [Boolean] def starred? attributes[:starred] end # @return [Boolean] def has_lists? lists.size > 0 end # Find a card on this Board with the given ID. # @return [Trello::Card] def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end # Add a member to this Board. # type => [ :admin, :normal, :observer ] def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end # Remove a member of this Board. def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end # Return all the cards on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :cards, filter: :open # Returns all the lists on this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :open, :closed, :all ] # default :open many :lists, filter: :open # Returns an array of members who are associated with this board. # # This method, when called, can take a hash table with a filter key containing any # of the following values: # :filter => [ :none, :normal, :owners, :all ] # default :all many :members, filter: :all # Returns a reference to the organization this board belongs to. one :organization, path: :organizations, using: :organization_id many :labels def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end # :nodoc: def request_prefix "/boards/#{id}" end private # On creation # https://trello.com/docs/api/board/#post-1-boards # - permissionLevel # - voting # - comments # - invitations # - selfJoin # - cardCovers # - background # - cardAging # # On update # https://trello.com/docs/api/board/#put-1-boards-board-id # Same as above plus: # - calendarFeedEnabled def flat_prefs separator = id ? "/" : "_" attributes[:prefs].inject({}) do |hash, (pref, v)| hash.merge("prefs#{separator}#{pref}" => v) end end end |
Class Method Details
.all ⇒ Array<Trello::Board>
Returns all boards for the current user.
55 56 57 |
# File 'lib/trello/board.rb', line 55 def all client.get("/members/#{Member.find(:me).username}/boards").json_into(self) end |
.create(fields) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/trello/board.rb', line 43 def create(fields) data = { 'name' => fields[:name], 'desc' => fields[:description], 'closed' => fields[:closed] || false, 'starred' => fields[:starred] || false } data.merge!('idOrganization' => fields[:organization_id]) if fields[:organization_id] data.merge!('prefs' => fields[:prefs]) if fields[:prefs] client.create(:board, data) end |
.find(id, params = {}) ⇒ Trello::Board
Finds a board.
39 40 41 |
# File 'lib/trello/board.rb', line 39 def find(id, params = {}) client.find(:board, id, params) end |
Instance Method Details
#add_member(member, type = :normal) ⇒ Object
Add a member to this Board.
type => [ :admin, :normal, :observer ]
124 125 126 |
# File 'lib/trello/board.rb', line 124 def add_member(member, type = :normal) client.put("/boards/#{self.id}/members/#{member.id}", { type: type }) end |
#closed? ⇒ Boolean
102 103 104 |
# File 'lib/trello/board.rb', line 102 def closed? attributes[:closed] end |
#find_card(card_id) ⇒ Trello::Card
Find a card on this Board with the given ID.
118 119 120 |
# File 'lib/trello/board.rb', line 118 def find_card(card_id) client.get("/boards/#{self.id}/cards/#{card_id}").json_into(Card) end |
#has_lists? ⇒ Boolean
112 113 114 |
# File 'lib/trello/board.rb', line 112 def has_lists? lists.size > 0 end |
#label_names ⇒ Object
159 160 161 162 |
# File 'lib/trello/board.rb', line 159 def label_names label_names = client.get("/boards/#{id}/labelnames").json_into(LabelName) MultiAssociation.new(self, label_names).proxy end |
#remove_member(member) ⇒ Object
Remove a member of this Board.
129 130 131 |
# File 'lib/trello/board.rb', line 129 def remove_member(member) client.delete("/boards/#{self.id}/members/#{member.id}") end |
#request_prefix ⇒ Object
:nodoc:
165 166 167 |
# File 'lib/trello/board.rb', line 165 def request_prefix "/boards/#{id}" end |
#save ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/trello/board.rb', line 60 def save return update! if id fields = { name: name } fields.merge!(desc: description) if description fields.merge!(idOrganization: organization_id) if organization_id fields.merge!(flat_prefs) client.post("/boards", fields).json_into(self) end |
#starred? ⇒ Boolean
107 108 109 |
# File 'lib/trello/board.rb', line 107 def starred? attributes[:starred] end |
#update! ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/trello/board.rb', line 71 def update! fail "Cannot save new instance." unless self.id @previously_changed = changes @changed_attributes.clear fields = { name: attributes[:name], description: attributes[:description], closed: attributes[:closed], starred: attributes[:starred], idOrganization: attributes[:organization_id] } fields.merge!(flat_prefs) client.put("/boards/#{self.id}/", fields).json_into(self) end |
#update_fields(fields) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/trello/board.rb', line 89 def update_fields(fields) attributes[:id] = fields['id'] if fields['id'] attributes[:name] = fields['name'] if fields['name'] attributes[:description] = fields['desc'] if fields['desc'] attributes[:closed] = fields['closed'] if fields.has_key?('closed') attributes[:starred] = fields['starred'] if fields.has_key?('starred') attributes[:url] = fields['url'] if fields['url'] attributes[:organization_id] = fields['idOrganization'] if fields['idOrganization'] attributes[:prefs] = fields['prefs'] || {} self end |