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
|
# File 'lib/trello-fs/trello_api.rb', line 21
def new_board(board_id)
json = download_board_json(board_id)
board = OpenStruct.new(name: json['name'],
desc: json['desc'],
id: json['id'],
url: json['url'])
lists = {}
board.organization_name = json['organization']['displayName'] if json['organization']
board.labels = json['labels'].
select {|lbl| !lbl['name'].empty? }.
map do |label|
@repository.labels[label['name']] ||= OpenStruct.new(name: label['name'],
id: label['id'],
cards: [])
end
json['lists'].each do |list|
lists[list['id']] = OpenStruct.new(name: list['name'],
id: list['id'],
board: board,
cards: [])
end
cards = json['cards'].
select {|card| lists[card['idList']] }.
map do |card|
list = lists[card['idList']]
c = OpenStruct.new(id: card['id'],
name: card['name'],
desc: card['desc'],
url: card['url'],
short_link: card['shortLink'],
list: list)
list.cards << c
c.labels = card['labels'].
select {|lbl| @repository.labels[lbl['name']] }.
map do |label|
label = @repository.labels[label['name']]
label.cards << c
label
end
c.checklists = card['checklists'].map do |checklist|
OpenStruct.new(
name: checklist['name'],
items: checklist['checkItems'].map do |item|
OpenStruct.new(name: item['name'], state: item['state'])
end
)
end
c.attachments = card['attachments'].map do |attachment|
a = OpenStruct.new(name: attachment['name'],
url: attachment['url'],
id: attachment['id'],
card: c)
@repository.attachments << a
a
end
@repository.cards[card['shortLink']] = c
c
end
board.lists = lists.values
board
end
|