Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TrelloAPI = {}
- local HTTPService = game:GetService("HttpService")
- local Key = script.Key.Value
- local Token = script.Token.Value
- script.Key:Destroy()
- script.Token:Destroy()
- function getAddon()
- local addon
- addon = "?key="..Key.."&token="..Token
- return addon
- end
- function TrelloAPI:GetBoard(boardId)
- local addon = getAddon()
- local JSON = HTTPService:GetAsync("https://api.trello.com/1/boards/"..boardId..''..addon)
- local DecodedData = HTTPService:JSONDecode(JSON)
- return DecodedData.name
- end
- function TrelloAPI:GetBoardID(name)
- local addon = getAddon()
- local JSON = HTTPService:GetAsync("https://api.trello.com/1/members/me/boards"..addon)
- local DecodedData = HTTPService:JSONDecode(JSON)
- if name ~= nil then
- for _,tab in pairs(DecodedData) do
- for _,v in pairs(tab) do
- if tab.name == name then
- return tab.id
- end
- end
- end
- error(name.." Was Not Found!")
- return nil
- end
- end
- function TrelloAPI:CreateList(name, boardid)
- local addon = getAddon()
- if name == nil or boardid == nil then
- error('Invalid Arguments!')
- return nil
- else
- local data = {name=name,idBoard=boardid}
- local EncodedData = HTTPService:JSONEncode(data)
- local Return = HTTPService:PostAsync("https://api.trello.com/1/lists"..addon.."&name="..name.."&idBoard="..boardid, EncodedData)
- local ReturnDecoded = HTTPService:JSONDecode(Return)
- return ReturnDecoded.id
- end
- end
- function TrelloAPI:GetListID(name, boardid)
- local addon = getAddon()
- if name == nil or boardid == nil then
- error('Invalid Arguments!')
- return nil
- else
- local Data = HTTPService:GetAsync("https://api.trello.com/1/boards/"..boardid.."/lists"..addon.."&value=true")
- local DecodedData = HTTPService:JSONDecode(Data)
- for _,tab in pairs(DecodedData) do
- for _,v in pairs(tab) do
- if tab.name == name then
- return tab.id
- end
- end
- end
- end
- end
- function TrelloAPI:CreateCard(name, desc, listid)
- local addon = getAddon()
- if name == nil or desc == nil or listid == nil then
- error('Invalid Arguments!')
- return nil
- else
- local data = {name=name, desc=desc, idList=listid}
- local dataencoded = HTTPService:JSONEncode(data)
- local Return = HTTPService:PostAsync("https://api.trello.com/1/cards"..addon.."&name="..name.."&desc="..desc.."&idList="..listid, dataencoded)
- local ReturnDecoded = HTTPService:JSONDecode(Return)
- return ReturnDecoded.id
- end
- end
- function TrelloAPI:RemoveList(listid)
- local addon = getAddon()
- if addon == nil then
- error('Invalid Arguments!')
- return nil
- else
- local data = {id=listid}
- local EncodedData = HTTPService:JSONEncode(data)
- HTTPService:RequestAsync({
- Url = "https://api.trello.com/1/lists/"..listid.."/closed"..addon.."&value=true",
- Method = "PUT",
- Body = EncodedData
- })
- end
- end
- function TrelloAPI:DeleteCard(cardid)
- local addon = getAddon()
- if addon == nil then
- error('Invalid Arguments!')
- return nil
- else
- local data = {id=cardid}
- local EncodedData = HTTPService:JSONEncode(data)
- HTTPService:RequestAsync({
- Url = "https://api.trello.com/1/cards/"..cardid..addon,
- Method = "DELETE",
- Body = EncodedData
- })
- end
- end
- return TrelloAPI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement