Class: Trello::Board

Inherits:
BasicData show all
Includes:
HasActions
Defined in:
lib/trello/board.rb

Overview

A board on Trello

Instance Attribute Summary collapse

Attributes inherited from BasicData

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasActions

#actions

Methods inherited from BasicData

#==, client, #initialize, many, one, parse, parse_many, path_name, #refresh!, register_attributes, save

Methods included from JsonUtils

included

Constructor Details

This class inherits a constructor from Trello::BasicData

Instance Attribute Details

#closedBoolean

Returns:

  • (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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

#descriptionString

Returns:



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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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

#idString (readonly)

Returns:



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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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

#nameString (readonly)

Returns:



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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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_idString

Returns A 24-character hex string.

Returns:

  • (String)

    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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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

#prefsHash (readonly)

Returns A 24-character hex string.

Returns:

  • (Hash)

    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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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

#urlString (readonly)

Returns:



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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/trello/board.rb', line 19

class Board < BasicData
  register_attributes :id, :name, :description, :closed, :starred, :url, :organization_id, :prefs, :last_activity_date,
    readonly: [ :id, :url, :last_activity_date ]
  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
      from_response client.get("/members/#{Member.find(:me).username}/boards")
    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)

    from_response(client.post("/boards", fields))
  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)

    from_response client.put("/boards/#{self.id}/", fields)
  end

  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

  # @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)
    Card.from_response client.get("/boards/#{self.id}/cards/#{card_id}")
  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 list of checklists associated with the board.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :all ] # default :all
  many :checklists, filter: :all

  # Returns a reference to the organization this board belongs to.
  one :organization, path: :organizations, using: :organization_id

  # Returns a list of plugins associated with the board
  many :plugin_data, path: "pluginData"

  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

  def label_names
    label_names = LabelName.from_response client.get("/boards/#{id}/labelnames")
    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

.allArray<Trello::Board>

Returns all boards for the current user.

Returns:



55
56
57
# File 'lib/trello/board.rb', line 55

def all
  from_response client.get("/members/#{Member.find(:me).username}/boards")
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.

Parameters:

  • id (String)

    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.)

  • params (Hash) (defaults to: {})

Returns:

Raises:

  • (Trello::Board)

    if a board with the given ID could not be found.



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 ]


127
128
129
# 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?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/trello/board.rb', line 105

def closed?
  attributes[:closed]
end

#find_card(card_id) ⇒ Trello::Card

Find a card on this Board with the given ID.

Returns:



121
122
123
# 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?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/trello/board.rb', line 115

def has_lists?
  lists.size > 0
end

#label_namesObject



177
178
179
180
# 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 = {}) ⇒ Object



170
171
172
173
174
175
# 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) ⇒ Object

Remove a member of this Board.



132
133
134
# File 'lib/trello/board.rb', line 132

def remove_member(member)
  client.delete("/boards/#{self.id}/members/#{member.id}")
end

#request_prefixObject

:nodoc:



183
184
185
# File 'lib/trello/board.rb', line 183

def request_prefix
  "/boards/#{id}"
end

#saveObject



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)

  from_response(client.post("/boards", fields))
end

#starred?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/trello/board.rb', line 110

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)

  from_response client.put("/boards/#{self.id}/", fields)
end

#update_fields(fields) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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