class Trello::Board

A board on Trello

@!attribute [r] id

@return [String]

@!attribute [r] name

@return [String]

@!attribute [rw] description

@return [String]

@!attribute [rw] closed

@return [Boolean]

@!attribute [r] url

@return [String]

@!attribute [rw] organization_id

@return [String] A 24-character hex string

@!attribute [r] prefs

@return [Hash] A 24-character hex string

Public Class Methods

all() click to toggle source

@return [Array<Trello::Board>] all boards for the current user

# File lib/trello/board.rb, line 55
def all
  from_response client.get("/members/#{Member.find(:me).username}/boards")
end
create(fields) click to toggle source
# 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 = {}) click to toggle source

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]

# File lib/trello/board.rb, line 39
def find(id, params = {})
  client.find(:board, id, params)
end

Public Instance Methods

add_member(member, type = :normal) click to toggle source

Add a member to this Board.

type => [ :admin, :normal, :observer ]
# File lib/trello/board.rb, line 127
def add_member(member, type = :normal)
  client.put("/boards/#{self.id}/members/#{member.id}", { type: type })
end
closed?() click to toggle source

@return [Boolean]

# File lib/trello/board.rb, line 105
def closed?
  attributes[:closed]
end
find_card(card_id) click to toggle source

Find a card on this Board with the given ID. @return [Trello::Card]

# File lib/trello/board.rb, line 121
def find_card(card_id)
  Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
end
has_lists?() click to toggle source

@return [Boolean]

# File lib/trello/board.rb, line 115
def has_lists?
  lists.size > 0
end
label_names() click to toggle source
# File lib/trello/board.rb, line 177
def label_names
  label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
  MultiAssociation.new(self, label_names).proxy
end
labels(params = {}) click to toggle source
# File lib/trello/board.rb, line 170
def labels(params = {})
  # Set the limit to as high as possible given there is no pagination in this API.
  params[:limit] = 1000 unless params[:limit]
  labels = Label.from_response client.get("/boards/#{id}/labels", params)
  MultiAssociation.new(self, labels).proxy
end
remove_member(member) click to toggle source

Remove a member of this Board.

# File lib/trello/board.rb, line 132
def remove_member(member)
  client.delete("/boards/#{self.id}/members/#{member.id}")
end
save() click to toggle source
# 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)

  from_response(client.post("/boards", fields))
end
starred?() click to toggle source

@return [Boolean]

# File lib/trello/board.rb, line 110
def starred?
  attributes[:starred]
end
update!() click to toggle source
# 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)

  from_response client.put("/boards/#{self.id}/", fields)
end
update_fields(fields) click to toggle source
# File lib/trello/board.rb, line 89
def update_fields(fields)
  attributes[:id]              = fields['id'] || fields[:id]                          if fields['id']   || fields[:id]
  attributes[:name]            = fields['name'] || fields[:name]                      if fields['name'] || fields[:name]
  attributes[:description]     = fields['desc'] || fields[:desc]                      if fields['desc'] || fields[:desc]
  attributes[:closed]          = fields['closed']                                     if fields.has_key?('closed')
  attributes[:closed]          = fields[:closed]                                      if fields.has_key?(:closed)
  attributes[:starred]         = fields['starred']                                    if fields.has_key?('starred')
  attributes[:starred]         = fields[:starred]                                     if fields.has_key?(:starred)
  attributes[:url]             = fields['url']                                        if fields['url']
  attributes[:organization_id] = fields['idOrganization'] || fields[:organization_id] if fields['idOrganization'] || fields[:organization_id]
  attributes[:prefs]           = fields['prefs'] || fields[:prefs] || {}
  attributes[:last_activity_date] = Time.iso8601(fields['dateLastActivity']) rescue nil
  self
end