Advertisement
Aiden_12114

Aiden's Trello API [OS]

Jul 20th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1.  
  2. local TrelloAPI = {}
  3. local HTTPService = game:GetService("HttpService")
  4. local Key = script.Key.Value
  5. local Token = script.Token.Value
  6. script.Key:Destroy()
  7. script.Token:Destroy()
  8. function getAddon()
  9.     local addon
  10.     addon = "?key="..Key.."&token="..Token
  11.     return addon
  12. end
  13. function TrelloAPI:GetBoard(boardId)
  14.     local addon = getAddon()
  15.     local JSON = HTTPService:GetAsync("https://api.trello.com/1/boards/"..boardId..''..addon)
  16.     local DecodedData = HTTPService:JSONDecode(JSON)
  17.     return DecodedData.name
  18. end
  19. function TrelloAPI:GetBoardID(name)
  20.     local addon = getAddon()
  21.     local JSON = HTTPService:GetAsync("https://api.trello.com/1/members/me/boards"..addon)
  22.     local DecodedData = HTTPService:JSONDecode(JSON)
  23.     if name ~= nil then
  24.             for _,tab in pairs(DecodedData) do
  25.             for _,v in pairs(tab) do
  26.                 if tab.name == name then
  27.                     return tab.id
  28.                 end
  29.             end
  30.         end
  31.         error(name.." Was Not Found!")
  32.         return nil
  33.     end
  34. end
  35. function TrelloAPI:CreateList(name, boardid)
  36.     local addon = getAddon()
  37.     if name == nil or boardid == nil then
  38.         error('Invalid Arguments!')
  39.         return nil
  40.     else
  41.         local data = {name=name,idBoard=boardid}
  42.         local EncodedData = HTTPService:JSONEncode(data)
  43.         local Return = HTTPService:PostAsync("https://api.trello.com/1/lists"..addon.."&name="..name.."&idBoard="..boardid, EncodedData)
  44.         local ReturnDecoded = HTTPService:JSONDecode(Return)
  45.         return ReturnDecoded.id
  46.     end
  47. end
  48. function TrelloAPI:GetListID(name, boardid)
  49.     local addon = getAddon()
  50.     if name == nil or boardid == nil then
  51.         error('Invalid Arguments!')
  52.         return nil
  53.     else
  54.         local Data = HTTPService:GetAsync("https://api.trello.com/1/boards/"..boardid.."/lists"..addon.."&value=true")
  55.         local DecodedData = HTTPService:JSONDecode(Data)
  56.         for _,tab in pairs(DecodedData) do
  57.             for _,v in pairs(tab) do
  58.                 if tab.name == name then
  59.                     return tab.id
  60.                 end
  61.             end
  62.         end
  63.     end
  64. end
  65. function TrelloAPI:CreateCard(name, desc, listid)
  66.     local addon = getAddon()
  67.     if name == nil or desc == nil or listid == nil then
  68.         error('Invalid Arguments!')
  69.         return nil
  70.     else
  71.         local data = {name=name, desc=desc, idList=listid}
  72.         local dataencoded = HTTPService:JSONEncode(data)
  73.         local Return = HTTPService:PostAsync("https://api.trello.com/1/cards"..addon.."&name="..name.."&desc="..desc.."&idList="..listid, dataencoded)
  74.         local ReturnDecoded = HTTPService:JSONDecode(Return)
  75.         return ReturnDecoded.id
  76.     end
  77. end
  78. function TrelloAPI:RemoveList(listid)
  79.     local addon = getAddon()
  80.     if addon == nil then
  81.         error('Invalid Arguments!')
  82.         return nil
  83.     else
  84.         local data = {id=listid}
  85.         local EncodedData = HTTPService:JSONEncode(data)
  86.         HTTPService:RequestAsync({
  87.             Url = "https://api.trello.com/1/lists/"..listid.."/closed"..addon.."&value=true",
  88.             Method = "PUT",
  89.             Body = EncodedData
  90.         })
  91.     end
  92. end
  93. function TrelloAPI:DeleteCard(cardid)
  94.         local addon = getAddon()
  95.     if addon == nil then
  96.         error('Invalid Arguments!')
  97.         return nil
  98.     else
  99.         local data = {id=cardid}
  100.         local EncodedData = HTTPService:JSONEncode(data)
  101.         HTTPService:RequestAsync({
  102.             Url = "https://api.trello.com/1/cards/"..cardid..addon,
  103.             Method = "DELETE",
  104.             Body = EncodedData
  105.         })
  106.     end
  107. end
  108. return TrelloAPI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement