Created
November 3, 2017 11:57
-
-
Save shop-0761/dd2e8e3414599b294d3c6a0d691d187e to your computer and use it in GitHub Desktop.
trello + GAS する時の関数たち
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//trelloの指定のボードIDを取得する関数 | |
function getTrelloBoardID(trello_API_KEY, trello_TOKEN, trello_USERNAME, boardName){ | |
var url = 'https://trello.com/1/members/' + trello_USERNAME + '/boards?key=' + trello_API_KEY + '&token=' + trello_TOKEN + '&fields=name'; | |
var fetch = UrlFetchApp.fetch(url, {'method':'get'}); | |
var json = JSON.parse(fetch); | |
for(var i in json){ | |
if(json[i].name == boardName){ | |
return json[i].id; | |
} | |
} | |
return null; | |
} | |
//trelloの指定のListIDを取得する関数 | |
function getTrelloListID(trello_API_KEY, trello_TOKEN, boardId, listName){ | |
var url = 'https://trello.com/1/boards/' + boardId + '/lists?key=' + trello_API_KEY + '&token=' + trello_TOKEN + '&fields=name'; | |
var fetch = UrlFetchApp.fetch(url, {'method':'get'}); | |
var json = JSON.parse(fetch); | |
for(var i in json){ | |
if(json[i].name == listName){ | |
return json[i].id; | |
} | |
} | |
return null; | |
} | |
//trelloにカードを追加する関数 | |
function addTrelloCard(trello_API_KEY, trello_TOKEN, listId, text){ | |
var url = 'https://api.trello.com/1/cards/?key=' + trello_API_KEY + '&token=' + trello_TOKEN; | |
var options = { | |
'method' : 'post', | |
'muteHttpExceptions' : true, | |
'payload' : { | |
'name' : text, | |
'desc' : '', | |
'due' : '', | |
'idList' : listId, | |
'urlSource' : '' | |
} | |
} | |
UrlFetchApp.fetch(url, options); | |
} | |
//trelloのカードを削除する関数 | |
function deleteTrelloCard(trello_API_KEY, trello_TOKEN, listId, text){ | |
var url = 'https://api.trello.com/1/lists/' + listId + '/cards/?key=' + trello_API_KEY + '&token=' + trello_TOKEN; | |
var fetch = UrlFetchApp.fetch(url, {'method':'get'}); | |
var json = JSON.parse(fetch); | |
for(var i in json){ | |
if(json[i].name == text){ | |
url = 'https://api.trello.com/1/cards/' + json[i].id +'?key=' + trello_API_KEY + '&token=' + trello_TOKEN; | |
fetch = UrlFetchApp.fetch(url, {'method':'delete'}); | |
json = JSON.parse(fetch); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment