Class: Trello::List

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

Overview

A List is a container which holds cards. Lists are items on a board.

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

#board_idString (readonly)

Returns A 24-character hex string.

Returns:

  • (String)

    A 24-character hex string



14
15
16
17
18
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
# File 'lib/trello/list.rb', line 14

class List < BasicData
  register_attributes :id, :name, :closed, :board_id, :pos, :source_list_id, readonly: [ :id, :board_id ]
  validates_presence_of :id, :name, :board_id
  validates_length_of   :name, in: 1..16384

  include HasActions

  class << self
    # Finds a specific list, given an id.
    #
    # @param [id] id the list's ID on Trello (24-character hex string).
    # @param [Hash] params
    def find(id, params = {})
      client.find(:list, id, params)
    end

    def create(options)
      client.create(:list,
          'name'         => options[:name],
          'idBoard'      => options[:board_id],
          'pos'          => options[:pos],
          'idListSource' => options[:source_list_id])
    end
  end

  # Updates the fields of a list.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a List.
  def update_fields(fields)
    attributes[:id]             = fields['id']
    attributes[:name]           = fields['name'] || fields[:name]
    attributes[:closed]         = fields['closed']
    attributes[:board_id]       = fields['idBoard'] || fields[:board_id]
    attributes[:pos]            = fields['pos'] || fields[:pos]
    attributes[:source_list_id] = fields['idListSource'] || fields[:source_list_id]
    self
  end

  def save
    return update! if id

    from_response client.post("/lists", {
      name: name,
      closed: closed || false,
      idBoard: board_id,
      pos: pos,
      idListSource: source_list_id
    })
  end

  def update!
    client.put("/lists/#{id}", {
      name: name,
      closed: closed,
      pos: pos
    })
  end

  # Check if the list is not active anymore.
  def closed?
    closed
  end

  def close
    self.closed = true
  end

  def close!
    close
    save
  end

  # Return the board the list is connected to.
  one :board, path: :boards, using: :board_id

  # Returns all the cards on this list.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :open, :closed, :all ] # default :open
  many :cards, filter: :open

  def move_all_cards(other_list)
    client.post("/lists/#{id}/moveAllCards", {
      idBoard: other_list.board_id,
      idList: other_list.id
     })
  end

  # Archives all the cards of the list
  def archive_all_cards
    client.post("/lists/#{id}/archiveAllCards")
  end

  # :nodoc:
  def request_prefix
    "/lists/#{id}"
  end
end

#closedBoolean

Returns:

  • (Boolean)


14
15
16
17
18
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
# File 'lib/trello/list.rb', line 14

class List < BasicData
  register_attributes :id, :name, :closed, :board_id, :pos, :source_list_id, readonly: [ :id, :board_id ]
  validates_presence_of :id, :name, :board_id
  validates_length_of   :name, in: 1..16384

  include HasActions

  class << self
    # Finds a specific list, given an id.
    #
    # @param [id] id the list's ID on Trello (24-character hex string).
    # @param [Hash] params
    def find(id, params = {})
      client.find(:list, id, params)
    end

    def create(options)
      client.create(:list,
          'name'         => options[:name],
          'idBoard'      => options[:board_id],
          'pos'          => options[:pos],
          'idListSource' => options[:source_list_id])
    end
  end

  # Updates the fields of a list.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a List.
  def update_fields(fields)
    attributes[:id]             = fields['id']
    attributes[:name]           = fields['name'] || fields[:name]
    attributes[:closed]         = fields['closed']
    attributes[:board_id]       = fields['idBoard'] || fields[:board_id]
    attributes[:pos]            = fields['pos'] || fields[:pos]
    attributes[:source_list_id] = fields['idListSource'] || fields[:source_list_id]
    self
  end

  def save
    return update! if id

    from_response client.post("/lists", {
      name: name,
      closed: closed || false,
      idBoard: board_id,
      pos: pos,
      idListSource: source_list_id
    })
  end

  def update!
    client.put("/lists/#{id}", {
      name: name,
      closed: closed,
      pos: pos
    })
  end

  # Check if the list is not active anymore.
  def closed?
    closed
  end

  def close
    self.closed = true
  end

  def close!
    close
    save
  end

  # Return the board the list is connected to.
  one :board, path: :boards, using: :board_id

  # Returns all the cards on this list.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :open, :closed, :all ] # default :open
  many :cards, filter: :open

  def move_all_cards(other_list)
    client.post("/lists/#{id}/moveAllCards", {
      idBoard: other_list.board_id,
      idList: other_list.id
     })
  end

  # Archives all the cards of the list
  def archive_all_cards
    client.post("/lists/#{id}/archiveAllCards")
  end

  # :nodoc:
  def request_prefix
    "/lists/#{id}"
  end
end

#idString (readonly)

Returns:



14
15
16
17
18
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
# File 'lib/trello/list.rb', line 14

class List < BasicData
  register_attributes :id, :name, :closed, :board_id, :pos, :source_list_id, readonly: [ :id, :board_id ]
  validates_presence_of :id, :name, :board_id
  validates_length_of   :name, in: 1..16384

  include HasActions

  class << self
    # Finds a specific list, given an id.
    #
    # @param [id] id the list's ID on Trello (24-character hex string).
    # @param [Hash] params
    def find(id, params = {})
      client.find(:list, id, params)
    end

    def create(options)
      client.create(:list,
          'name'         => options[:name],
          'idBoard'      => options[:board_id],
          'pos'          => options[:pos],
          'idListSource' => options[:source_list_id])
    end
  end

  # Updates the fields of a list.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a List.
  def update_fields(fields)
    attributes[:id]             = fields['id']
    attributes[:name]           = fields['name'] || fields[:name]
    attributes[:closed]         = fields['closed']
    attributes[:board_id]       = fields['idBoard'] || fields[:board_id]
    attributes[:pos]            = fields['pos'] || fields[:pos]
    attributes[:source_list_id] = fields['idListSource'] || fields[:source_list_id]
    self
  end

  def save
    return update! if id

    from_response client.post("/lists", {
      name: name,
      closed: closed || false,
      idBoard: board_id,
      pos: pos,
      idListSource: source_list_id
    })
  end

  def update!
    client.put("/lists/#{id}", {
      name: name,
      closed: closed,
      pos: pos
    })
  end

  # Check if the list is not active anymore.
  def closed?
    closed
  end

  def close
    self.closed = true
  end

  def close!
    close
    save
  end

  # Return the board the list is connected to.
  one :board, path: :boards, using: :board_id

  # Returns all the cards on this list.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :open, :closed, :all ] # default :open
  many :cards, filter: :open

  def move_all_cards(other_list)
    client.post("/lists/#{id}/moveAllCards", {
      idBoard: other_list.board_id,
      idList: other_list.id
     })
  end

  # Archives all the cards of the list
  def archive_all_cards
    client.post("/lists/#{id}/archiveAllCards")
  end

  # :nodoc:
  def request_prefix
    "/lists/#{id}"
  end
end

#nameString

Returns:



14
15
16
17
18
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
# File 'lib/trello/list.rb', line 14

class List < BasicData
  register_attributes :id, :name, :closed, :board_id, :pos, :source_list_id, readonly: [ :id, :board_id ]
  validates_presence_of :id, :name, :board_id
  validates_length_of   :name, in: 1..16384

  include HasActions

  class << self
    # Finds a specific list, given an id.
    #
    # @param [id] id the list's ID on Trello (24-character hex string).
    # @param [Hash] params
    def find(id, params = {})
      client.find(:list, id, params)
    end

    def create(options)
      client.create(:list,
          'name'         => options[:name],
          'idBoard'      => options[:board_id],
          'pos'          => options[:pos],
          'idListSource' => options[:source_list_id])
    end
  end

  # Updates the fields of a list.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a List.
  def update_fields(fields)
    attributes[:id]             = fields['id']
    attributes[:name]           = fields['name'] || fields[:name]
    attributes[:closed]         = fields['closed']
    attributes[:board_id]       = fields['idBoard'] || fields[:board_id]
    attributes[:pos]            = fields['pos'] || fields[:pos]
    attributes[:source_list_id] = fields['idListSource'] || fields[:source_list_id]
    self
  end

  def save
    return update! if id

    from_response client.post("/lists", {
      name: name,
      closed: closed || false,
      idBoard: board_id,
      pos: pos,
      idListSource: source_list_id
    })
  end

  def update!
    client.put("/lists/#{id}", {
      name: name,
      closed: closed,
      pos: pos
    })
  end

  # Check if the list is not active anymore.
  def closed?
    closed
  end

  def close
    self.closed = true
  end

  def close!
    close
    save
  end

  # Return the board the list is connected to.
  one :board, path: :boards, using: :board_id

  # Returns all the cards on this list.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :open, :closed, :all ] # default :open
  many :cards, filter: :open

  def move_all_cards(other_list)
    client.post("/lists/#{id}/moveAllCards", {
      idBoard: other_list.board_id,
      idList: other_list.id
     })
  end

  # Archives all the cards of the list
  def archive_all_cards
    client.post("/lists/#{id}/archiveAllCards")
  end

  # :nodoc:
  def request_prefix
    "/lists/#{id}"
  end
end

#posObject

Returns:

  • (Object)


14
15
16
17
18
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
# File 'lib/trello/list.rb', line 14

class List < BasicData
  register_attributes :id, :name, :closed, :board_id, :pos, :source_list_id, readonly: [ :id, :board_id ]
  validates_presence_of :id, :name, :board_id
  validates_length_of   :name, in: 1..16384

  include HasActions

  class << self
    # Finds a specific list, given an id.
    #
    # @param [id] id the list's ID on Trello (24-character hex string).
    # @param [Hash] params
    def find(id, params = {})
      client.find(:list, id, params)
    end

    def create(options)
      client.create(:list,
          'name'         => options[:name],
          'idBoard'      => options[:board_id],
          'pos'          => options[:pos],
          'idListSource' => options[:source_list_id])
    end
  end

  # Updates the fields of a list.
  #
  # Supply a hash of string keyed data retrieved from the Trello API representing
  # a List.
  def update_fields(fields)
    attributes[:id]             = fields['id']
    attributes[:name]           = fields['name'] || fields[:name]
    attributes[:closed]         = fields['closed']
    attributes[:board_id]       = fields['idBoard'] || fields[:board_id]
    attributes[:pos]            = fields['pos'] || fields[:pos]
    attributes[:source_list_id] = fields['idListSource'] || fields[:source_list_id]
    self
  end

  def save
    return update! if id

    from_response client.post("/lists", {
      name: name,
      closed: closed || false,
      idBoard: board_id,
      pos: pos,
      idListSource: source_list_id
    })
  end

  def update!
    client.put("/lists/#{id}", {
      name: name,
      closed: closed,
      pos: pos
    })
  end

  # Check if the list is not active anymore.
  def closed?
    closed
  end

  def close
    self.closed = true
  end

  def close!
    close
    save
  end

  # Return the board the list is connected to.
  one :board, path: :boards, using: :board_id

  # Returns all the cards on this list.
  #
  # The options hash may have a filter key which can have its value set as any
  # of the following values:
  #    :filter => [ :none, :open, :closed, :all ] # default :open
  many :cards, filter: :open

  def move_all_cards(other_list)
    client.post("/lists/#{id}/moveAllCards", {
      idBoard: other_list.board_id,
      idList: other_list.id
     })
  end

  # Archives all the cards of the list
  def archive_all_cards
    client.post("/lists/#{id}/archiveAllCards")
  end

  # :nodoc:
  def request_prefix
    "/lists/#{id}"
  end
end

Class Method Details

.create(options) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/trello/list.rb', line 30

def create(options)
  client.create(:list,
      'name'         => options[:name],
      'idBoard'      => options[:board_id],
      'pos'          => options[:pos],
      'idListSource' => options[:source_list_id])
end

.find(id, params = {}) ⇒ Object

Finds a specific list, given an id.

Parameters:

  • id (id)

    the list’s ID on Trello (24-character hex string).

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


26
27
28
# File 'lib/trello/list.rb', line 26

def find(id, params = {})
  client.find(:list, id, params)
end

Instance Method Details

#archive_all_cardsObject

Archives all the cards of the list



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

def archive_all_cards
  client.post("/lists/#{id}/archiveAllCards")
end

#closeObject



78
79
80
# File 'lib/trello/list.rb', line 78

def close
  self.closed = true
end

#close!Object



82
83
84
85
# File 'lib/trello/list.rb', line 82

def close!
  close
  save
end

#closed?Boolean

Check if the list is not active anymore.

Returns:

  • (Boolean)


74
75
76
# File 'lib/trello/list.rb', line 74

def closed?
  closed
end

#move_all_cards(other_list) ⇒ Object



97
98
99
100
101
102
# File 'lib/trello/list.rb', line 97

def move_all_cards(other_list)
  client.post("/lists/#{id}/moveAllCards", {
    idBoard: other_list.board_id,
    idList: other_list.id
   })
end

#request_prefixObject

:nodoc:



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

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

#saveObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/trello/list.rb', line 53

def save
  return update! if id

  from_response client.post("/lists", {
    name: name,
    closed: closed || false,
    idBoard: board_id,
    pos: pos,
    idListSource: source_list_id
  })
end

#update!Object



65
66
67
68
69
70
71
# File 'lib/trello/list.rb', line 65

def update!
  client.put("/lists/#{id}", {
    name: name,
    closed: closed,
    pos: pos
  })
end

#update_fields(fields) ⇒ Object

Updates the fields of a list.

Supply a hash of string keyed data retrieved from the Trello API representing a List.



43
44
45
46
47
48
49
50
51
# File 'lib/trello/list.rb', line 43

def update_fields(fields)
  attributes[:id]             = fields['id']
  attributes[:name]           = fields['name'] || fields[:name]
  attributes[:closed]         = fields['closed']
  attributes[:board_id]       = fields['idBoard'] || fields[:board_id]
  attributes[:pos]            = fields['pos'] || fields[:pos]
  attributes[:source_list_id] = fields['idListSource'] || fields[:source_list_id]
  self
end