Skip to content

Commit

Permalink
modify for keeping download data as cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hidetak committed Jun 28, 2020
1 parent d427c6b commit 49eb298
Showing 1 changed file with 55 additions and 13 deletions.
68 changes: 55 additions & 13 deletions lib/trello-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ class TrelloCSV {
this.LISTS_URL = `https://trello.com/1/boards/$$BOARD_ID$$/lists?fields=name,url&key=${config.KEY}&token=${config.TOKEN}`
this.CARDS_URL = `https://trello.com/1/lists/$$LIST_ID$$/cards?key=${config.KEY}&token=${config.TOKEN}&fields=name,labels,idMembers,desc,shortUrl`
this.ACTIONS_URL = `https://trello.com/1/cards/$$CARD_ID$$/actions?key=${config.KEY}&token=${config.TOKEN}&filter=all`
this.clearRawData()
}

getRawData() {
return {
_boards: this._boards,
_members: this._members,
_lists: this._lists,
_cards: this._cards,
_actions: this._actions,
}
}

setRawData(datas) {
this._boards = datas._boards
this._members = datas._members
this._lists = datas._lists
this._cards = datas._cards
this._actions = datas._actions
}

clearRawData() {
this._boards = null
this._members = {}
this._lists = {}
this._cards = {}
this._actions = {}
}

async _getDataFromTrello(url) {
Expand All @@ -28,31 +55,46 @@ class TrelloCSV {
}

async loadBoards() {
return this._getDataFromTrello(this.BOARDS_URL)
if (!this._boards) {
this._boards = await this._getDataFromTrello(this.BOARDS_URL)
}
return this._boards
}

async loadMember(memberId) {
return this._getDataFromTrello(
this.MEMBERS_URL.replace('$$MEMBER_ID$$', memberId)
)
if (!this._members[memberId]) {
this._members[memberId] = await this._getDataFromTrello(
this.MEMBERS_URL.replace('$$MEMBER_ID$$', memberId)
)
}
return this._members[memberId]
}

async loadLists(boardId) {
return this._getDataFromTrello(
this.LISTS_URL.replace('$$BOARD_ID$$', boardId)
)
if (!this._lists[boardId]) {
this._lists[boardId] = await this._getDataFromTrello(
this.LISTS_URL.replace('$$BOARD_ID$$', boardId)
)
}
return this._lists[boardId]
}

async loadCards(listId) {
return this._getDataFromTrello(
this.CARDS_URL.replace('$$LIST_ID$$', listId)
)
if (!this._cards[listId]) {
this._cards[listId] = await this._getDataFromTrello(
this.CARDS_URL.replace('$$LIST_ID$$', listId)
)
}
return this._cards[listId]
}

async loadActions(cardId) {
return this._getDataFromTrello(
this.ACTIONS_URL.replace('$$CARD_ID$$', cardId)
)
if (!this._actions[cardId]) {
this._actions[cardId] = await this._getDataFromTrello(
this.ACTIONS_URL.replace('$$CARD_ID$$', cardId)
)
}
return this._actions[cardId]
}

async parseBoard(board) {
Expand Down

0 comments on commit 49eb298

Please sign in to comment.