Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. --[[
  2.    
  3.     Made by Sceleratis
  4.     Trello API Documentation:   https://trello.com/docs/
  5.    
  6. --]]
  7.  
  8.  
  9. local http = game:service("HttpService")
  10.  
  11. function checkHttp()
  12.     local y,n = pcall(function()
  13.         local get = http:GetAsync('http://trello.com')
  14.     end)
  15.     if y and not n then
  16.         return true
  17.     else
  18.         return false,n
  19.     end
  20. end
  21.  
  22. function decode(str)
  23.     return http:JSONDecode(str)
  24. end
  25.  
  26. function encode(str)
  27.     return http:JSONEncode(str)
  28. end
  29.  
  30. function urlEncode(str)
  31.     return http:UrlEncode(str)
  32. end
  33.  
  34. function httpGet(url)
  35.     return http:GetAsync(url,true)
  36. end
  37.  
  38. function httpPost(url,data,type)
  39.     return http:PostAsync(url,data,type)
  40. end
  41.  
  42. function trim(str)
  43.     return str:match("^%s*(.-)%s*$")
  44. end
  45.  
  46. function getListObj(list,name)
  47.     for i,v in pairs(list) do
  48.         if trim(v.name)==trim(name) then
  49.             return v
  50.         end
  51.     end
  52. end
  53.  
  54. function Trello(appKey, token)
  55.     local Status,Message = checkHttp()
  56.     if not Status then
  57.         return false,Message
  58.     end
  59.    
  60.     local appKey = appKey or ""
  61.     local token = token or ""
  62.     local base = "https://api.trello.com/1/"
  63.     local toks = "key="..appKey.."&token="..token
  64.    
  65.     local api
  66.     api = {
  67.        
  68.         http = http;
  69.        
  70.         getListObj = getListObj;       
  71.        
  72.         checkHttp = checkHttp;
  73.        
  74.         urlEncode = urlEncode;
  75.        
  76.         encode = encode;
  77.        
  78.         decode = decode;
  79.        
  80.         httpGet = httpGet;
  81.        
  82.         httpPost = httpPost;
  83.        
  84.         trim = trim;
  85.        
  86.         epochToHuman = function(epoch)
  87.             return decode(httpGet("http://www.convert-unix-time.com/api?timestamp="..epoch.."&returnType=json&format=iso8601")).utcDate
  88.         end;
  89.        
  90.         getBoard = function(boardId)
  91.             return decode(httpGet(api.getUrl("boards/"..boardId)))
  92.         end;
  93.        
  94.         getLists = function(boardId)
  95.             return decode(httpGet(api.getUrl("boards/"..boardId.."/lists")))
  96.         end;
  97.        
  98.         getList = function(boardId, name)
  99.             local lists = api.getLists(boardId)
  100.             return getListObj(lists,name)
  101.         end;
  102.        
  103.         getCards = function(listId)
  104.             return decode(httpGet(api.getUrl("lists/"..listId.."/cards")))
  105.         end;
  106.        
  107.         getCard = function(listId, name)
  108.             local cards=api.getCards(listId)
  109.             return getListObj(cards,name)
  110.         end;
  111.        
  112.         getComments = function(cardId)
  113.             return decode(httpGet(api.getUrl("cards/"..cardId.."/actions?filter=commentCard")))
  114.         end;
  115.        
  116.         delComment = function(cardId, comId)
  117.             -- No PUT/DELETE :(  (?)
  118.         end;
  119.        
  120.         makeComment = function(cardId, text)
  121.             return decode(httpPost(api.getUrl("cards/"..cardId.."/actions/comments"),"&text="..urlEncode(text),2))
  122.         end;
  123.        
  124.         getCardField = function(cardId,field)
  125.             return decode(httpGet(api.getUrl("cards/"..cardId.."/"..field)))
  126.         end; -- http://prntscr.com/923fmw
  127.        
  128.         getBoardField = function(boardId,field)
  129.             return decode(httpGet(api.getUrl("boards/"..boardId.."/"..field)))
  130.         end; -- http://prntscr.com/923gq3
  131.        
  132.         getListField = function(listId,field)
  133.             return decode(httpGet(api.getUrl("lists/"..listId.."/"..field)))
  134.         end; -- http://prntscr.com/923uyb
  135.        
  136.         getLabel = function(boardId,name)
  137.             local labels = api.getBoardField(boardId,"labels")
  138.             return getListObj(labels,name)
  139.         end;
  140.        
  141.         makeCard = function(listId,name,desc,extra)
  142.             local extra = extra or ""
  143.             return decode(httpPost(api.getUrl("lists/"..listId.."/cards"),"&name="..urlEncode(name).."&desc="..urlEncode(desc)..extra,2))
  144.         end;
  145.        
  146.         makeList = function(boardId,name,extra)
  147.             local extra = extra or ""
  148.             return decode(httpPost(api.getUrl("boards/"..boardId.."/lists"),"&name="..urlEncode(name)..extra,2))
  149.         end;
  150.        
  151.         doAction = function(method,subUrl,data)
  152.             if method:lower()=="post" then
  153.                 return decode(httpPost(api.getUrl(subUrl),data,2))
  154.             elseif method:lower()=="get" then
  155.                 return decode(httpGet(api.getUrl(subUrl)))
  156.             end
  157.         end;
  158.        
  159.         getUrl = function(str)
  160.             local toks=toks
  161.             if str:find("?") then
  162.                 toks="&"..toks
  163.             else
  164.                 toks="?"..toks
  165.             end
  166.             return base..str..toks
  167.         end;
  168.     }  
  169.     return api
  170. end
  171.  
  172. return Trello
  173.  
  174.                                                                                                                                                                                                                                                 --[[
  175.                                                            --                                                                                                                         ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement